unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* RFC: Arbitrary-precision floats for Guile
@ 2011-02-01 13:57 Mark H Weaver
  2011-02-01 14:28 ` Hans Aberg
  2011-02-01 20:37 ` Andy Wingo
  0 siblings, 2 replies; 9+ messages in thread
From: Mark H Weaver @ 2011-02-01 13:57 UTC (permalink / raw)
  To: guile-devel

Hello all,

I want to add arbitrary-precision floats to Guile.
I'd use the mpf_t type from GNU MP.

There would be a fluid whose value would determine the minimum precision
to use for inexact operators.  A value of #f (the default) would mean
that normal floats would be used unless one of the operands was a
bigfloat.  Procedures that produce inexact numbers (including read and
exact->inexact) would use the precision of the most precise inexact
operand contributing to the result, or the value of the fluid, whichever
is greater.  There would also be a procedure to reduce the precision of
an inexact number to some specified value.  The syntax for inexact
numbers would allow an optional suffix to specify the precision.

One complication is that we'd have to implement the transcendental
functions.  However, I already have code to do that, as part of a
bigfloat library I wrote a while back.

I'd also like to add another more general representation of complex
numbers whose real and imaginary parts are each of type SCM, like the
way fractions are represented.  The primary motivation would be to
support arbitrary-precision complex numbers, but as an added bonus,
would be able to support exact Gaussian integers.  The existing complex
representation would still be supported in the interests of efficiency.

scm_make_rectangular would automatically choose the right
representation: if the imaginary part was an exact zero, it would simply
return the specified real part.  If both parts were normal floats it
would return the existing fast complex numbers, otherwise it would
return the new more general complex number type.

Now I know we have a release coming soon.  I don't necessarily expect to
get these changes merged before then, although I'm willing and able to
implement all of this in the next week.  However, I was hoping that I
could at least get enough of it into 2.0 so that it could be part of 2.1
without breaking ABI compatibility.  Do you think this is feasible?
If not, would it be possible to delay the release a week or two?

What do you think of this?  Am I crazy? :)

    Best,
     Mark



^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: RFC: Arbitrary-precision floats for Guile
@ 2011-02-02  1:53 Nelson H. F. Beebe
  2011-02-02 15:42 ` Pierpaolo Bernardi
  0 siblings, 1 reply; 9+ messages in thread
From: Nelson H. F. Beebe @ 2011-02-02  1:53 UTC (permalink / raw)
  To: guile-devel; +Cc: beebe

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/ -
-------------------------------------------------------------------------------



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-02-02 15:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-01 13:57 RFC: Arbitrary-precision floats for Guile Mark H Weaver
2011-02-01 14:28 ` Hans Aberg
2011-02-01 16:42   ` dsmich
2011-02-01 17:03   ` Mark H Weaver
2011-02-01 19:20     ` Hans Aberg
2011-02-01 20:37 ` Andy Wingo
2011-02-02 14:30   ` Hans Aberg
  -- strict thread matches above, loose matches on Subject: below --
2011-02-02  1:53 Nelson H. F. Beebe
2011-02-02 15:42 ` Pierpaolo Bernardi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).