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 16:56 ` [Bug c/31394] " sdirkse at gams dot com
` (3 more replies)
0 siblings, 4 replies; 6+ 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] 6+ messages in thread
* [Bug c/31394] cos() returns wrong value unless -O0 is used
2007-03-29 16:54 [Bug c/31394] New: cos() returns wrong value unless -O0 is used sdirkse at gams dot com
@ 2007-03-29 16:56 ` sdirkse at gams dot com
2007-03-29 17:50 ` [Bug target/31394] " dominiq at lps dot ens dot fr
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: sdirkse at gams dot com @ 2007-03-29 16:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from sdirkse at gams dot com 2007-03-29 17:55 -------
Created an attachment (id=13297)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13297&action=view)
test case for the bug
Building with
gcc -m64 -O1 -o xxx cosbug.i -lm
shows the bug bug
gcc -m64 -o xxx cosbug.i -lm
is OK. I observe the bug also with -O2 and -O3
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31394
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/31394] cos() returns wrong value unless -O0 is used
2007-03-29 16:54 [Bug c/31394] New: cos() returns wrong value unless -O0 is used sdirkse at gams dot com
2007-03-29 16:56 ` [Bug c/31394] " sdirkse at gams dot com
@ 2007-03-29 17:50 ` 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
3 siblings, 0 replies; 6+ messages in thread
From: dominiq at lps dot ens dot fr @ 2007-03-29 17:50 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from dominiq at lps dot ens dot fr 2007-03-29 18:50 -------
This bug reminds me PR30980 and PR31161, though they were reported only for g++
and gfortran (they were fixed on 2007-03-16). Could you look at them to see if
the bug you have reported is not a duplicate? If yes, you should update your
build.
Could you be also kind enough to look at the related optimization problem
PR31249 and see it affects also your platform?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31394
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/31394] cos() returns wrong value unless -O0 is used
2007-03-29 16:54 [Bug c/31394] New: cos() returns wrong value unless -O0 is used sdirkse at gams dot com
2007-03-29 16:56 ` [Bug c/31394] " 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
3 siblings, 0 replies; 6+ messages in thread
From: sdirkse at gams dot com @ 2007-03-30 20:36 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from sdirkse at gams dot com 2007-03-30 21:36 -------
I installed gcc 20070329 and the problem I was having is solved. I suppose
that makes it a duplicate of PR30980.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31394
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/31394] cos() returns wrong value unless -O0 is used
2007-03-29 16:54 [Bug c/31394] New: cos() returns wrong value unless -O0 is used sdirkse at gams dot com
` (2 preceding siblings ...)
2007-03-30 20:36 ` sdirkse at gams dot com
@ 2007-03-30 20:56 ` dominiq at lps dot ens dot fr
3 siblings, 0 replies; 6+ messages in thread
From: dominiq at lps dot ens dot fr @ 2007-03-30 20:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from dominiq at lps dot ens dot fr 2007-03-30 21:56 -------
> I suppose that makes it a duplicate of PR30980.
It would have been better to check it directly before updating. PR30980 was
related to g++ and gfortran and not gcc, so it seems that your platform
(i386-pc-solaris2.10?) differs from Darwin at least.
Now, could you please time the C test of PR31249, with and without -O and
report what you get:
#include <math.h>
#include <stdio.h>
int main()
{
long n = 1000000;
long i;
double mo = -1.0;
double pi = acos(mo);
double sc = 0.0;
double ss = 0.0;
double t = 0.0;
double dt = pi/n;
printf("%.17g \n", pi);
printf("%.17g \n", dt);
for (i=0; i< 40*n; i++) {
sc += cos(t);
ss += sin(t);
t += dt;
}
printf("%.17g %.17g \n", sc, ss);
}
It will take less than a couple of minutes and see if -O is a real optimization
or not on your platform.
TIA
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31394
^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <bug-31394-4@http.gcc.gnu.org/bugzilla/>]
end of thread, other threads:[~2012-01-19 5:01 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-29 16:54 [Bug c/31394] New: cos() returns wrong value unless -O0 is used sdirkse at gams dot com
2007-03-29 16:56 ` [Bug c/31394] " 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
[not found] <bug-31394-4@http.gcc.gnu.org/bugzilla/>
2012-01-19 5:16 ` pinskia at gcc dot gnu.org
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).