[clean-list] Exercise 2 from Chapter 2 of Clean Book

Zeno zenem@earthlink.net
Wed, 19 Nov 2003 16:17:24 -0800


Howdy,

The problem is...

   Finite precision of reals. Execute the start expression given
   in section 2.4.2.  Rewrite the program such that it only prints
   the smallest number that is different from zero using the
   function until.

The program we must rewrite is...

   Start = takeWhile ((<>) 0.0) (iterate (\x -> x/10.0) 1.0)

...and this is what I came up with...

   Start = until((==) 0.0 o (*) 0.1) (\x->x*0.1) 1.0

I did see a previous message about the same problem which directed the
poster to http://www.cs.kun.nl/pipermail/clean-list/2001/001639.html .
I think I have done what the message says to do, but I do not
understand in that post why one version transfers the value to a
register before comparison, but the other doesn't.

But even so, shouldn't the following work...

   Start = until((==) 0.0 o (*) 0.00000000001) (\x->x*0.1) 1.0

...it doesn't, the following works...

   Start = until((==) 0.1 o (*) 0.1) (\x->x*0.1) 1.0

---but the following does not work...

   Start = until((==) 0.01 o (*) 0.1) (\x->x*0.1) 1.0

Can anyone help me with this?

Thank you,
   - Zeno