<div dir="ltr"><div><div><div><div><div>Hi there,<br><br></div>There are certain common misconceptions around floating-point numbers.<br></div>The key thing to keep in mind is that a) they have limited precision, as they are represented in a fixed number of bits, and b) they are represented in base 2, so numbers which look nice in base 10 and "feel" as if they should not suffer from precision loss, may surprise by doing so.<br>
<br></div>In your case, notice that for 10ēģ to be represented accurately takes >3*23 = 69 bits -- and Erlang floats are represented in 64 bits (IEEE 754 double precision / C's "double") -- which means that even if all 64 bits were used for the mantissa, the number could not be represented accurately. In fact, there are only 52+1 bits for the mantissa, so the problem starts already at around 10^16:<br>
</div> round(10000000000000001.0) => 10000000000000000.<br><br><br></div>Hoping this helps,<br>/Erik<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/4/6 Pierre Fenoll <span dir="ltr"><<a href="mailto:pierrefenoll@gmail.com" target="_blank">pierrefenoll@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I have notice that on both my R16B 64bit machines (Archlinux & OSX),</div><div>
round(1.0e23) = 99999999999999991611392</div><div>Instead of 10ēģ as it should.</div>
<div><br></div><div>I think it's a matter of float to int.</div><div>Do you guys have any idea? Am I doing something wrong?</div><div><br></div><div>Cheers,</div><div>Pierre</div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>