Is there an equivalent of the decimal type in D?

Myron Alexander someone at somewhere.com
Fri Jan 26 19:27:09 PST 2007


Sean Kelly wrote:
> Myron Alexander wrote:
>> Hello.
>>
>> I want to work with numbers without having to worry about binary 
>> representation. I work with currencies and other such values that must 
>> be absolute. In Java I have BigDecimal and in Python I have decimal.
> 
> For finance, isn't round-off error more of an issue than internal 
> representation?
> 
> 
> Sean

Internal representation is not the issue. I need stable and predictable 
handling of arithmetic operations and display. With floats and double, 
workarounds exist but they are cumbersome and not guaranteed. Also, 
different compilers and C/FPUs can handle floats and doubles slightly 
differently; not a problem currently but may be a problem for the 
future. A decimal type sacrifices raw performance for guaranteed decimal 
accuracy.

It has been a long time since I had to deal with floats and doubles 
since I do most of my work with BigDecimal; the type of applications do 
not seem to suffer in performance, they are mostly io bound. I have read 
several papers on float handling including, what I have been told is the 
holy text: http://docs.sun.com/source/806-3568/ncg_goldberg.html.

If you have any links to guides on how to handle floating point to 
achieve predictable accuracy, could you please post them as I can't say 
that I understand that problem space as well as I used to.

Regards,

Myron.


More information about the Digitalmars-d-learn mailing list