Page 1 of 1

Floats bug, or feature?

Posted: Wed Oct 18, 2006 11:46 pm
by Killswitch
Just messing about with PB but I've noticed this:

Code: Select all

a.l=b.f*c.l+1.5+9
Debug a ;debugs 10
a.l=b.f*c.l+1.5+90
Debug a ;debugs 92
Why is 1.5 being rounded to 1 in the first case, but 2 in the second?

Posted: Thu Oct 19, 2006 3:59 pm
by Trond
The multiplication has nothing do to with it:

Code: Select all

a.l = b.f + 1.5 + 9
Debug a ;debugs 10

a.l = b.f + 1.5 + 10
Debug a ;debugs 12
Purebasic correctly adds the float constants together:

Code: Select all

PokeL(@a.f, 1093140480)
Debug a ; 10.5

PokeL(@a.f, 1094189056)
Debug a ; 11.5
Conclusion: The FPU FISP instruction (store a float number to an integer) uses banker's rounding mode.