Mail Archives: djgpp/1996/12/03/14:40:24
In article <32A33C44 DOT 68FE AT exis DOT net>, Joe Wright <wrightj AT exis DOT net> wrote:
>Not so fast. Before the answer, we have the real question: Not why is
>the result 'wrong' but why are they different? Why does i=(int)(f*100);
>yield a different result than f=f*100; i=(int)f; ? Why? Clearly the
>compiler is doing conversions differently in the two cases.
Once again (for those who missed the answer the first time it was
posted): with (int)(f*100), the precision of the intermediate value
(f*100) must be at _least_ equal to the precision of a float; it may be
a double or long double. To be exact, it's probably whatever size fits
in the FPU (80 bits). When you assign it to a float first, it will be
converted to a size which fits in a float, an operation which involves
round-to-nearest. The round-to-nearest-float is the difference.
- Raw text -