<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">2014-04-09 22:23 GMT+02:00 Nicolas Cellier <span dir="ltr">&lt;<a href="mailto:nicolas.cellier.aka.nice@gmail.com" target="_blank">nicolas.cellier.aka.nice@gmail.com</a>&gt;</span>:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">2014-04-09 20:16 GMT+02:00 Nicolas Cellier <span dir="ltr">&lt;<a href="mailto:nicolas.cellier.aka.nice@gmail.com" target="_blank">nicolas.cellier.aka.nice@gmail.com</a>&gt;</span>:<div>
<div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_quote">

2014-04-09 17:53 GMT+02:00 Chris Muller <span dir="ltr">&lt;<a href="mailto:asqueaker@gmail.com" target="_blank">asqueaker@gmail.com</a>&gt;</span>:<div><div><br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">It&#39;s just a different printOn: method.  The new one shows the &quot;truth&quot;.<br>
 You must now use one of the print formatting methods to display<br>
pretty Floats.<br>
<div><div><br>
On Wed, Apr 9, 2014 at 10:07 AM, Vaidotas Didžbalis &lt;<a href="mailto:vaidasd@gmail.com" target="_blank">vaidasd@gmail.com</a>&gt; wrote:<br>
&gt; 1245 *  0.01 evaluates to 12.45 in Squeak 4.3, but it is<br>
&gt; 12.450000000000001 in later versions.<br>
&gt; regatds,<br>
&gt; Vaidotas<br>
&gt;<br>
<br></div></div></blockquote><br></div></div><div>Every two different Float shall have a different printString:<br>(12.45) = (1245*0.01) -&gt; false.<br></div><div>So...<br></div><div><br></div><div>The printString shall be the shortest decimal that rounds to the same float.<br>


</div><div>It&#39;s hard to demonstrate with a simple snippet, but you can check that we are very close yet:<br></div><div>((Fraction readFrom: &#39;12.450000000000001&#39;) - (1245*0.01) asTrueFraction) / (1245*0.01) ulp.<br>


<div></div>((Fraction readFrom: &#39;12.45&#39;) - (1245*0.01) asTrueFraction) / (1245*0.01) ulp.</div><div> <br></div></div><br></div></div></blockquote><div><br></div></div></div><div>Maybe some other usefull expressions:<br>
<br>((1245*0.01) asTrueFraction printShowingMaxDecimalPlaces: Float precision - Float emin + 1)<br>
-&gt; &#39;12.4500000000000010658141036401502788066864013671875&#39;<br><br></div><div>&quot;Find least number of decimals necessary for converting back to the same float&quot;<br></div><div>((1 to: Float precision - Float emin + 1) detect: [:i | ((1245*0.01) asTrueFraction roundTo: (10 raisedTo: i) reciprocal) asFloat = (1245*0.01)])<br>

-&gt; 15<br></div></div><br></div><div class="gmail_extra">&quot;A variant...&quot;<br></div><div class="gmail_extra">((1 to: Float precision - Float emin + 1) detect: [:i | (((1245*0.01) asTrueFraction roundTo: (10 raisedTo: i) reciprocal) - (1245*0.01) asTrueFraction) abs &lt;= ((1245*0.01) ulp / 2)])<br>

-&gt; 15<br><br>((1245*0.01) asTrueFraction printShowingDecimalPlaces: 15)<br> &#39;12.450000000000001&#39;<br></div></div></blockquote><div><br></div><div>Ah, and of course, don&#39;t forget those ones:<br><br>(12.45 asTrueFraction printShowingMaxDecimalPlaces: Float precision - Float emin + 1)<br>
-&gt; &#39;12.449999999999999289457264239899814128875732421875&#39; <br><br></div><div>so:<br><br></div><div>12.45s2 = 12.45<br></div><div>-&gt; false<br></div></div><br></div><div class="gmail_extra">Float are represented in binary internally, not decimals, so every conversion binary &lt;-&gt; decimal might be inexact (and most often is).<br>
</div></div>