[erlang-questions] Maths Problem -> 2452.45*100. = 245244.99999999997

Richard A. O'Keefe <>
Thu Nov 28 02:57:06 CET 2013


On 28/11/2013, at 2:37 AM, Alexander Alexeev wrote:

> Unfortunately, decimal does not solves all problems. For example:
> 
> http://pastexen.com/code.php?file=zt4viJXw1I.txt

Smalltalk has a ScaledDecimal class.
If the implementations could only agree to follow what the
standard says, or if for that matter the standard were
sufficiently coherent to _be_ followed -- referring to
non-existent material in another standard does not help --
it might be a very good thing.
My reading of that standard is that a ScaledDecimal is
an arbitrary precision integer M and a scale S
representing the precise number M*10^(-S).
Addition, subtraction, multiplication, and comparison are
_no_ problem, but division is, and that's what your link
above is all about.

No finite-precision representation of numbers can handle
division perfectly, even when it has unbounded range.
(Question for people using data bases with Erlang:  do
you know what the SQL standard says about division of
NUMERIC values?  Does your SQL implementation do that?)

> I wonder, does Erlang has a Data.Ratio equivalent from Haskell?

Not as a built in type.  It's not that hard to make something
using {Num,Den} pairs, tedious rather than difficult, and not
usable with ordinary mathematical operations.  Since Erlang's
close relatives Lisp and Scheme have ratios, and since some
even closer Prolog relatives have ratios (thanks, Jan, for
ratios in SWI Prolog), ratios would _fit_ into Erlang quite
nicely.  It has been argued for years that Erlang applications
wouldn't benefit from them sufficiently to justify the cost of
implementing them.




More information about the erlang-questions mailing list