[clean-list] Rounding problems

Jerzy Karczmarczuk karczma@info.unicaen.fr
Wed, 24 Jan 2001 11:59:30 +0000


Good day.

Yesterday I sent to the Clean team a question concerning the
behaviour of toInt.

It rounds sometimes to the nearest *even*. This program

l = map toReal [-2 .. 20]
Start = map (\x -> toInt (x-0.5)) l

produces
[-2,-2,0,0,2,2,4,4,6,6,8,8, ... etc. ]

and for two days I couldn't debug my program, I thought really
that I am becoming selectively blind or crazy. I asked "why" -

the function 'entier' behaves differently than a naive truncation
obtained from rounding by toInt (x-0.5).

John van Groningen answered concisely, mentioning the IEEE floating-
point standard. Thank you very much, John.

I report this problem on a larger forum, because it might be of
general interest.

First, I suggest to the Clean Team, to describe this explicitly in
the manual, and even to underline it using red ink. Not all people
who want to apply Clean for numerics know that.

Then, the IEEE standard is not as simple as that. There is a plethora
of possible solutions: four legal rounding schemes, and often several 
different ones are proposed.
Perhaps your toInt should be called 'nearest' like in some libraries
which keep references to ANSI/IEEE Std 754-1985 (the standards of
SUN, or AIX, etc.)



==

[[Off the record. If you want to know where I had problems: I wrote
a small program which generates Scottish Tartan/plaid patterns, such
silly exercise as here:
http://users.info.unicaen.fr/~karczma/extras/tartan.gif
I got something very different from the known standards, and I was
afraid
that a Scottish ghost of a mighty clean, ugh! I meant CLAN, might haunt 
my house to punish me for this horrible corruption...]]


Regards

Jerzy Karczmarczuk
Caen, France