
I think this is a bug. It also seems to impact explicitly sized types:
Prelude Data.Int> (minBound::Int8) `quot` (-1)
*** Exception: arithmetic overflow
Prelude Data.Int> (minBound::Int16) `quot` (-1)
*** Exception: arithmetic overflow
You should definitely report it. I think there's a pending release of GHC,
so they might be able to fix it shortly.
-Levent.
On Thu, Jan 23, 2014 at 10:33 PM, Rob Leslie
Greetings,
I have a question about arithmetic overflow in Haskell -- actually, probably specifically in GHC.
It’s my understanding from the Haskell 2010 Language Report that “The results of exceptional conditions (such as overflow or underflow) on the fixed-precision numeric types [e.g. Int] are undefined; an implementation may choose error (⊥, semantically), a truncated value, or a special value such as infinity, indefinite, etc.”
In the documentation for Data.Int from the current release of the Haskell Platform, I read that “All arithmetic is performed modulo 2^n, where n is the number of bits in the type.”
However, there seems to be at least one exception to this promise, namely:
λ> (minBound :: Int) `quot` (-1) *** Exception: arithmetic overflow
Is this a bug?
More specifically, is it intended to be safe to rely on the modulo arithmetic behavior of GHC in spite of the Language Report? And if so, should the above witnessed behavior still be expected?
Thanks,
-- Rob Leslie rob@mars.org
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe