Language-Independent Arithmetic

Kent Karlsson kentk@md.chalmers.se
Mon, 23 Jun 2003 11:49:07 +0200


Alastair Reid wrote:
> On Sunday 22 June 2003 6:30 am, Ashley Yakeley wrote:
> > From the Haskell 98 Report, sec. 6.4:
> >
> >     "The default floating point operations defined by
> >     the Haskell  Prelude do not  conform to current
> >     language independent arithmetic (LIA) standards.
> >     These standards require considerably more complexity
> >     in the numeric structure and have thus been
> >     relegated to a library."
> >
> > Is this true? Which library?
> 
> If I recall correctly, the LIA standard requires control over 
> rounding modes, 

No, it does not.  But IEC 60559 (a.k.a. IEEE 754, or "IEEE f.p.
arithmetic") does.

(Side remark: the quote above refers only to LIA-1.  LIA-2 (elementary
functions) is now done, and LIA-3 (complex integers and complex
floating point) is in the works.  All three LIA parts are relevant to
Haskell,
since Haskell includes elementary functions and complex floating point
values and operations.)

> requires that you provide several variants of each 
> comparision operation 
> which respond differently to +0,-0,infinity,NaN, etc. 

No it does not.  Nor does IEC 60559, while it informatively suggests
the possibility w.r.t NaNs (not w.r.t. signed zeroes or infinities); I
don't
think that suggestion has been picked up by anyone though.  The C
committee considered it, but apparently rejected it.

> I 
> think some of the 
> obvious type signatures would have to change too.

How?  I haven't been looking into this for quite a while, but I don't
recall any such problem.  There are a few missing constants, and a
few missing operations, though.



A major problem, however, is error handling.  While LIA allows for
"write error message and terminate", that's rarely the best way of
handling arithmetic errors.  The "recording of indicators" approach,
much like IEC 60559 default error handling, is problematic in
Haskell due to the hidden state.

> What would be needed to conform to LIA would be to add a 
> library providing all 
> the operations.   The default ops (i.e., the Prelude) would 
> still not conform 
> to LIA but that may not be such a big deal.

It is the intent for LIA-1 that most programming languages (and their
implementations) should be able to conform to LIA-1 without too much
trouble.  Even if it means "terminate on error" in a conforming mode of
operation.

		/Kent Karlsson

(Current editor of the LIA series of standards.)


> 
> --
> Alastair Reid