Skip to content

Arithmetic overflow from (minBound :: Int) `quot` (-1)

According to the documentation for Data.Int, “All arithmetic is performed modulo 2!^n, where n is the number of bits in the type.”

However, this promise is broken by the following exception:

Prelude> (minBound :: Int) `quot` (-1)
*** Exception: arithmetic overflow

(This also occurs with Int8, Int16, Int32, and Int64, and likewise for div.)

If all arithmetic is performed modulo 2!^n, I would rather expect the above to evaluate to minBound, since after all minBound * (-1) == minBound. The fact that an exception is raised adds an unnecessary burden in pure code to ensure quot (or div) is never called with these specific arguments.

Trac metadata
Trac field Value
Version 7.6.3
Type Bug
TypeOfFailure IncorrectResultAtRuntime
Priority normal
Resolution Unresolved
Component libraries/haskell2010
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information