[erlang-questions] In Erlang , {1.1*1.1.} show me the answer is 1.2100000000000002, why?

Dmytro Lytovchenko dmytro.lytovchenko@REDACTED
Sun Oct 26 10:00:40 CET 2014


Because of the principle how floating point numbers work. Encoded number is
approximate, so that 0.0000000002 is just closest representation in binary
that would encode your given fraction (1.21), and it is below the precision
which is guaranteed for this size of floating point value. This question
been discussed million times for every programming language.

http://en.wikipedia.org/wiki/IEEE_floating_point (there is chinese variant
of this article, hope its detailed enough).

On Sun, Oct 26, 2014 at 8:24 AM, 张栋 <zd2559@REDACTED> wrote:

> Hello the maillist member:
> I am  new in Erlang,Please Help me.
>
> When I try some multiplication, I got the some unexpected answer about
> the following expression.
>
> Please help!
>
> List:
>
> 23> [1.1*1.1,1.1*1.2,1.1*1.3,1.1*1.4,1.1*1.5].
> [1.2100000000000002,1.32,1.4300000000000002,1.54,
>  1.6500000000000001]
>
> 24> [1.2*1.2,1.2*1.3,1.2*1.4,1.2*1.5,1.2*1.6].
> [1.44,1.56,1.68,1.7999999999999998,1.92]
>
> Thank you for your time.
>
> Eric D. Zhang In China.
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20141026/3b6ccb83/attachment.htm>


More information about the erlang-questions mailing list