[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: weird math

What we see in this thread is yet another periodic revelation that binary
floating point doesn't work well in a decimal world.  It really isn't the
right way to represent lots of things.  US money, for example.  I believe
that what follows is a list of the numbers of cents (expressed as decimal
parts of a dollar) which represent exactly in binary floating point of ANY
     (.00, .25, .50, .75)
(or 4% of the possible values).  This is the basic reason why Apple
extended the IEEE standard with the SANE comp (computational) type.  Money
can be recorded precisely in 100ths (or, perhaps better, 1000ths) of
dollars in a comp, quite nicely.  [A simple 64-bit integer and the related
math might have been even better, saving the conversions to (exact)
floating point representations for all operations, and back to comp for

   If you see a binary floating point system in which you DON'T see these
comparison oddities, you're working with one which does fuzzy compares for
equal.  All that really accomplishes is to give the programmer a false
sense of exactness where there is not exactness.

jwbaxter@pt.olympus.net (John W. Baxter)
AppleLink BAXTER.JOHN if you really must (but ONLY from AppleLink).
CIS 71735,1626