[PATCH]: PR29335 use MPFR for builtins fma, fmin and fmax

Kaveh R. GHAZI ghazi@caip.rutgers.edu
Wed Nov 8 04:04:00 GMT 2006


On Tue, 7 Nov 2006, Andrew Pinski wrote:

> Do you know how much precision fma gets for mpfr?
> Andrew Pinski

My understanding is that mpfr is supposed to always yield exact (AKA
correctly) rounded results for the requested precision.  For the case of
fma, here's the code that implements it:

  /* if we take prec(u) >= prec(x) + prec(y), the product
     u <- x*y is always exact */
  mpfr_init2 (u, MPFR_PREC(x) + MPFR_PREC(y));
  mpfr_mul (u, x, y, GMP_RNDN); /* always exact */
  inexact = mpfr_add (s, z, u, rnd_mode);
  mpfr_clear(u);


In this case x, y and z are the supplied args and they all have a
precision of the underlying types (float, double or long double.)

We see that u is given a precision equal to prec(x) + prec(y), which is
supposed to allow the multiplication x*y to be exact.  The addition of z
occurs in the precision of the resulting type (again float, double, long
double) and that is rounded once.  I believe that's as good as you can
get.

		--Kaveh
--
Kaveh R. Ghazi			ghazi@caip.rutgers.edu



More information about the Gcc-patches mailing list