Bug 14759

Summary: Most functions in math.h not correctly rounded
Product: glibc Reporter: Joshua Hopp <JoshuaHopp>
Component: mathAssignee: Not yet assigned to anyone <unassigned>
Severity: normal CC: bagnara, bob.wilson, hjl.tools, zimmerma+gcc
Priority: P2 Flags: fweimer: security-
Version: 2.15   
Target Milestone: ---   
Host: x86_64 Target: x86_64
Build: linux-gnu Last reconfirmed:

Description Joshua Hopp 2012-10-24 08:07:40 UTC
Most functions in math.h do not use correct rounding. Example:

//--- snip ---
#include <math.h>
#include <fenv.h>
#include <assert.h>

int main() {
        double x = 1.0; // 1.0 is exact

        double a = asin(x);
        double b = asin(x);

        // asin(1) == pi/2, which is not exactly representable
        // so, assuming correct rounding, a should be less than b
        assert(a < b);
//--- snap ---

Compile with "gcc -lm" (or even "gcc -lm -ffloat-store -frounding-math").

Run the example:
 main: Assertion `a < b' failed.

Similar results can be obtained with exp, cos, acos, atan, sinh, cosh, atanh, asinh and acosh.

Kernel version: 3.5.2-1.fc17
gcc version 4.7.2 20120921 (Red Hat 4.7.2-2) (GCC) 
GNU ld version 20120131
Comment 1 Joseph Myers 2012-10-24 12:39:29 UTC
I'll use this as the general meta-bug for not-correctly-rounding functions (other than those with fully specified results such as sqrt and fma), as I suggested in <http://sourceware.org/ml/libc-alpha/2012-02/msg00392.html>, and mark other bugs for small ulps errors (say 1-10ulps) as duplicates of this one.

SUSPENDED as correctly-rounding issues are generally known to be hard to fix and to need new implementations of functions in many cases, with detailed error analysis and exhaustive searches for worst cases for rounding.
Comment 2 Joseph Myers 2012-10-24 12:42:06 UTC
*** Bug 1161 has been marked as a duplicate of this bug. ***
Comment 3 Joseph Myers 2012-10-24 12:43:43 UTC
*** Bug 1163 has been marked as a duplicate of this bug. ***
Comment 4 Joseph Myers 2012-10-24 12:44:26 UTC
*** Bug 2540 has been marked as a duplicate of this bug. ***
Comment 5 Joseph Myers 2013-11-28 22:38:55 UTC
glibc accuracy goals are now documented in the manual and the FAQ and correct rounding is explicitly excluded - without ruling out the possibility that in future we could add correctly rounding functions under names such as crasin, or other functions with well-defined error bounds, probably automatically generated with tools such as metalibm.
Comment 6 Joseph Myers 2014-01-29 16:35:24 UTC
*** Bug 16509 has been marked as a duplicate of this bug. ***