public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "wxzkenny at aliyun dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug libc/31227] New: The value of cos varies with different optimization levels
Date: Wed, 10 Jan 2024 01:20:49 +0000	[thread overview]
Message-ID: <bug-31227-131@http.sourceware.org/bugzilla/> (raw)

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.

             reply	other threads:[~2024-01-10  1:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-10  1:20 wxzkenny at aliyun dot com [this message]
2024-01-10  9:38 ` [Bug libc/31227] " schwab@linux-m68k.org
2024-01-11  3:20 ` wxzkenny at aliyun dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-31227-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).