[clean-list] Lists

Tomasz Zielonka t.zielonka@students.mimuw.edu.pl
Tue, 21 May 2002 21:14:48 +0200


On Tue, May 21, 2002 at 03:39:51PM -0300, Willer Alves wrote:
> 
> 	makeList x y h
> 	|x==y = x
> 	|otherwise = makeList (x + h) y h
> 	
> 	Start = makeList 1.0 2.0 0.1
> 
> The answer is an infinity loop. Again, it works with y >= 5.0 (Start = 
> makeList 1.0 5.0 0.1), or writing (x>=y) instead of (x==y).
> 
> What could be the problem?

This is a well known problem that Real numbers can't be (effectively)
exactly represented in computers. You should not rely so much on
comparison between Reals/floats, because certain numbers cannot be exactly
represented in Clean's Real type (like 0.1, 1.1) and because arithmetic
operations introduce round-off errors.

Some programming languages, SML for example, even disallow equality test
between reals.

There is Rational type in Clean 2.0's ExtendedArith library, with which
you can do exact computations on Rational numbers.

> Best regards,
> Willer Alves
> Brazil

cheers,
Tom

-- 
.signature: Too many levels of symbolic links