<div dir="ltr"><div class="gmail_default" style="font-family:monospace;font-size:large">Thanks for your response, Martin!</div><div class="gmail_default" style="font-family:monospace;font-size:large">I thought that #roundTo: only affected representation, but it seems that there are some caveats when applied to floatings.</div><div class="gmail_default" style="font-family:monospace;font-size:large">I've experimented with 0.1, 0.01, and 0.001, and this misrepresentation affects other numbers in the interval. So the lesson would be: be careful with #roundUp: & similar methods when using floating as the imagined or expected representation could fail.</div><div class="gmail_default" style="font-family:monospace;font-size:large"><br></div><div class="gmail_default" style="font-family:monospace;font-size:large">Thanks again</div><div class="gmail_default" style="font-family:monospace;font-size:large">Nacho</div><div class="gmail_default" style="font-family:monospace;font-size:large"><br></div><div class="gmail_default" style="font-family:monospace;font-size:large"><br></div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><b><font size="2">Ignacio Sniechowski</font></b><b><br></b></div><div><br></div><div><b><br></b></div><div><br></div><div><b></b></div><div><b><br></b></div><div><b><br></b></div><div><b><br></b></div><div><b><br></b></div><div><b></b><br></div><b><div><b><br></b></div><div><b><br></b></div><div><b><br></b></div><br></b><b><br></b><b><br></b><div><br><br><div style="text-align:left"><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Mar 5, 2023 at 10:34 PM Martin McClure <<a href="mailto:martin@hand2mouse.com">martin@hand2mouse.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
  
    
  
  <div>
    <div>On 3/5/23 16:51, Ignacio Sniechowski
      via Cuis-dev wrote:<br>
    </div>
    <blockquote type="cite">
      <div class="gmail_default" style="font-family:monospace;font-size:large"><span style="color:rgb(0,0,0);font-size:9pt;font-family:CMTT9">Float
          pi to: 5 by: 1/3 do: [:i | Transcript show: (i roundTo: 0.01)
          ; space]<span> </span></span><span style="color:rgb(0,0,0);font-size:9pt;font-family:CMSY9">⇒<span> </span></span><span style="color:rgb(0,0,0);font-size:9pt;font-family:CMTT9">3.14
          3.47 3.81 4.14 4.47 4.81</span> </div>
      <div>
        <div dir="ltr">
          <div dir="ltr">
            <div dir="ltr">
              <div dir="ltr">
                <div dir="ltr">
                  <div dir="ltr">
                    <div dir="ltr">
                      <div dir="ltr">
                        <div dir="ltr">
                          <div dir="ltr">
                            <div dir="ltr">
                              <div dir="ltr">
                                <div dir="ltr">
                                  <div dir="ltr">
                                    <div><b><font size="2"><span class="gmail_default" style="font-family:monospace;font-size:large">"</span></font></b><b><font size="2"><span class="gmail_default" style="font-family:monospace;font-size:large"></span></font></b>3.14
                                      3.47 3.81 4.14 4.47
                                      4.8100000000000005<span class="gmail_default" style="font-family:monospace;font-size:large">"
                                        the last number is not
                                        rounded...</span></div>
                                    <div><span class="gmail_default" style="font-family:monospace;font-size:large">What
                                        is especially intriguing is the
                                        last case...that
                                        4.8100000000000005 is not
                                        rounded.</span></div>
                                    <div><span class="gmail_default" style="font-family:monospace;font-size:large"></span></div>
                                  </div>
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    Hi Nacho,<br>
    <br>
    Ah, welcome the lovely and confusing world of decimal expressions of
    binary floating-point numbers. <br>
    <br>
    What is not obvious here is that the last case <i>is</i> rounded. <br>
    <br>
    "roundTo: 0.01" requests that the result be an exact multiple of
    0.01. But 0.01 is not exactly representable as a floating-point
    number, so the closest Float is used, and that float is a bit
    greater than 1/100. <br>
    <br>
    0.01 asFraction > (1/100) ==> true<br>
    <br>
    So we end up with a float that is 481 * 0.01, which is a little more
    than 481 / 100, <i>and</i> there exists a different float which is
    closer to 481 / 100. Every float has a unique default print string.
    The string '4.81' is used for that other float, so we have to use
    the string '4.8100000000000005' for the float that is the correct
    result of the expression.<br>
    <br>
    Regards,<br>
    -Martin<br>
  </div>

</blockquote></div>