alice-teacher s Digest, Vol 37, Issue 8

Deane Fistick deane.fistick at ecotoh.org
Wed Aug 14 12:28:35 EDT 2013


Bob,

Thanks for the explanation and suggestion. The "within a tolerance" approach is a good alternative.

Deane

-----Original Message-----
From: alice-teachers-bounces+deane.fistick=ecotoh.org at lists.andrew.cmu.edu [mailto:alice-teachers-bounces+deane.fistick=ecotoh.org at lists.andrew.cmu.edu] On Behalf Of Robert Durtschi
Sent: Wednesday, August 14, 2013 6:24 AM
To: alice-teachers at lists.andrew.cmu.edu
Subject: Re: alice-teacher s Digest, Vol 37, Issue 8

There has always been a problem comparing two floats/doubles for equality, at least during the 44 years that I've been playing with computers, because of the way that the floating point values are stored, as binary fractions, and the inability of some fractions such as 1/6 in decimal to be expressed exactly in decimal (or binary) form.  Sometimes it works, sometimes it doesn't depending on the value. The safest way to do such a comparison is to compare the difference to a delta, say 0.001. 
 i.e. 
      if ((x - int(x)) < closeEnough) then <do equality process> else <do inequality process>

where: closeEnough is a constant containing your delta value.

Best
Bob Durtschi
________________________________________
From: alice-teachers-bounces+robert.durtschi=gcsu.edu at lists.andrew.cmu.edu [alice-teachers-bounces+robert.durtschi=gcsu.edu at lists.andrew.cmu.edu] on behalf of alice-teachers-request at lists.andrew.cmu.edu [alice-teachers-request at lists.andrew.cmu.edu]
Sent: Tuesday, August 13, 2013 12:00 PM
To: alice-teachers at lists.andrew.cmu.edu
Subject: alice-teachers Digest, Vol 37, Issue 8

Send alice-teachers mailing list submissions to
        alice-teachers at lists.andrew.cmu.edu

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers
or, via email, send a message with subject or body 'help' to
        alice-teachers-request at lists.andrew.cmu.edu

You can reach the person managing the list at
        alice-teachers-owner at lists.andrew.cmu.edu

When replying, please edit your Subject line so it is more specific than "Re: Contents of alice-teachers digest..."


Today's Topics:

   1. Re:  Problem with INT function?? (Deane Fistick)


----------------------------------------------------------------------

Message: 1
Date: Mon, 12 Aug 2013 16:50:09 +0000
From: Deane Fistick <deane.fistick at ecotoh.org>
Subject: Re: alice-teacher Problem with INT function??
To: "'Alice educators'" <alice-teachers at lists.andrew.cmu.edu>
Message-ID:
        <BF8F8509F51BED4C91C1A2362BE45766AEE31658 at DCMBEXCH01a.ecotoh.net>
Content-Type: text/plain; charset="iso-8859-1"

Thanks Claude,

I think you're on the right "track". I will continue to suggest the "rearranged" formula for now.

Strangely, a simple version of the program that Don Slater sent me (made on his Mac) runs correctly on my Windows machine.

Deane

From: alice-teachers-bounces+deane.fistick=ecotoh.org at lists.andrew.cmu.edu [mailto:alice-teachers-bounces+deane.fistick=ecotoh.org at lists.andrew.cmu.edu] On Behalf Of "C. Gu?ganno"
Sent: Sunday, August 11, 2013 1:39 PM
To: Alice educators
Subject: Re: alice-teacher Problem with INT function??



 it could be  problem of type..
 if NumberEntered  is of type double or float (i.e. decimal number) ,
    NumberEntered == (int)NumberEntered   is always false
 (entering a whole number  does not modify its type)

 Your second test is good. By rearranging the equation, you modify the types :
    left side: (decimal number) - (whole number) -> the result is of  type 'decimal value'
    right side : 0 is automatically interpreted as 0.0 (due to the left side)

All the best
Claude Gueganno
http://www.st-joseph-lorient.org/



Le 11/08/2013 18:23, Deane Fistick a ?crit :
Hi Don,

I recently downloaded Alice 2.3.5 preparing for the coming school year. I was pleased to see that the INT function (in advanced math) is now a number rather than a string.

However I had some trouble getting it to work properly. I was teaching the kids how to check to make sure the user had entered a whole number when asked.

If NumberEntered = Int(NumberEntered) should be true if a whole number is entered - but that doesn't seem to work.

I did figure out a "work around" by rearranging the equation.

If NumberEntered - Int(NumberEntered) = 0 seems to work OK.

Although we have a "work around", the first If statement is the most straight forward, logical approach, and I would like to use it if possible.

Do you know of any reason why the first If statement shouldn't work?

I've attached a copy of the relevant part of my lesson, which includes more detail and pictures that may help.

Thanks,
Deane Fistick
ECOT (Electronic Classroom Of Tomorrow)




_______________________________________________

alice-teachers mailing list

alice-teachers at lists.andrew.cmu.edu<mailto:alice-teachers at lists.andrew.cmu.edu>

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/20130812/8446d8e1/attachment-0001.html

------------------------------

_______________________________________________
alice-teachers mailing list
alice-teachers at lists.andrew.cmu.edu
https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers


End of alice-teachers Digest, Vol 37, Issue 8
*********************************************
_______________________________________________
alice-teachers mailing list
alice-teachers at lists.andrew.cmu.edu
https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers


More information about the alice-teachers mailing list