[Bug libc/31227] New: The value of cos varies with different optimization levels

wxzkenny at aliyun dot com sourceware-bugzilla@sourceware.org
Wed Jan 10 01:20:49 GMT 2024


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.


More information about the Glibc-bugs mailing list