This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/59089] New: sin and/or cos produce bogus results with -O2
- From: "terra at gnome dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 12 Nov 2013 14:49:19 +0000
- Subject: [Bug c/59089] New: sin and/or cos produce bogus results with -O2
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59089
Bug ID: 59089
Summary: sin and/or cos produce bogus results with -O2
Product: gcc
Version: 4.7.1
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: terra at gnome dot org
Created attachment 31199
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31199&action=edit
sc.c
welinder@sherwood:~> gcc --version
gcc (SUSE Linux) 4.7.1 20120723 [gcc-4_7-branch revision 189773]
When sin(x) and cos(x) are used near each other and -O2 is active,
results are utterly unreliable:
welinder@sherwood:~> gcc -Wall -O0 sc.c -lm
welinder@sherwood:~> ./a.out 1e19
cot(1e+19) = 0.40440089012342833596
welinder@sherwood:~> gcc -Wall -O2 sc.c -lm
welinder@sherwood:~> ./a.out 1e19
cot(1e+19) = 0.60484784464511465174
Reference value from
http://www.wolframalpha.com/input/?i=Cot[10^19]&a=TrigRD_R
--> 0.404400890123428300526065555419647330231956673028985010736178...
Further info: -O2 uses sincos, not sin and cos:
welinder@sherwood:~> gcc -Wall -O2 sc.c
/tmp/ccouebOR.o: In function `gnm_cot':
sc.c:(.text+0xd): undefined reference to `sincos'
collect2: error: ld returned 1 exit status
welinder@sherwood:~> gcc -Wall -O0 sc.c
/tmp/ccR0uAFj.o: In function `gnm_cot':
sc.c:(.text+0x1b): undefined reference to `sin'
sc.c:(.text+0x3a): undefined reference to `cos'
collect2: error: ld returned 1 exit status