From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1452 invoked by alias); 29 Mar 2007 16:54:00 -0000 Received: (qmail 1197 invoked by uid 48); 29 Mar 2007 16:53:42 -0000 Date: Thu, 29 Mar 2007 16:54:00 -0000 Subject: [Bug c/31394] New: cos() returns wrong value unless -O0 is used X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "sdirkse at gams dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-03/txt/msg02725.txt.bz2 I have some code that involves computing a cosine via cos(), specifically b = cos(v). Depending on the context of the cos call, I get correct and incorrect answers. In the example code's main program, I get a correct result regardless of the compilation flags. In the MATHNEW_funceval routine, correctness depends on the flags. Just a note on "correctness" since these are floating-point operations: IMHO the incorrect result is far enough away from the true result to remove all doubt, but I can say more if necessary. In the output below, "b =" is correct, but "b2=" is incorrect. Here's the output I get: sunamd1:/export/home/gams/lang/cosbug$gmake && ./cosbug gcc -m64 -Wall -w -m64 -fwrapv -O1 -save-temps -v -o cosbug cosbug.c -lm Using built-in specs. Target: i386-pc-solaris2.10 Configured with: ../configure --build=i386-pc-solaris2.10 --with-gnu-as --with-as=/usr/sfw/bin/gas --without-gnu-ld -with-ld=/usr/ccs/bin/ld --with-gmp=/usr/local --with-mpfr=/usr/local --enable-languages=c,c++,fortran --enable-shared Thread model: posix gcc version 4.3.0 20070301 (experimental) /usr/local/libexec/gcc/i386-pc-solaris2.10/4.3.0/cc1 -E -quiet -v -imultilib amd64 cosbug.c -m64 -mtune=generic -Wall -w -fwrapv -O1 -fpch-preprocess -o cosbug.i ignoring nonexistent directory "/usr/local/lib/gcc/i386-pc-solaris2.10/4.3.0/../../../../i386-pc-solaris2.10/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/local/lib/gcc/i386-pc-solaris2.10/4.3.0/include /usr/local/lib/gcc/i386-pc-solaris2.10/4.3.0/include-fixed /usr/include End of search list. /usr/local/libexec/gcc/i386-pc-solaris2.10/4.3.0/cc1 -fpreprocessed cosbug.i -quiet -dumpbase cosbug.c -m64 -mtune=generic -auxbase cosbug -O1 -Wall -w -version -fwrapv -o cosbug.s GNU C version 4.3.0 20070301 (experimental) (i386-pc-solaris2.10) compiled by GNU C version 4.3.0 20070301 (experimental). GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 Compiler executable checksum: 15fd974b8d70fc2c218783c6076c49f0 /usr/sfw/bin/gas --traditional-format -V -Qy --64 -s -o cosbug.o cosbug.s GNU assembler version 2.15 (i386-pc-solaris2.10) using BFD version 2.15 /usr/local/libexec/gcc/i386-pc-solaris2.10/4.3.0/collect2 -V -Y P,/lib/64:/usr/lib/64 -Qy -o cosbug /usr/lib/amd64/crt1.o /usr/lib/amd64/crti.o /usr/lib/amd64/values-Xa.o /usr/local/lib/gcc/i386-pc-solaris2.10/4.3.0/amd64/crtbegin.o -L/usr/local/lib/gcc/i386-pc-solaris2.10/4.3.0/amd64 -L/usr/local/lib/gcc/i386-pc-solaris2.10/4.3.0/../../../amd64 -L/lib/amd64 -L/usr/lib/amd64 -L/usr/local/lib/gcc/i386-pc-solaris2.10/4.3.0 -L/usr/local/lib/gcc/i386-pc-solaris2.10/4.3.0/../../.. cosbug.o -lm -lgcc -lgcc_eh -lc -lgcc -lgcc_eh /usr/local/lib/gcc/i386-pc-solaris2.10/4.3.0/amd64/crtend.o /usr/lib/amd64/crtn.o ld: Software Generation Utilities - Solaris Link Editors: 5.10-1.482 0 = 0 x0= -635.4813998334932 y = -7.036102677544457e-09 z = 635.4813998264574 *** |t| < mu: return smoother v = -3.141592653589793 b = -1.224646799147353e-16 *** |t| < mu: return smoother v2= -3.141592653589793 b2= -0.04318444754676655 sunamd1:/export/home/gams/lang/cosbug$ Now using the .i file I get: sunamd1:/export/home/gams/lang/cosbug$gcc -m64 -o xxx cosbug.i -lm sunamd1:/export/home/gams/lang/cosbug$./xxx 0 = 0 x0= -635.4813998334932 y = -7.036102677544457e-09 z = 635.4813998264574 *** |t| < mu: return smoother v = -3.141592653589793 b = -1.224646799147353e-16 *** |t| < mu: return smoother v2= -3.141592653589793 b2= -1.224646799147353e-16 sunamd1:/export/home/gams/lang/cosbug$gcc -m64 -O1 -o xxx cosbug.i -lm sunamd1:/export/home/gams/lang/cosbug$./xxx 0 = 0 x0= -635.4813998334932 y = -7.036102677544457e-09 z = 635.4813998264574 *** |t| < mu: return smoother v = -3.141592653589793 b = -1.224646799147353e-16 *** |t| < mu: return smoother v2= -3.141592653589793 b2= -0.04318444754676655 -- Summary: cos() returns wrong value unless -O0 is used Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sdirkse at gams dot com GCC build triplet: i386-pc-solaris2.10 GCC host triplet: i386-pc-solaris2.10 GCC target triplet: i386-pc-solaris2.10 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31394