alice-teacher Possible Problem with Alice 3.3

Donald Slater djslater107 at mac.com
Sun Jun 4 09:52:30 EDT 2017


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

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> 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 <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/ec33995f/attachment.html>


More information about the alice-teachers mailing list