floating-point NaN handling in Squeak
janb at pmatrix.com
Fri Feb 19 21:23:26 UTC 1999
I've been following the messages about curious Float errors and am
wondering if a big part the problem is NaN propogation.
Squeak seems to rairly test for NaN's before or after an operation. My
understanding of alternative floating point error modes is: you can get a
processor exception when certain errors occur (much like integer division
by 0), or you tell the processor not to fault, but to return a
distinguishing value (NaN) when an error occurs. Your code should then
explicitly test for this value, and "do the right thing" when an error
happens. The right thing may be to inform the user or abort some calculation.
It offhand seems like the right thing for a floating point primitive to do
when passed a NaN value would be to fail the primitive. Also mabey when a
floating point primitive is going to return a NaN, it should also fail. I
looked at the VM, and currently, NaN's are pretty much just passed thru and
returned, like nothing is wrong.
I don't have any experience with writing major floating-point code in
Smalltalk, so magically propagating NaN's may be the correct thing to do.
NaN error do seem exactly like division by zero though, which is immediatly
noticed. I think most of us would not think returning an integer form of
NaN as the result of division by zero was the right thing to do. I could
argue that immediate detecting and handling of any NaN values is the right
thing to do. Or perhaps we need Float and QuiteFloat classes, which have
significantly different error handling. Or perhaps Float objects need an
instance variable to tell what to do in case of error.
Paradigm Matrix Inc., San Ramon California
"video products and development services for Win32 platforms"
Internet: Jan Bottorff janb at pmatrix.com
Phone: voice (925) 803-9318
fax (925) 803-9397
PGP: public key <http://www-swiss.ai.mit.edu/~bal/pks-toplev.html>
fingerprint 52 CB FF 60 91 25 F9 44 6F 87 23 C9 AB 5D 05 F6
More information about the Squeak-dev