From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Nelson H. F. Beebe" Newsgroups: gmane.lisp.guile.devel Subject: Re: RFC: Arbitrary-precision floats for Guile Date: Tue, 1 Feb 2011 18:53:54 -0700 (MST) Message-ID: NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1296613292 30506 80.91.229.12 (2 Feb 2011 02:21:32 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 2 Feb 2011 02:21:32 +0000 (UTC) Cc: beebe@math.utah.edu To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Feb 02 03:21:27 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PkSL8-0000Yv-82 for guile-devel@m.gmane.org; Wed, 02 Feb 2011 03:21:25 +0100 Original-Received: from localhost ([127.0.0.1]:54036 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PkSL6-0007dx-Bs for guile-devel@m.gmane.org; Tue, 01 Feb 2011 21:21:00 -0500 Original-Received: from [140.186.70.92] (port=49292 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PkSKy-0007ce-NE for guile-devel@gnu.org; Tue, 01 Feb 2011 21:20:55 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PkSKu-0000Ba-Kc for guile-devel@gnu.org; Tue, 01 Feb 2011 21:20:50 -0500 Original-Received: from mail.math.utah.edu ([155.101.98.135]:33851) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PkSKu-0000BF-5x for guile-devel@gnu.org; Tue, 01 Feb 2011 21:20:48 -0500 Original-Received: from psi.math.utah.edu (psi.math.utah.edu [155.101.96.19]) by mail.math.utah.edu (8.14.4/8.14.4) with ESMTP id p121rsQJ021117; Tue, 1 Feb 2011 18:53:54 -0700 (MST) Original-Received: from psi.math.utah.edu (localhost [127.0.0.1]) by psi.math.utah.edu (8.14.4/8.14.4) with ESMTP id p121rsCG020027; Tue, 1 Feb 2011 18:53:54 -0700 (MST) Original-Received: (from beebe@localhost) by psi.math.utah.edu (8.14.4/8.14.4/Submit) id p121rspX020026; Tue, 1 Feb 2011 18:53:54 -0700 (MST) X-US-Mail: "Department of Mathematics, 110 LCB, University of Utah, 155 S 1400 E RM 233, Salt Lake City, UT 84112-0090, USA" X-Telephone: +1 801 581 5254 X-FAX: +1 801 585 1640, +1 801 581 4148 X-URL: http://www.math.utah.edu/~beebe X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0 (mail.math.utah.edu [155.101.98.135]); Tue, 01 Feb 2011 18:53:54 -0700 (MST) X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-Received-From: 155.101.98.135 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:11501 Archived-At: 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: beebe@math.utah.edu - - 155 S 1400 E RM 233 beebe@acm.org beebe@computer.org - - Salt Lake City, UT 84112-0090, USA URL: http://www.math.utah.edu/~beebe/ - -------------------------------------------------------------------------------