24 Jan 07:33 2014

## Arithmetic overflow

Rob Leslie <rob <at> mars.org>

2014-01-24 06:33:34 GMT

2014-01-24 06:33:34 GMT

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)(Continue reading)*** 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 <at> mars.org _______________________________________________ Haskell-Cafe mailing list