#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 hvr): Fwiw as a precedent, the following C99 program when compiled with gcc or clang, and executed on Linux results in a runtime exception as well: {{{#!c #include <stdio.h> #include <inttypes.h> int main(int argc, char *argv[]) { volatile int32_t a = INT32_MIN; volatile int32_t b = -1; volatile int32_t c = a / b; printf("%" PRId32 "\n", c); return 0; } }}} Given that `quot`/`div` is already a partial function due to div-by-zero, and {{{minBound `quot` -1}}} being the only special case (beside div-by- zero) for (`quot`/`div`) which leads to a result outside the `[minBound..maxBound]` range, so I'd rather have this exception thrown than to have a program which didn't take into account this non-obvious overflow silently misbehaving due to a flipped sign (as you pointed out yourself if I understood you correctly, but then dismissed it as not being worth an exception). PS: I believe one may as well argue (as an academic exercise) in a parallel way, that `quotRem` by 0 could be assigned a value that satisfies the laws from ยง 6.4.2 as well, thus making it a total function. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8695#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler