[erlang-questions] Any way to correct the round off errors?
Thu Oct 15 20:23:18 CEST 2009
Sorry for reviving this old thread, but I missed it on the first pass and
wanted to add my 2 cents.
When most people talk of IEEE-754, they are referring to IEEE-754-1985
which which encompasses single and double precision floating points, which
are both binary FP formats. Erlang's floating point type is the double
IEEE-754-2008 defines a much broader set of formats which includes 4 binary
binary16 (half precision)
binary32 (single precision)
binary64 (double precision)
binary128 (quad precision)
and 3 decimal FP formats:
In addition there are the so-called interchange formats that are independent
of machine architecture.
The binary formats provide good precise values, but as has been pointed out,
not all decimal values are represented in these formats. For scientific
applications and applications where precise unrounded values are required,
the binary formats are appropriate. For business applications where
predictable rounded values are required, the decimal formats are
appropriate. To get the results you are looking for you should use one of
the decimal formats.
Erlang does not support any decimal format natively, however, it can be
supported in libraries. A couple of years ago I wrote a decimal linked-in
driver that is backed by the IBM AlphaWorks DecNumber library. Calulations
are done in decimal128 and the interface type is platform independent. Find
The library is very rough, but all the basic operations have been tested. I
appologize, but the Makefile only works on mac-os-x.
2009/9/21 Masklinn <>
> On 21 Sep 2009, at 03:50 , Richard O'Keefe wrote:
>> The IEEE 754 standard is small and tolerably clear;
>> there are drafts and summaries and review articles about it
>> all over the web.
> First and foremost being Goldberg's "What Every Computer Scientist Should
> Know About Floating-Point Arithmetic" (
> http://docs.sun.com/source/806-3568/ncg_goldberg.html) which is often
> considered the most basic knowledge requirement before any discussion of
> IEEE-754 floats.
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
More information about the erlang-questions