<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Please forgive me for plugging the new book... but for purposes of
    providing<br>
    and Alice example of the "rounding error" that occurs in floating
    point computations,<br>
    see Chapter 16, sections 16.7.2 and 16.7.3, of the new <i>Alice 3
      to Java</i> textbook.<br>
    <br>
    Wanda <br>
    <br>
    On 6/4/2017 3:19 PM, Michael L Owen wrote:<br>
    <blockquote
cite="mid:SN1PR14MB0575C150BC8C841887DFBA5EDDF50@SN1PR14MB0575.namprd14.prod.outlook.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
      <div id="divtagdefaultwrapper"
style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;"
        dir="ltr">
        <p>Hi Don- Nope, You got it right. It just threw me off a bit
          when I was originally using 0.2 as the increment value and
          getting the long strings with 3DText. As Terri mentioned,
          there is always a way to get around a binary kludge like this,
          and probably good to inform students that computers aren't
          always perfect.</p>
        <p>Including a patched version that works a little better.</p>
        <p><br>
        </p>
        Mike<br>
        <br>
        <div style="color: rgb(0, 0, 0);">
          <hr tabindex="-1" style="width: 98%; display: inline-block;">
          <div id="divRplyFwdMsg" dir="ltr"><font style="font-size:
              11pt;" face="Calibri, sans-serif" color="#000000"><b>From:</b>
              alice-teachers
              <a class="moz-txt-link-rfc2396E" href="mailto:alice-teachers-bounces+mrgrog=outlook.com@lists.andrew.cmu.edu"><alice-teachers-bounces+mrgrog=outlook.com@lists.andrew.cmu.edu></a>
              on behalf of Donald Slater <a class="moz-txt-link-rfc2396E" href="mailto:djslater107@mac.com"><djslater107@mac.com></a><br>
              <b>Sent:</b> Sunday, June 4, 2017 8:52 AM<br>
              <b>To:</b> Alice Teachers<br>
              <b>Subject:</b> Re: alice-teacher Possible Problem with
              Alice 3.3</font>
            <div> </div>
          </div>
          <div>Michael,
            <div>If I understand what you are saying correctly, and if I
              am seeing what you are seeing when I run your program, you
              are seeing the results of floating point addition (in Java
              and other programming languages). (See the Rounding Error
              section in the following document: <a
                moz-do-not-send="true" id="LPlnk498948"
                href="https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html"
                previewremoved="true">https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html</a>)</div>
            <div id="LPBorder_GT_14966020936420.475383645581972"
              style="width: 100%; text-indent: 0px; overflow: auto;
              margin-bottom: 20px; display: inline-block;">
              <table id="LPContainer_14966020936180.009684158556686473"
                role="presentation" style="width: 90%; overflow: auto;
                padding-top: 20px; padding-bottom: 20px; margin-top:
                20px; border-top-color: rgb(200, 200, 200);
                border-bottom-color: rgb(200, 200, 200);
                border-top-width: 1px; border-bottom-width: 1px;
                border-top-style: dotted; border-bottom-style: dotted;
                position: relative; background-color: rgb(255, 255,
                255);" cellspacing="0">
                <tbody>
                  <tr style="border-spacing: 0px;" valign="top">
                    <td id="TextCell_14966020936220.38062014447345565"
                      style="padding: 0px; vertical-align: top; display:
                      table-cell; position: relative;" colspan="2">
                      <div
                        id="LPRemovePreviewContainer_14966020936220.10706015825925585"
                        style="float: right;">
                      </div>
                      <div id="LPTitle_14966020936220.20424583460279244"
                        style="top: 0px; color: rgb(0, 120, 215);
                        line-height: 21px; font-family:
                        "wf_segoe-ui_light", "Segoe UI
                        Light", "Segoe WP Light",
                        "Segoe UI", "Segoe WP",
                        Tahoma, Arial, sans-serif; font-size: 21px;
                        font-weight: 400;">
                        <a moz-do-not-send="true"
                          id="LPUrlAnchor_14966020936290.05506855051623244"
                          style="text-decoration: none;"
                          href="https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html"
                          target="_blank">What Every Computer Scientist
                          Should Know About Floating ...</a></div>
                      <div
                        id="LPMetadata_14966020936300.9902409290815635"
                        style="margin: 10px 0px 16px; color: rgb(102,
                        102, 102); line-height: 14px; font-family:
                        "wf_segoe-ui_normal", "Segoe
                        UI", "Segoe WP", Tahoma, Arial,
                        sans-serif; font-size: 14px; font-weight: 400;">
                        docs.oracle.com</div>
                      <div
                        id="LPDescription_14966020936360.8452525816514639"
                        style="color: rgb(102, 102, 102); line-height:
                        20px; overflow: hidden; font-family:
                        "wf_segoe-ui_normal", "Segoe
                        UI", "Segoe WP", Tahoma, Arial,
                        sans-serif; font-size: 14px; font-weight: 400;
                        display: block; max-height: 100px;">
                        Abstract. Floating-point arithmetic is
                        considered an esoteric subject by many people.
                        This is rather surprising because floating-point
                        is ubiquitous in computer systems.</div>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
            <br>
            <div><br>
            </div>
            <div>When I run Java equivalent code, as in:<span class="Apple-tab-span" style="white-space: pre;">
