in reply to Rounding error?
It all comes down to the inexactitude in the way computers represent floating point values. By printing the values out with as many digits of precision as you can, you'll see that one value rounds down, and the other rounds up.
printf "%.17f\n", 40.88050; 40.88049999999999800 printf "%.17f\n", 41.78050; 41.78050000000000400
The (probable) reason that you see a different result from C, is that you are (probably) using single precision (floats) in your C code, whilst Perl uses double precision. (Probably:)
See Re: Re: Re: Bug? 1+1 != 2 for more information.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Rounding error?
by pg (Canon) on Oct 19, 2004 at 03:27 UTC |