[erlang-questions] Any way to correct the round off errors?

Masklinn masklinn@REDACTED
Sun Sep 20 19:00:07 CEST 2009


On 20 Sep 2009, at 18:12 , Witold Baryluk wrote:
> Dnia 2009-09-20, nie o godzinie 18:06 +0200, Masklinn pisze:
>> On 20 Sep 2009, at 17:22 , Witold Baryluk wrote:
>>> If you want something which calculates correctly in decimal number,
>>> use
>>> integers multiplied with some 10^k power. It is called fixed point
>>> arithmetic.
>> Or use a decimal floating-point library such as gmp.
>
> Sure. But considering that Erlang already have arbitrary precision
> integers, writing few functions for add/sub/mul/div isn't very hard :)

Arbitrary precision integers are quite different beasts (and easier to  
handle) than arbitrary precision floats. Most languages with native  
arbitrary precision integers (python, ruby, Haskell's Integer type, …)  
tend to relegate arbitrary precision floats to libraries, either  
stdlib or third-party, and pretty much systematically rely on IEEE754  
floating-points natively (though they might have fraction types  
between integer and reals).

> It will be more portable than linking to gmp, :)
Not necessarily (gmp is quite damn portable), and it would be much  
harder to handle correctly. FWIW, Python's decimal module is 2500  
lines of pure python.


More information about the erlang-questions mailing list