in reply to Perl 5.8.x floating point representation error
An issue discussed frequently enough to warrant a spot in perlfaq4.
Put in simple terms, you cannot rely on floating point to be free of rounding errors in some of the last few digits of precision. You're out at the limits there. Different versions of Perl, different architectures, and different alignment of planetary orbits will introduce minor rounding errors as the internal binary representation of floating point numbers manifests its limitations.
I cannot explain why one version may differ from another, but can comfortably assert that this is documented and expected behavior.
Math::BigFloat is one solution. Stringification may be another solution, depending on what you're doing with the FP numbers.
Searching through an old node of mine on a similar topic I found a great link that explains the concept better than I possibly could: What Every Computer Scientist Should Know About Floating Point Arithmetic.
Enjoy!
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl 5.8.x floating point representation error
by satish.rpr (Novice) on Jan 21, 2009 at 12:12 UTC | |
by BrowserUk (Patriarch) on Jan 21, 2009 at 12:40 UTC | |
by Anonymous Monk on Jan 21, 2009 at 12:49 UTC |