[clean-list] IEEE floating point and Clean
Siegfried Gonzi
siegfried.gonzi@kfunigraz.ac.at
Wed, 12 Sep 2001 08:48:49 +0200
Still under impression from the last day (I do not have got a
televison but after turning on the radio I have been believing the
3 world war had started) I post the following:
Currently, I read Kahan's article "How Java's floating point hurts
everone everywhere":
http://www.cs.berkeley.edu/~wkahan/
But Kahan is playing close to his chest and I cannot really figure out
what he means when he writes that Java has no possibility to handle
exceptions.
I also cannot post my question to a Java discussion group (and they are
astoundingly numerous), because they would not honor the following
Clean code in order to emphasize what bothers me.
Maybe there is a Clean user who has got a basic understanding of
Java's numerics.
- In Clean (on a Macintosh and Sun):
Start = 0.0/0.0 delivers NAN(000)
Start = 1.0/0.0 delivers INF
Start = 1.0/(-0.0) delivers -INF
Start = 0.0/(1.0/0.0) delivers 0
Start = 0.0/(1.0/(-0.0)) delivers -0
Question 1:
What does Java deliver here?
- In Clean (on a Macintosh and Sun):
Start = [(1.0/toReal(x)) \\ x <- [2,1,0,0,1,2]]
delivers [0.5,1,INF,INF,1,0.5]
Question 2:
What will Java spy out here (under the assumption that the
implemented Java function does the same as Clean his
list comprehension)?
- In Clean (on a Macintosh and Sun):
Start = [1.0/toReal(y) \\ y <- [1.0/toReal(x) \\ x <- [2,1,0,0,1,2]] ]
delivers [2,1,0,0,1,2]
Question 3:
How will Java do here?
- In Clean (on a Macintosh and Sun):
exception =[check(1.0/toReal(x)) \\ x <- [2,1,0,0,1,2]]
where
check y
| y == infinity = abort("infinity reached")
= 1.0
where
infinity = 1.0/0.0
Start = exception
delivers [1,1,infinity reached
Question 4:
What about Java here?
Are my Clean examples some sort of "exception handling"? I cannot prove
it with Java,
because I do not have installed a Java development kit on any of my
platforms.
S. Gonzi