</span></div>
            <div><br>
            </div>
            <div>
              <div><span class="Apple-tab-span" style="white-space: pre;"></span>double
                counter = 0.0;</div>
              <div>        while (counter < 2.0) {</div>
              <div>            counter += 0.1;</div>
              <div>            System.out.println("counter: " +
                counter);</div>
              <div>        }</div>
              <div><br>
              </div>
              <div>I get the following output: </div>
              <div><br>
              </div>
            </div>
            <blockquote style="margin: 0px 0px 0px 40px; padding: 0px;
              border: currentColor; border-image: none;">
              <div>
                <div>
                  <div>counter: 0.1</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 0.2</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 0.30000000000000004</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 0.4</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 0.5</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 0.6</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 0.7</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 0.7999999999999999</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 0.8999999999999999</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 0.9999999999999999</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.0999999999999999</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.2</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.3</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.4000000000000001</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.5000000000000002</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.6000000000000003</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.7000000000000004</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.8000000000000005</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.9000000000000006</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 2.0000000000000004</div>
                </div>
              </div>
              <div><br>
              </div>
            </blockquote>
            If you make your counter a WholeNumber variable, which is
            our typical implementation, which might make sense as you
            are using a 1 second delay between each update, your code
            will work as you expect.
            <div><br>
            </div>
            <div>Although this is not a bug, it may suggest that
              sometime Alice implement a decimal precision option that
              mimics the DecimalFormat class of Java… See the following
              Java example and output</div>
            <div><br>
            </div>
            <div>
              <div><span class="Apple-tab-span" style="white-space: pre;"></span>double
                counter = 0.0;</div>
              <div>        while (counter < 2.0) {</div>
              <div>            counter += 0.1;</div>
              <div>            <b>DecimalFormat df = new
                  DecimalFormat("#.##");</b></div>
              <div>            System.out.println("counter: " +
                df.format(counter));</div>
              <div>        }</div>
              <div><br>
              </div>
              <div>Output:</div>
            </div>
            <blockquote style="margin: 0px 0px 0px 40px; padding: 0px;
              border: currentColor; border-image: none;">
              <div>
                <div>
                  <div>counter: 0.1</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 0.2</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 0.3</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 0.4</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 0.5</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 0.6</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 0.7</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 0.8</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 0.9</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.1</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.2</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.3</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.4</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.5</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.6</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.7</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.8</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 1.9</div>
                </div>
              </div>
              <div>
                <div>
                  <div>counter: 2</div>
                </div>
              </div>
            </blockquote>
            <div>
              <div><br>
              </div>
              <div>This is probably not something that will happen soon,
                however.</div>
              <div><br>
              </div>
              <div>I apologize if I have misunderstood you in some way.</div>
              <div><br>
              </div>
              <div>Thank you,</div>
              <div>Don Slater</div>
              <div><br>
              </div>
              <div><br>
              </div>
              <div>
                <div>
                  <blockquote type="cite">
                    <div>On Jun 3, 2017, at 2:39 PM, Michael L Owen <<a
                        moz-do-not-send="true"
                        href="mailto:mrgrog@outlook.com">mrgrog@outlook.com</a>>
                      wrote:</div>
                    <br class="Apple-interchange-newline">
                    <div>
                      <div id="divtagdefaultwrapper"
                        style="text-transform: none; text-indent: 0px;
                        letter-spacing: normal; font-family:
                        Calibri,Arial,Helvetica,sans-serif,EmojiFont,"Apple
                        Color Emoji","Segoe UI
                        Emoji",NotoColorEmoji,"Segoe UI
                        Symbol","Android
                        Emoji",EmojiSymbols; font-size: 12pt;
                        font-style: normal; font-weight: normal;
                        word-spacing: 0px; white-space: normal;"
                        dir="ltr">
                        <div style="margin-top: 0px; margin-bottom:
                          0px;">Hi All- I was looking at a post recently
                          that addressed adding a timer loop to a
                          program that would display the timer while
                          counting up to the finish.</div>
                        <div style="margin-top: 0px; margin-bottom:
                          0px;">I decided to try few options, but into a
                          problem with the display almost immediately.
                          I'm running the 64-bit Alice 3.3.</div>
                        <div style="margin-top: 0px; margin-bottom:
                          0px;">On my machine the number
                          displayed appears to be encountering a
                          rounding error of some sort that causes the
                          number to be expanded the maximum.</div>
                        <div style="margin-top: 0px; margin-bottom:
                          0px;"><br>
                        </div>
                        <div style="margin-top: 0px; margin-bottom:
                          0px;">Maybe a Bug?</div>
                        <div style="margin-top: 0px; margin-bottom:
                          0px;">Mike Owen  </div>
                        <div style="margin-top: 0px; margin-bottom:
                          0px;"><br>
                        </div>
                      </div>
                      <span
                        id="cid:2A8BF2CA-EE03-4BA2-BFA9-3DC8F16FF767@T-mobile.com"><TimerExample.a3p></span><span
                        style="text-transform: none; text-indent: 0px;
                        letter-spacing: normal; font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-weight: normal; word-spacing: 0px; float:
                        none; display: inline !important; white-space:
                        normal;">_______________________________________________</span><br
                        style="text-transform: none; text-indent: 0px;
                        letter-spacing: normal; font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-weight: normal; word-spacing: 0px;
                        white-space: normal;">
                      <span style="text-transform: none; text-indent:
                        0px; letter-spacing: normal; font-family:
                        Helvetica; font-size: 14px; font-style: normal;
                        font-weight: normal; word-spacing: 0px; float:
                        none; display: inline !important; white-space:
                        normal;">alice-teachers mailing list</span><br
                        style="text-transform: none; text-indent: 0px;
                        letter-spacing: normal; font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-weight: normal; word-spacing: 0px;
                        white-space: normal;">
                      <a moz-do-not-send="true" style="text-transform:
                        none; text-indent: 0px; letter-spacing: normal;
                        font-family: Helvetica; font-size: 14px;
                        font-style: normal; font-weight: normal;
                        word-spacing: 0px; white-space: normal;"
                        href="mailto:alice-teachers@lists.andrew.cmu.edu">alice-teachers@lists.andrew.cmu.edu</a><br
                        style="text-transform: none; text-indent: 0px;
                        letter-spacing: normal; font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-weight: normal; word-spacing: 0px;
                        white-space: normal;">
                      <span style="text-transform: none; text-indent:
                        0px; letter-spacing: normal; font-family:
                        Helvetica; font-size: 14px; font-style: normal;
                        font-weight: normal; word-spacing: 0px; float:
                        none; display: inline !important; white-space:
                        normal;">To change settings or unsubscribe
                        visit:</span><br style="text-transform: none;
                        text-indent: 0px; letter-spacing: normal;
                        font-family: Helvetica; font-size: 14px;
                        font-style: normal; font-weight: normal;
                        word-spacing: 0px; white-space: normal;">
                      <a moz-do-not-send="true" style="text-transform:
                        none; text-indent: 0px; letter-spacing: normal;
                        font-family: Helvetica; font-size: 14px;
                        font-style: normal; font-weight: normal;
                        word-spacing: 0px; white-space: normal;"
                        href="https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers">https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers</a></div>
                  </blockquote>
                </div>
                <br>
              </div>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
alice-teachers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:alice-teachers@lists.andrew.cmu.edu">alice-teachers@lists.andrew.cmu.edu</a>
To change settings or unsubscribe visit:
<a class="moz-txt-link-freetext" href="https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers">https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers</a></pre>
    </blockquote>
    <br>
  </body>
</html>