Such are the vagaries of floating point mathematics on a digital computer.
There is no "exact" with floating point representation.

Signature
Fred
Microsoft Visual FoxPro MVP
> Such are the vagaries of floating point mathematics on a digital computer. There is no "exact" with floating point representation.
yes, and here is why:
? 8279.17500 * 1.000 * 1024
8477875.20000000
? 8279.17500 * 1.0000 * 1024
8477875.199999999
The factor 1024 exactly shifts the value 10 bits.
Now you can see that there is a difference
in the results of 8279.17500 * 1.000 and
8279.17500 * 1.0000, although I cannot
say, how exact numbers are represented
and why a multiplication with 1 has different
results, as 1 can be represented exactly.
But 0.175 has three decimals in base 10 and
binary it's 0.001011.... It's never ending and
can't be exactly represented, so different re-
presentations with a different exactness can be
above or below 0.175 and so rounding can
work or fail...
There are binary coded decimals especially for
monetary calculations. In motorola 68000 assem-
bler there was a command for adding two binary
coded decimals called ABCD (Add Binary
Coded Decimals). In a binary coded decimal
each digit is represented by 4 bits, so a byte
can represent 00 to 99. It's something like hexa-
decimal without letters ;-). With this kind of re-
presentation you can represent decimal numbers
exactly (or you'd have the same problems as
with decimal numbers), so these kind of rounding
errors don't occur with BCDs.
There are two interesting downloads at uni-
versalthread: "decimal COM library" and "Math
Unlimited", which are download ids 9987 and
10044. I think decimal COM library works with
BCDs and Math unlimited works with strings and
can therefore calculate with very large numbers...
Bye, Olaf.