public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/31394]  New: cos() returns wrong value unless -O0 is used
@ 2007-03-29 16:54 sdirkse at gams dot com
  2007-03-29 17:50 ` [Bug target/31394] " dominiq at lps dot ens dot fr
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: sdirkse at gams dot com @ 2007-03-29 16:54 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-01-19  5:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-31394-4@http.gcc.gnu.org/bugzilla/>
2012-01-19  5:16 ` [Bug target/31394] cos() returns wrong value unless -O0 is used pinskia at gcc dot gnu.org
2007-03-29 16:54 [Bug c/31394] New: " sdirkse at gams dot com
2007-03-29 17:50 ` [Bug target/31394] " dominiq at lps dot ens dot fr
2007-03-30 20:36 ` sdirkse at gams dot com
2007-03-30 20:56 ` dominiq at lps dot ens dot fr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).