[GHC] #8695: Arithmetic overflow from (minBound :: Int) `quot` (-1)
GHC
ghc-devs at haskell.org
Fri Jan 24 21:36:49 UTC 2014
#8695: Arithmetic overflow from (minBound :: Int) `quot` (-1)
-------------------------------------+-------------------------------------
Reporter: rleslie | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: | Version: 7.6.3
libraries/haskell2010 | Operating System: Unknown/Multiple
Keywords: | Type of failure: Incorrect result
Architecture: Unknown/Multiple | at runtime
Difficulty: Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: |
-------------------------------------+-------------------------------------
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.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8695>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list