public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/59089] New: sin and/or cos produce bogus results with -O2
@ 2013-11-12 14:49 terra at gnome dot org
  2013-11-12 14:51 ` [Bug c/59089] " terra at gnome dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: terra at gnome dot org @ 2013-11-12 14:49 UTC (permalink / raw)
  To: gcc-bugs

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


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

end of thread, other threads:[~2013-11-14  8:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-12 14:49 [Bug c/59089] New: sin and/or cos produce bogus results with -O2 terra at gnome dot org
2013-11-12 14:51 ` [Bug c/59089] " terra at gnome dot org
2013-11-12 15:34 ` octoploid at yandex dot com
2013-11-14  8:50 ` rguenth 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).