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

 From: Carl Eastlund (carl.eastlund at gmail.com) Date: Tue Jan 25 15:41:34 EST 2005 Previous message: [plt-scheme] ProfessorJ, ==, and double Next message: [plt-scheme] ProfessorJ, ==, and double Messages sorted by: [date] [thread] [subject] [author]

```On Tue, 25 Jan 2005 15:18:00 -0500, Don Blaheta <dblaheta at knox.edu> wrote:
> Quoth Carl Eastlund:
> > I'm very wary of the claim that this is "correct".  For very very
> > large values - the distance in meters between galaxies, for instance -
> > this epsilon is woefully small and this might as well be the == test.
> > For very very small values - the distance in meters between electrons,
> > for instance - this epsilon is woefully large and this might as well
> > be the constant true.
>
> Sorry, I thought it was clear that epsilon is not a universally constant
> value; that's why I named it instead of just using 1e-4 directly.  When
> I introduce this idea in class, I also include the fact that you need to
> pick an appropriate value of epsilon for the sorts of values you'll be
> using.

That's a good practice.  Not everyone is so careful.

> > I think floating-point comparison is a trickier issue than this, and
> > not one necessarily solvable by making freshman students declare or
> > use a constant epsilon.
>
> Perhaps, but it's certainly not solved by letting students use ==
> willy-nilly.

If either way has to be given with a caveat, there's at least
something to be said for choosing the simpler of the two incomplete
solutions.  I'm with you that epsilon-testing is probably better, but
"==" gives them something to write in the first week or two.

> But where are you actually using == ?  Test cases don't require them.

Test cases don't test anything unless they compare to an expected
value, and putting "should be about 3.33" in a comment doesn't force
the students to actually perform the comparison.  So we try to get
them to produce booleans in code as often as possible, which requires
comparing results (often doubles) to something or other.

--Carl

```

 Posted on the users mailing list. Previous message: [plt-scheme] ProfessorJ, ==, and double Next message: [plt-scheme] ProfessorJ, ==, and double Messages sorted by: [date] [thread] [subject] [author]