public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/31227] New: The value of cos varies with different optimization levels
@ 2024-01-10  1:20 wxzkenny at aliyun dot com
  2024-01-10  9:38 ` [Bug libc/31227] " schwab@linux-m68k.org
  2024-01-11  3:20 ` wxzkenny at aliyun dot com
  0 siblings, 2 replies; 3+ messages in thread
From: wxzkenny at aliyun dot com @ 2024-01-10  1:20 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=31227

            Bug ID: 31227
           Summary: The value of cos varies with different optimization
                    levels
           Product: glibc
           Version: 2.28
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: wxzkenny at aliyun dot com
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

I wrote a test case test_cos.c, the context of file test_cos.c as following:

#include <stdio.h>
#include <math.h>

static double dcos(double arg1)
{
    return cos(arg1);
}

int main()
{
    double d = 17.14159265;
    volatile double c = dcos(d);

    printf("cos(d) = %.17f %llx\n", c, *(long long*)&c);

    return 0;
}

When we compiled with different optimization levels, we got different results: 
[root@localhost tmp]# gcc -o test_cos -lm -O test_cos.c && ./test_cos
cos(d) = -0.13673722176390943 bfc1809af3cf9a1b
[root@localhost tmp]# gcc -o test_cos -lm -O0 test_cos.c && ./test_cos
cos(d) = -0.13673722176390940 bfc1809af3cf9a1a
[root@localhost tmp]# gcc -o test_cos -lm -O1 test_cos.c && ./test_cos
cos(d) = -0.13673722176390943 bfc1809af3cf9a1b
[root@localhost tmp]# gcc -o test_cos -lm -O2 test_cos.c && ./test_cos
cos(d) = -0.13673722176390943 bfc1809af3cf9a1b
[root@localhost tmp]# gcc -o test_cos -lm -O3 test_cos.c && ./test_cos
cos(d) = -0.13673722176390943 bfc1809af3cf9a1b

When I embed cos in my large program and compile it with -O2 I get the same
result as here with -O0

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2024-01-11  3:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-10  1:20 [Bug libc/31227] New: The value of cos varies with different optimization levels wxzkenny at aliyun dot com
2024-01-10  9:38 ` [Bug libc/31227] " schwab@linux-m68k.org
2024-01-11  3:20 ` wxzkenny at aliyun dot com

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).