[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RFC: Arbitrary-precision floats for Guile
From: |
Nelson H. F. Beebe |
Subject: |
Re: RFC: Arbitrary-precision floats for Guile |
Date: |
Tue, 1 Feb 2011 18:53:54 -0700 (MST) |
Before rushing off and implementing arbitrary-precision floats in
Guile, please study this recent book carefully first, particularly
Chapter 3 that discusses IEEE Standards requirements for
floating-point arithmetic:
@String{pub-BIRKHAUSER-BOSTON = "Birkh{\"a}user Boston Inc."}
@String{pub-BIRKHAUSER-BOSTON:adr = "Cambridge, MA, USA"}
@Book{Muller:2010:HFP,
author = "Jean-Michel Muller and Nicolas Brisebarre and Florent
de Dinechin and Claude-Pierre Jeannerod and Vincent
Lef{\`e}vre and Guillaume Melquiond and Nathalie Revol
and Damien Stehl{\'e} and Serge Torres",
title = "Handbook of Floating-Point Arithmetic",
publisher = pub-BIRKHAUSER-BOSTON,
address = pub-BIRKHAUSER-BOSTON:adr,
pages = "xxiii + 572",
year = "2010",
DOI = "http://dx.doi.org/10.1007/978-0-8176-4704-9";,
ISBN = "0-8176-4704-X",
ISBN-13 = "978-0-8176-4704-9",
LCCN = "QA76.9.C62 H36 2010",
bibdate = "Thu Jan 27 16:18:58 2011",
price = "US\$90 (est.)",
acknowledgement = ack-nhfb,
}
The authors of that book are a group of leading French researchers who
have done a lot of important work in the area of hardware and software
for floating-point arithmetic, and some are co-authors of the MPFR
package that builds on top of the facilities provided by GMP. MPFR
and its companion, MPC (from
http://mpc.multiprecision.org/
) for complex arithmetic, represents the state of the art in the area
of correctly-rounded arithmetic.
Another recent book addresses arithmetic and the computation of
elementary functions in software arbitrary-precision arithmetic:
@String{pub-CAMBRIDGE = "Cambridge University Press"}
@String{pub-CAMBRIDGE:adr = "Cambridge, UK"}
@Book{Brent:2011:MCA,
author = "Richard P. Brent and Paul Zimmermann",
title = "Modern computer arithmetic",
volume = "18",
publisher = pub-CAMBRIDGE,
address = pub-CAMBRIDGE:adr,
pages = "xvi + 221",
year = "2011",
ISBN = "0-521-19469-5 (hardcover)",
ISBN-13 = "978-0-521-19469-3 (hardcover)",
LCCN = "QA76.9.C62 BRE 2011",
bibdate = "Sat Jan 15 12:25:22 MST 2011",
bibsource = "library.ox.ac.uk:210/ADVANCE",
series = "Cambridge monographs on applied and computational
mathematics",
acknowledgement = ack-nhfb,
subject = "Computer arithmetic",
}
Recent releases of the gcc-4.x compiler family require GMP, MPFR, and
MPC so that correctly-rounded compile-time conversions can be
guaranteed; thus, recent GNU/Linux systems are likely to have all
three libraries already installed. All are extremely portable to
systems with IEEE 754 arithmetic; don't expect them to run on older
architectures (VAX, PDP-10, etc.).
The programming-language compiler field is littered with far too many
code optimizations that are completely wrong for floating-point
arithmetic; please do not add to that mess! For example,
floating-point arithmetic is not associative, so (+ (a (+ b c)) is not
the same as (+ (b (+ a c)), and (* (a (* b c))) may differ (possibly
wildly) from (* (b (* a c))) etc.
Reciprocation is rarely exact, so (/ x y) is NOT the same as
(* x (/ 1 y)), unless y is known in advance to be a power of the base.
Importantly, (equal x x) MUST return #f if x is a NaN (quiet or
signaling), and cannot be optimized away to #t.
Comparisons of floating-point values may return UNORDERED, so (< a b)
is NOT the same as (not (>= b a)).
It is imperative that the floating-point programmer have control over
whether higher precision is used in intermediate evaluations. The
C/C++/Java/C# family, and Fortran 20xx, provide a volatile type
qualifier that forces intermediate results into memory in their normal
storage size. This can be an issue in the Lisp family, where type
declarations may be omitted, or variable types may change at run time.
If interval arithmetic is to eventually be supported in guile, then
the floating-point system MUST provide access to rounding-mode
control, or else provide additional arithmetic operators that produce
upper and lower bounds for basic arithmetic operations (+, -, /, *, sqrt).
Interval arithmetic is already available in C++ and Fortran 90 in the
freely-available Sun (now Oracle) compilers, and they should be used
as a test bed for any development of interval arithmetic in guile.
Careful study of the C99 Standard and subsequent documents is also
desirable:
@String{pub-ISO = "International Organization for
Standardization"}
@String{pub-ISO:adr = "Geneva, Switzerland"}
@Book{ISO:1999:IIP,
author = "{ISO}",
title = "{ISO\slash IEC 9899:1999}: Programming Languages ---
{C}",
publisher = pub-ISO,
address = pub-ISO:adr,
pages = "538",
day = "16",
month = dec,
year = "1999",
ISBN = "????",
ISBN-13 = "????",
LCCN = "????",
bibdate = "Tue Dec 12 06:46:19 2000",
note = "Available in electronic form for online purchase at
\path=http://webstore.ansi.org/= and
\path=http://www.cssinfo.com/=.";,
price = "US\$18 (electronic), US\$225 (print)",
URL = "http://www.iso.ch/cate/d29237.html;
http://anubis.dkuug.dk/JTC1/SC22/open/n2620/n2620.pdf;
http://anubis.dkuug.dk/JTC1/SC22/WG14/www/docs/n897.pdf;
http://webstore.ansi.org/ansidocstore/product.asp?sku=ISO%2FIEC+9899%3A1999";,
acknowledgement = ack-nhfb,
}
There are at least three critical subsequent Technical Corrigenda to
that document.
There are also recommendations for support of decimal arithmetic, and
additional library functions, although in my opinion, more work is
required in both cases (my forthcoming book discusses these issues in
detail):
@Misc{ISO:2006:IIJa,
key = "C",
title = "{ISO\slash IEC JTC1 SC22 WG14 N1154}: Extension for
the programming language {C} to support decimal
floating-point arithmetic",
howpublished = "World-Wide Web document",
day = "27",
month = feb,
year = "2006",
bibdate = "Tue Mar 07 18:23:45 2006",
URL = "http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1154.pdf";,
acknowledgement = ack-nhfb,
keywords = "decimal floating-point arithmetic",
}
@Misc{ISO:2006:IIJb,
key = "C",
title = "{ISO\slash IEC JTC1 SC22 WG14 N1161}: Rationale for
{TR 24732}: Extension to the programming language {C}:
Decimal Floating-Point Arithmetic",
howpublished = "World-Wide Web document",
day = "27",
month = feb,
year = "2006",
bibdate = "Tue Mar 07 18:23:45 2006",
URL = "http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1161.pdf";,
acknowledgement = ack-nhfb,
keywords = "decimal floating-point arithmetic",
}
@Misc{ISO:2006:IIJc,
key = "C",
title = "{ISO\slash IEC JTC1 SC22 WG14 N1176}: Extension for
the programming language {C} to support decimal
floating-point arithmetic",
howpublished = "World-Wide Web document",
pages = "iii + 33",
day = "24",
month = may,
year = "2006",
bibdate = "Sat Feb 24 20:00:36 2007",
URL = "http://open-std.org/jtc1/sc22/wg14/www/docs/n1176.pdf";,
acknowledgement = ack-nhfb,
keywords = "decimal floating-point arithmetic",
}
@Book{ISO:2009:IIT,
key = "C",
title = "{ISO/IEC TR 24732:2009} Information technology ---
Programming languages, their environments and system
software interfaces --- Extension for the programming
language {C} to support decimal floating-point
arithmetic",
publisher = pub-ISO,
address = pub-ISO:adr,
year = "2009",
bibdate = "Thu Nov 25 08:56:44 2010",
bibsource = "http://www.iso.org/iso/search.htm";,
series = "Technical report",
URL =
"http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=38842";,
acknowledgement = ack-nhfb,
subject = "programming languages (electronic computers)",
}
@Book{ISO:2010:IIIa,
key = "C++",
title = "{ISO/IEC 29124:2010}: Information technology ---
Programming languages, their environments and system
software interfaces --- Extensions to the {C++ Library}
to support mathematical special functions",
publisher = pub-ISO,
address = pub-ISO:adr,
year = "2010",
bibdate = "Thu Nov 25 08:56:44 2010",
bibsource = "http://www.iso.org/iso/search.htm";,
series = "Technical report",
URL =
"http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=50511";,
acknowledgement = ack-nhfb,
subject = "programming languages (electronic computers)",
}
Recently a draft of the developing ISO C 201x standard that will
eventually replace C99 became available:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1539.pdf
-------------------------------------------------------------------------------
- Nelson H. F. Beebe Tel: +1 801 581 5254 -
- University of Utah FAX: +1 801 581 4148 -
- Department of Mathematics, 110 LCB Internet e-mail: address@hidden -
- 155 S 1400 E RM 233 address@hidden address@hidden -
- Salt Lake City, UT 84112-0090, USA URL: http://www.math.utah.edu/~beebe/ -
-------------------------------------------------------------------------------