Thank you for this perfect and complete answer !<div><br class="webkit-block-placeholder"></div><div>Fréd<br><br><div><span class="gmail_quote">2007/11/16, John M McIntosh <<a href="mailto:johnmci@smalltalkconsulting.com">
johnmci@smalltalkconsulting.com</a>>:</span><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">Actually we can skip some of the complexity<br><br>(0.3 + 0.6 +
0.1) = 1.0 -> false<br><br>This is not a squeak problem, it's a problem with how floating point<br>numbers are stored in binary floating point representation.<br><a href="http://en.wikipedia.org/wiki/Floating_point_number">
http://en.wikipedia.org/wiki/Floating_point_number</a><br><br><br>The 0.3 + 0.6 + 0.1 returns a number close to, but not quite 1.0<br><br>(0.3 + 0.6 + 0.1) hex '3FEFFFFFFFFFFFFF'<br>and<br>(0.3 + 0.5 + 0.2) hex '3FF0000000000000'
<br>and<br>(1.0) hex '3FF0000000000000<br><br>so when you compare 3FEFFFFFFFFFFFFF to 3FF0000000000000 that<br>returns (truefully) false.<br><br>It's dangerous to compare floating point numbers, so consider instead.
<br><br>(0.3 + 0.6 + 0.1) closeTo: (0.3 + 0.5 + 0.2) -> true<br><br>but you would need to look at the algorithm in closeTo: to decide if<br>it's statistically meaningful to what you want.<br><br><br><br>On Nov 15, 2007, at 11:06 PM, Frederic Pluquet wrote:
<br><br>> Hello,<br>><br>> I found a bug in Squeak (3.0, #7067)... The following code returns<br>> true:<br>><br>> (#(0.3 0.5 0.2) inject: 0.0<br>> into: [:sum :proportion | sum + proportion]) =
1.0<br>><br>><br>> But this following code returns false !<br>> (#(0.3 0.6 0.1) inject: 0.0<br>> into: [:sum :proportion | sum + proportion]) = 1.0<br>><br>><br>> An idea ?
<br>><br>> Fréd<br>> --<br>> Frédéric Pluquet<br>> Université Libre de Bruxelles (ULB)<br>> Assistant<br>><br><br>--<br>=<br>=<br>=<br>========================================================================
<br><br>John M. McIntosh <<a href="mailto:johnmci@smalltalkconsulting.com">johnmci@smalltalkconsulting.com</a>><br>Corporate Smalltalk Consulting Ltd. <a href="http://www.smalltalkconsulting.com">http://www.smalltalkconsulting.com
</a><br>=<br>=<br>=<br>========================================================================<br><br></blockquote></div><br><br clear="all"><br>-- <br>Frédéric Pluquet<br>Université Libre de Bruxelles (ULB)<br>Assistant
</div>