Floating Point is killin' me...

BlitzMax Forums/BlitzMax Programming/Floating Point is killin' me...

Chroma(Posted 2007) [#1]
I'm dealing with air pressure density and when I have a float that is supposed to be 1.2929, I need it to be exactly that. Blitz3D doesn't have this problem, so why does BlitzMax?!?!


Who was John Galt?(Posted 2007) [#2]
They both have that problem, maybe Blitz3D has a slightly different rounding alg for printing?

Try using doubles instead. If the problem is only the way the number is printing, take a look in the archives for printing code (I haven't checked)


Chroma(Posted 2007) [#3]
So you're saying what is printed and what the variable is holding isn't the same thing?


N(Posted 2007) [#4]
In addition to doubles, you could also consider using fixed-point notation with long integers. The downside to this is you won't get the speed benefits included by using your system's FPU and there is a direct limit to the precision available.

Or, with GCC, you can use long doubles (96-bit floating point number), but this would require you to do a C implementation of your code. Also, the size of long doubles is pretty inconsistent between compilers.


Who was John Galt?(Posted 2007) [#5]
Can you post a short example? Are you just printing a constant, or is it the expected result of some math?


Dreamora(Posted 2007) [#6]
Blitz3D is not precise. I'm not fully sure if Blitz3D uses float at all as its behavior on rounding etc looks more like fixed point math than actual float math. Haven't seen any of the regular floating point inaccuracies. Not near 0 nor if you go a fair amount away of 0 where the floats should become extermely inaccurate.

Which is what you actually see in BM.


ImaginaryHuman(Posted 2007) [#7]
Depending on the range of the numbers that you are likely to store in the variable, you can just use an integer - or a long, and use a ShL or ShR operation to multiply/divide it so you can treat it like a fixed point variable.


Chroma(Posted 2007) [#8]
Nm on this guys. I don't think anyone has the answer. I'm just not going to worry about it and press on.


Who was John Galt?(Posted 2007) [#9]
Yeah that looks about the expected level of precision. Floating point can't store 1.1 exactly.


Chroma(Posted 2007) [#10]
Yeah that's cool. I probably over-reacted. Sorry Mark!! :p


sebas76(Posted 2007) [#11]
Yes there is a bug on Blitzmax printing functions.
They don't print exactly what the float or double contain.
I have the same problem but now I don't care about the exact value printing.
I hope one day this bug will be resolved...