[Haskell-cafe] NaN, Infinity literals
Bertram Felgenhauer
bertram.felgenhauer at googlemail.com
Thu Sep 7 05:18:07 EDT 2006
Hi,
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
> NaN
> *Main> nan==0/0
> False
This is correct according to the IEEE 754 standard, which defines
that NaN compares unequal to everything, including itself.
You can test the numbers using the isNaN and isInfinite functions.
Incidentally, one can define
isNaN x = x /= x
for IEEE floating point numbers. Comparing with +Infinity and
-Infinity works as expected.
regards,
Bertram.
More information about the Haskell-Cafe
mailing list