The attached test case produces the erroneous value of -20763584.029346 for cos(2 * Pi / 4) 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.
Compile with gcc -O0 -o cos_bug cos_bug.c -lm Compilers used (both show the bug) are gcc (GCC) 4.3.2 and gcc (GCC) 4.3.0 20080428 (Red Hat 4.3.0-8) Processor is Intel(R) Core(TM)2 CPU 6400 @ 2.13GHz. Math library is from Redhat Fedora 9, glibc-2.8-8.x86_64 package. -- Summary: cos() returns incorrect value in FE_UPWARD rounding mode Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: kruppaal at loria dot fr GCC host triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38352