[erlang-questions] Strange arithmetic behaviour
Matthias Lang
matthias@REDACTED
Thu May 8 10:58:05 CEST 2008
Gurgen Tumanian writes:
> There is some kind of strange behaviour that i have noticed when dealing
> with big float values.
This problem is not a "big nasty bug", it's a fundamental consequence
of the way floating point numbers are commonly represented. It is
basically unrelated to Erlang, you'll get the same behaviour in C, for
instance.
Your first subtraction is a textbook example of the relative error
growing dramatically when you subtract two large numbers which are
close together.
This wikipedia article is a quick introduction to the topic:
http://en.wikipedia.org/wiki/Floating_point
Matt
----------------------------------------------------------------------
> For example:
>
> 123123123123123123123.0 - 123123123123123123121.0 is 0.00000e+0 when i
> expect 2.0 or something like that in e notation.
> I found this kind of errors with round() and trunc(). for example:
> trunc(1233333333333333123333333333.12311111111) is
> 1233333333333333065680814080.
> or
> round(1233333333333333123333333333.12311111111) is
> 1233333333333333065680814080.
>
> furthermore
> 1233333333333333123333333333.12311111111 =
> 123333333333333312367575676573.92311111111 matches
>
>
> I have tested this on R11-B5 and on R12-B1
>
> Is this a big nasty bug, or am i missing something?
>
> Regards
> Gurgen Tumanyan
> Smart Tech
> Dear all.<br><br>There is some kind of strange behaviour that i have noticed when dealing with big float values.<br>For example:<br><br> 123123123123123123123.0 - 123123123123123123121.0 is 0.00000e+0 when i expect 2.0 or something like that in e notation.<br>
> I found this kind of errors with round() and trunc(). for example: <br>trunc(1233333333333333123333333333.12311111111) is 1233333333333333065680814080.<br>or<br>round(1233333333333333123333333333.12311111111) is 1233333333333333065680814080.<br>
> <br>furthermore <br>1233333333333333123333333333.12311111111 = 123333333333333312367575676573.92311111111 matches<br><br><br>I have tested this on R11-B5 and on R12-B1<br><br>Is this a big nasty bug, or am i missing something?<br>
> <br>Regards<br>Gurgen Tumanyan<br>Smart Tech<br><br><br><br>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list