Over/underflow semantics for 'Int' et al.
Herbert Valerio Riedel
hvr at gnu.org
Wed Jan 29 11:09:51 UTC 2014
Hello *,
I'd like to point your attention to
https://ghc.haskell.org/trac/ghc/ticket/8695
which brings up the issue what the results operations such as
* `div minBound (-1)`
* `quot minBound (-1)`
* `abs minBound`
shall result in for the standard H2010 fixed-width signed types such as
`Int`, that is whether ⊥ (arithmetic overflow-exception) or
`minBound` is the more appropriate result.
Relevant sections from the Haskell 2010 report:
(http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1350006.4)
| 6.4. Numbers
|
| [...] The results of exceptional conditions (such as overflow or
| underflow) on the fixed-precision numeric types are undefined; an
| implementation may choose error (⊥, semantically), a truncated value,
| or a special value such as infinity, indefinite, etc.
...which seems contradictory to...
(http://www.haskell.org/onlinereport/haskell2010/haskellch18.html#x26-22400018.1)
| * 18.1. Signed integer types
|
| This module provides signed integer types of unspecified width (Int)
| and fixed widths (Int8, Int16, Int32 and Int64). All arithmetic is
| performed modulo 2^n, where n is the number of bits in the type.
| [...]
Would a Haskell 2010 implementation which turns *every* integer
over/underflow (even those for addition or multiplication of 'Int'
values whose result would lie outside of [minBound..maxBound]) into a
arithmetic exception be a valid H2010 implementation?
-- hvr
More information about the Haskell-prime
mailing list