[Haskell-cafe] 1/0

Evan Laforge qdunkan at gmail.com
Mon Jun 16 19:07:33 EDT 2008


So, I know this has been discussed before, but:

> 1/0
Infinity
> 0/0
NaN

... so I see from the archives that Infinity is mandated by ieee754
even though my intuition says both should be NaN.

Every other language throws an exception, even C will crash the
program, so I'm guessing it's telling the processor / OS to turn these
into signals, while GHC is turning that off.  Or something.  But then
what about this note in Control.Exception:

(NOTE: GHC currently does not throw ArithExceptions except for DivideByZero)

Doesn't this imply GHC should be throwing DivideByZero?  Why is it in
the stdlib if it's turned off?  And why would it be turned off?

I suppose I could accept the above since Infinity *is* an exceptional
value meant to represent things like 1/0, and it can be nice to see
NaNs in your output instead of crashing everything (this is, I assume,
why ieee754 has these modes in the first place), but how about this:

> round (0/0) :: Integer
(huge negative number)

Ok, so integral types don't have that exceptional value.  Shouldn't
trying to convert NaN or Infinity to an Integral throw something?  Is
it a performance thing?  I'd think if you're converting to Integer you
don't really need hardware level performance anyway, so a couple of
checks wouldn't kill anyone.


More information about the Haskell-Cafe mailing list