Is there an equivalent of the decimal type in D?
Sean Kelly
sean at f4.ca
Sat Jan 27 15:08:52 PST 2007
Bill Baxter wrote:
> Sean Kelly wrote:
>> I'm not sure that accuracy is a problem--at least not compared to
>> fixed-point BCD. The essential issue with using base 2 floating point
>> for problems where the user expects an "exact" result in base 10 is
>> that of representation. Simply put, some numbers that have an exact
>> representation in base 10 are infinitely repeating numbers in base 2,
>> and vice-versa. This is why a calculation resulting in 1.5 in base 10
>> displays as 1.4999... in base 2. But as far as accuracy is concerned,
>> I'm sure you'll agree that 1.4999... is not terribly far from 1.5 :-)
>> Of course, finance folks don't see it this way because if you display
>> 1.4999 on a report it doesn't match what they expect and they scream
>> and yell.
>
> Bad example. 1.5 *is* exactly representable in base 2 floating point.
> 2^0 + 2^-1 :-)
Oops! :-)
Sean
More information about the Digitalmars-d-learn
mailing list