
#8695: Arithmetic overflow from (minBound :: Int) `quot` (-1) ------------------------------------------------+-------------------------- Reporter: rleslie | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/haskell2010 | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result at runtime | Unknown/Multiple Test Case: | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Comment (by rleslie): Replying to [comment:2 hvr]:
Fwiw, you also have to avoid calling `quot`/`div` with a `0`-divisor, otherwise a div-by-zero exception is raised. I wonder if this isn't rather a deficiency of the Haskell2010 report, failing to mention that the modulo-semantics make an exception for the `quot`/`div` operations.
I think a division-by-zero exception is reasonably well-understood, since there is no value {{{q = d `quot` 0}}} that could be returned in general such that `q * 0 == d`, even with modulo arithmetic. Most code performing division with arbitrary operands is well aware of the possibility of a division-by-zero exception, and defensively avoids it. Much less well known or understood, I think, is the possibility of overflow from the singular case of {{{minBound `quot` (-1)}}} which, if not accounted for, can also break one’s application (and possibly be a vector for denial-of-service attacks…) I think I’d much rather have {{{minBound `quot` (-1) == minBound}}} under modulo arithmetic than a justification for the current exception. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8695#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler