Red Hat Bugzilla – Bug 473974
cos() returns incorrect value in FE_UPWARD rounding mode
Last modified: 2008-12-01 20:35:40 EST
Created attachment 325265 [details]
Test case for incorrect value of cos()
Description of problem:
The attached test case produces the erroneous value of -20763584.029346 for
cos(Pi / 2) when the rounding mode is set to FE_UPWARD, instead of the
correct value (close to) 0. Other rounding modes do not show this error,
compiling with optimization enabled (-O1, -O2 or -O3) or as a 32 bit binary
with -m32 also do not show the error. If the binary is linked statically with
-static, the bug disappears as well.
Version-Release number of selected component (if applicable):
gcc (GCC) 4.3.0 20080428 (Red Hat 4.3.0-8)
glibc-2.8-8.x86_64 (Build Date: Thu Jul 17 00:31:06 2008)
Steps to Reproduce:
1.Compile attached test case with
gcc -O0 -o cos_bug cos_bug.c -lm
2. run "./cos_bug"
x = 1.57079632679489655800 = 0x1.921fb54442d18p+0
cos(x) = -20763584.029346
cos(x) should be a value close to 0.
Processor is Intel(R) Core(TM)2 CPU 6400 @ 2.13GHz.
May be related to bug #88513
These routines aren't supposed to be called in non-standard rounding mode.
That's the caller's fault.
What Jakub said. The routines can only be called in the default mode. Programs changing the mode have to (temporarily) change it back before calling into the library.