alice-teacher Possible Problem with Alice 3.3

Michael L Owen MrGrog at outlook.com
Sun Jun 4 15:19:20 EDT 2017


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.

Including a patched version that works a little better.


Mike

________________________________
From: alice-teachers <alice-teachers-bounces+mrgrog=outlook.com at lists.andrew.cmu.edu> on behalf of Donald Slater <djslater107 at mac.com>
Sent: Sunday, June 4, 2017 8:52 AM
To: Alice Teachers
Subject: Re: alice-teacher Possible Problem with Alice 3.3

Michael,
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: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html)

What Every Computer Scientist Should Know About Floating ...<https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html>
docs.oracle.com
Abstract. Floating-point arithmetic is considered an esoteric subject by many people. This is rather surprising because floating-point is ubiquitous in computer systems.



When I run Java equivalent code, as in:

double counter = 0.0;
        while (counter < 2.0) {
            counter += 0.1;
            System.out.println("counter: " + counter);
        }

I get the following output:

counter: 0.1
counter: 0.2
counter: 0.30000000000000004
counter: 0.4
counter: 0.5
counter: 0.6
counter: 0.7
counter: 0.7999999999999999
counter: 0.8999999999999999
counter: 0.9999999999999999
counter: 1.0999999999999999
counter: 1.2
counter: 1.3
counter: 1.4000000000000001
counter: 1.5000000000000002
counter: 1.6000000000000003
counter: 1.7000000000000004
counter: 1.8000000000000005
counter: 1.9000000000000006
counter: 2.0000000000000004

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.

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

double counter = 0.0;
        while (counter < 2.0) {
            counter += 0.1;
            DecimalFormat df = new DecimalFormat("#.##");
            System.out.println("counter: " + df.format(counter));
        }

Output:
counter: 0.1
counter: 0.2
counter: 0.3
counter: 0.4
counter: 0.5
counter: 0.6
counter: 0.7
counter: 0.8
counter: 0.9
counter: 1
counter: 1.1
counter: 1.2
counter: 1.3
counter: 1.4
counter: 1.5
counter: 1.6
counter: 1.7
counter: 1.8
counter: 1.9
counter: 2

This is probably not something that will happen soon, however.

I apologize if I have misunderstood you in some way.

Thank you,
Don Slater


On Jun 3, 2017, at 2:39 PM, Michael L Owen <mrgrog at outlook.com<mailto:mrgrog at outlook.com>> wrote:

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.
I decided to try few options, but into a problem with the display almost immediately. I'm running the 64-bit Alice 3.3.
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.

Maybe a Bug?
Mike Owen

<TimerExample.a3p>_______________________________________________
alice-teachers mailing list
alice-teachers at lists.andrew.cmu.edu<mailto:alice-teachers at lists.andrew.cmu.edu>
To change settings or unsubscribe visit:
https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20170604/5f4595ad/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TimerExamplePatch.a3p
Type: application/octet-stream
Size: 44739 bytes
Desc: TimerExamplePatch.a3p
URL: <http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20170604/5f4595ad/attachment.obj>


More information about the alice-teachers mailing list