[erlang-questions] Erlang Numbers
Richard A. O'Keefe
ok@REDACTED
Wed Jun 18 00:33:56 CEST 2014
On 18/06/2014, at 4:21 AM, Camille Troillard wrote:
> I understand Erlang uses the IEEE-754 specs for floating-point numbers arithmetic. So when I type in the console:
>
> 1> 0.2 + 0.1.
> 0.30000000000000004
>
> This is fine, I was expecting that. However, why the following works:
>
> 2> 0.1.
> 0.1
>
> Is it because of some rounding behaviour?
If the question you're asking is whether it is because
of some *Erlang-specific* rounding behaviour, the answer
is NO.
m% gsi
Gambit v4.6.0
> (+ 0.2 0.1)
.30000000000000004
> 0.1
.1
> (* 0.1 3)
.30000000000000004
> (- (* 0.1 10) 1)
0.
> (- (* (+ 0.1 0.2) 10) 3)
4.440892098500626e-16
What we want from output is
- the shortest number that reads back as what we started with
and for 0.1 that happens to be "0.1".
More information about the erlang-questions
mailing list