[Haskell-cafe] NaN, Infinity literals
u.stenzel at web.de
Thu Sep 7 06:05:36 EDT 2006
Tamas K Papp wrote:
> Is there a way to use NaN and Infinity as literals, or at least to
> test if a value is NaN or Infinity?
> *Main> let nan=0/0
> *Main> nan
> *Main> nan==0/0
> so "storing" the value does not work...
Not sure what you mean here. In IEEE floating point, NaN is not equal
to anything, especially not to itself. So the above worked, didn't it?
isNaN :: Double -> Bool
isNaN x = not (x == x)
but this is wrong (I believe):
isNaN' :: Double -> Bool
isNaN' x = x /= x
Anyway, isNaN is alerady in the Prelude, and so are isInfinite,
isDenormalized and isNegativeZero.
This is all a bit ill-defined, but you'll have to live with that. If
you also want a personal advise: switch on signaling NaNs (there's a C
function to do that, simply foreign import it) and have your program
bomb out as soon as a NaN is formed. Propagating them through
calculations just increases the headache.
FORTUNE PROVIDES QUESTIONS FOR THE GREAT ANSWERS: #4
A: Go west, young man, go west!
Q: What do wabbits do when they get tiwed of wunning awound?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20060907/b0caf7f5/attachment-0001.bin
More information about the Haskell-Cafe