January 27, 2007 Re: Is there an equivalent of the decimal type in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | Sean Kelly wrote:
> Jeff Nowakowski wrote:
>> Sean Kelly wrote:
>>> Unless you're simply dealing with numbers too large to be represented exactly with floating-point (16 digits for 64-bit double, and I can't remember the limit for 80-bit real offhand), I think it makes more sense to use floating point internally and round to the appropriate degree of precision for display.
>>
>> Floating point is a very bad idea for representing money. If you're adding up currencies then you want an exact representation, not "close enough". Sooner or later you will get bitten by rounding error if you use floats.
>
> And this is more of a problem than rounding error with BCD? Most BCD representations I've seen only use around 6 decimal places, which is far too few in some cases.
Perhaps this is my source of confusion. Does Java's BigDecimal support arbitrary precision after the decimal point?
Sean
|
January 27, 2007 Re: Is there an equivalent of the decimal type in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | Sean Kelly wrote:
> Perhaps this is my source of confusion. Does Java's BigDecimal support arbitrary precision after the decimal point?
Yes.
-Jeff
|
January 28, 2007 Re: Is there an equivalent of the decimal type in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Myron Alexander | Myron Alexander wrote:
> 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.
>
> Does D have an equivalent, either at the language level or as a module/class?
The ongoing revision to the IEEE 754 floating-point standard has support for decimal; when 754r seems close to ratification would be a good time to add it to D.
--Joel
|
January 29, 2007 Re: Is there an equivalent of the decimal type in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Myron Alexander | Myron Alexander escribió: > 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. > > Does D have an equivalent, either at the language level or as a module/class? You can try using a C arbitrary precision library (or wrap it so it's little more pleasant to use in D), like GMP[1]. [1] http://www.swox.com/gmp/ -- Leandro Lucarella Integratech S.A. 4571-5252 |
January 29, 2007 Re: Is there an equivalent of the decimal type in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Leandro Lucarella | Leandro Lucarella wrote:
> Myron Alexander escribió:
>> 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.
>>
>> Does D have an equivalent, either at the language level or as a module/class?
>
> You can try using a C arbitrary precision library (or wrap it so it's little more pleasant to use in D), like GMP[1].
>
> [1] http://www.swox.com/gmp/
>
Hello Leandro.
Thanks for the pointer. I will take a look when I can.
All the best,
Myron.
|
Copyright © 1999-2021 by the D Language Foundation