Floats bug, or feature?

Everything else that doesn't fall into one of the other PB categories.
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Floats bug, or feature?

Post 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?
~I see one problem with your reasoning: the fact is thats not a chicken~
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
Post Reply