Re: Floating point performance issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2011-12-23 21:02:44 +0100, Vincent Lefevre wrote:
> On 2011-12-20 22:52:12 +0100, David Brown wrote:
> >  It's theoretical only, or for people who want to insist on
> > bit-perfect repeatability of their floating point code. The example
> > case given in the gcc manual is "(x + 2**52) - 2**52)". Assuming the
> > implication is that x is a small number, there are almost no
> > real-world circumstances when such code exists.
> 
> Many codes will fail when rewriting such math expressions. See for
> instance the rint() implementation, and the codes whose goal is to
> improve the accuracy of floating-point computations (these codes are
> generally based on algorithms like TwoSum/FastTwoSum and Veltkamp's
> splitting). For instance, see the IBM Accurate Mathematical Library,
> which is part of the glibc.

I would add that even the C standard (C99 and C11) explicitly forbids
the rearrangements of such expressions. In 5.1.2.3 Program execution:

  14    EXAMPLE 5  Rearrangement for floating-point expressions is often
        restricted because of limitations in precision as well as range.
        The implementation cannot generally apply the mathematical
        associative rules for addition or multiplication, nor the
        distributive rule, because of roundoff error, even in the
        absence of overflow and underflow. Likewise, implementations
        cannot generally replace decimal constants in order to rearrange
        expressions. In the following fragment, rearrangements
        suggested by mathematical rules for real numbers are often not
        valid (see F.9).

          double x, y, z;
          /* ... */
          x = (x * y) * z;    //  not equivalent to x  *= y * z;
          z = (x - y) + y ;   //  not equivalent to z  = x;
          z = x + x * y;      //  not equivalent to z  = x * (1.0 + y);
          y = x / 5.0;        //  not equivalent to y  = x * 0.2;

Note: "***often*** not valid".

See also the following articles:

  http://csdl.computer.org/dl/mags/co/2005/05/r5091.pdf
  "An Open Question to Developers of Numerical Software", by
  W. Kahan and D. Zuras

  http://www.cs.berkeley.edu/~wkahan/Mindless.pdf
  "How Futile are Mindless Assessments of Roundoff in Floating-Point
  Computation?", by W. Kahan

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux