Uhhhhh....

Blitz3D Forums/Blitz3D Programming/Uhhhhh....

kfprimm(Posted 2007) [#1]
This is so annoying. Can anyone explain why,
Print 1/2
If (1/2)<>.5 Print "There's a problem"

spits out,
0
There's a problem

instead of just .5?


GfK(Posted 2007) [#2]
1 and 2 are treated as integer, therefore the result will also be integer.

To get a float result, either or both sides of your equation should also be a float
Print 1/2.0



Who was John Galt?(Posted 2007) [#3]
/\ True....and your example still may not work. Generally speaking, don't compare floating point values with =. Instead use something that allows for some errors, e.g:

To check if x 'equals' 0.5:

if (abs(x-0.5)<0.0001)


Andy(Posted 2007) [#4]
>This is so annoying. Can anyone explain why,

2 issues. Blitz expects you to use floats in if you want floats out...

Secondly. Floats are inherently imprecise, which means that you should not compare floats to precise numbers.


Andy


kfprimm(Posted 2007) [#5]
Alright then, thanks everyone.