On Jan 17, 2008 9:33 PM, Elvedin Trnjanin <trnja001 at umn.edu> wrote:
> rhubarbpie at poetworld.net wrote:
> > I'm a Perl novice and hope this is a proper channel for a simple
> > question.  Why does the following decrement incorrectly below 10?  It
> > works with $i -- or $i -= .5.  This is part of a larger script and I've
> > made a workaround, but I'm still curious.
> >
> Start $i from 100 and you'll notice that it happens for numbers greater
> than 10. The reason for this is that certain numbers cannot be
> represented accurately with the floating point representation your
> computer architecture and data type use. IEEE 754 is a standard that
> addresses this so try reading up on that if you're really interested.
> Any who, this is even worse in C with a float.
1/10 is a repeating binary number, so no matter how many bits you have
in a floating point representation it will be wrong.  So the double
version does not work perfectly, just less imperfectly than the
floating point version.

leif