Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Real number assignment failing?

Author
Message
bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 2nd Nov 2010 02:44
I am trying to utilise the following function:



The output of the log is coming out as:

x:400 originX:400 radius:169
OffsetX:3518437208883200.000000 Radius:0.000000 Degrees:0.000000


Is there any reason why the real numbers are not being set correctly?
bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 2nd Nov 2010 02:48
Just out of curiosity have tried the following, but the results are the same; very confused by this. Hope someone has an answer.

gbark
20
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 2nd Nov 2010 04:17 Edited at: 2nd Nov 2010 04:23
The variables themselves seem to be set fine - Could it be the way you're using WRITELN LOG that's showing weird results? I tried the following program, and it worked fine:



I'm assuming that command is from MatrixUtils or some other plugin, unfortunately I can't test it right now.

EDIT: If I had to guess as to what the problem actually is, I'd assume that the %f is associating the variable as a FLOAT. When using the hash symbol (#) in DBP to define real numbers, I'm not sure whether it actually uses FLOATS or DOUBLES as the default - If DBP is treating them as doubles, that might cause weird results like what you're getting if that command expects them to be floats.

Have you tried explicitly defining the variables as float, something like



at the top of your function? I don't know if this is what's actually causing it, but couldn't hurt to try!
bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 2nd Nov 2010 08:20
Thanks for the response, I did try the explicit float declaration as in the second post I appended, but got the same results.

In the meantime I have gone back to print statements as you have suggested.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Nov 2010 10:51


You need to express them as floats as you read them in. Is that how you did it?

bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 4th Nov 2010 13:07
Thanks for the tip on the variable names. It turns out the function was working, just the WRITELN LOG was incorrectly displaying the contents of the variable.

None of the floats seem to be output correctly whether using the REAL (#) identifier or declaring them explicitly as floats.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th Nov 2010 13:26
I've never used "WRITELN LOG" so I can't say. Is it one of IanM's commands?

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Nov 2010 13:38
Quote: "You need to express them as floats as you read them in."


Not true. The assignments in his code do the necessary conversions so the problem is elsewhere.

Unfortunately I'm not familiar with C so I can't advise on the correct use of the %f format - but the code compiles, runs and looks OK otherwise. I suggest you post your query on IanM's Matrix1 Utilities thread:

Matrix1Utils Thread

Here's some complete runnable code you can give him to test:

bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 4th Nov 2010 13:52
Thanks - its late so I'll get onto it tomorrow.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th Nov 2010 13:59
Quote: "Not true. The assignments in his code do the necessary conversions so the problem is elsewhere."

You are right of course but I was trying to highlight the fact that if he was passing floats into the function for "radius", "originX" and "x" they would be converted into integers before being passed through his function.

His equation would still produce a float as an answer but it would be incorrect if the original values passed in were not integers.

I should have made it clear that I was not actually providing an answer to the main problem, sorry!

bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 4th Nov 2010 14:07
Sorry for any confusion there. It is deliberate that the parameters are integers as all the stored values in the TYPEs are integers, which was why I was ensuring they were converted to floats in the function.

I am still a newbie, so it may not be the best way of doing things...
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Nov 2010 14:26
Maybe, but it seems as if you've spotted a problem which IanM should comment on. I look forward to the outcome in due course.

By the way, I've just done some reading up on the C++ printf function and I can't see anything obviously wrong with your code. Definitely one for IanM.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Nov 2010 15:23
I'll take a look at it when I get home tonight.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th Nov 2010 18:20
Quote: "Sorry for any confusion there. It is deliberate that the parameters are integers as all the stored values in the TYPEs are integers, which was why I was ensuring they were converted to floats in the function.

I am still a newbie, so it may not be the best way of doing things..."

There's nothing wrong with the way you were doing it (as GG said) but by calling it in the "function" line you avoid having to put in lines such as "radius#=radius" because you already told it what kind of variable to 'be'...

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Nov 2010 22:14
@bodmcn,
I know what the problem is, and the short term fix for you is to pass the values to WRITELN LOG as double floats instead of floats and to use any of the 'float' specifiers (eg %f) as you do now.

In the meantime, I'll work on fixing this properly.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 5th Nov 2010 00:32
Great stuff - thanks for that

Login to post a reply

Server time is: 2026-07-26 05:03:27
Your offset time is: 2026-07-26 05:03:27