Fergus Henderson <[EMAIL PROTECTED]> asks:
What, if anything, does Haskell specify with regard to
(a) integer overflow,
(b) semantics of integer division and remainder
(div, mod, quot, rem)
(c) semantics of floating point arithmetic?
I had a look in the Haskell report, but didn't find anything.
a) Section 6.3 (Numbers) of the Haskell 1.3 report says:
The results of exceptional conditions (such as overflow and
underflow) on the fixed-precision numeric types is undefined; and
implementation may choose error (bottom, semantically), a truncated
value or a special value such as infinity, indefinite, etc.
In practice, most implementations do what C would do: Int arithmetic
is implicitly performed modulo 2^32; Float/Double arithmetic uses IEEE
values like +/- infinity, etc.
b) Section 6.3.2 (Arithmetic and Number-Theoretic operations) of the
Haskell 1.3 report precisely defines div, mod, quot and rem.
c) I don't think it says anything specific about floating point arith
but it does suggest that implementations should use (at least) IEEE
single-precision for Float and IEEE double precision for Double
(section 6.3 again). I guess it would be legal for all Float operations
to return bottom or 0 or otherwise act strangely - but people would
soon stop using that compiler.
In practice, I think implementations use whatever float and double
produce on their C compiler (usually IEEE - but not on older Suns,
for example). Hugs is an exception, it uses single precision for
both Float and Double - though it can be configured to use double
precision for both).
--
Alastair Reid Yale Haskell Project Hacker
[EMAIL PROTECTED] http://WWW.CS.Yale.EDU/homes/reid-alastair.html