Mail Archives: djgpp/2000/01/06/10:25:42
On Thu, 6 Jan 2000, Niklas Pettersson wrote:
> I think I have found an error in DJGPP...
No, it's not a bug in DJGPP.
> 0.1 0
> ..
> ..
> 0.9 0
> 1.0 1
> ...
>
> but 1.0 gets converted to 0!!!!
The problem is that 0.1 doesn't have an exact binary representation, so
it is converted to a number that is slightly less than 0.1. Therefore,
10 times that number is slightly less than 1.0. Printing that number
with %f rounds the value to 1.0, but assigning it to an int *truncates*
rather than rounds, and you get 0.
I suggest to read some introductory book about numerical computations, it
should explain this somewhere on page 3 or thereabouts...
- Raw text -