[plt-scheme] ProfessorJ, ==, and double

From: Viera K.Proulx (vkp at ccs.neu.edu)
Date: Tue Jan 25 10:11:41 EST 2005

Yes, there is, as we do not want students to compare two doubles for 
equality.
10.0/3.0 is not 0.333333 - and in our examples should be.

I plan to include the following in the Examples class in the lecture 
tomorrow:

// determine whether the two given double values are the same within 
0.001
boolean sameDoubles(value1, value2){
   return Math.abs(value1 - value2) < 0.0001;
}

Examples that illustrate the use:

sameDoubles(5.0, 0.499) --> true
sameDoubles(3.33333, 10.0/3) --> true
sameDoubles(2.0, 2.001) --> false

- Viera

On Jan 25, 2005, at 8:51 AM, Carl Eastlund wrote:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> The == operator doesn't operate on type double in ProfessorJ: Beginner
> in DrScheme v209.  It works fine in ProfessorJ: Advanced, but we've
> needed it in our earliest examples in the HtDCH class.  We can work
> around it with new Double(x).equals(new Double(y)), but yuck.  Is
> there any reason for this being left out of the Beginner level?
>
> --Carl
>



Posted on the users mailing list.