public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111646] New: cos function giving different result for the same input value
@ 2023-09-30  8:37 vishwambhar.rathi at puresoftware dot com
  2023-09-30  8:45 ` [Bug middle-end/111646] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: vishwambhar.rathi at puresoftware dot com @ 2023-09-30  8:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111646

            Bug ID: 111646
           Summary: cos function giving different result for the same
                    input value
           Product: gcc
           Version: 9.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vishwambhar.rathi at puresoftware dot com
  Target Milestone: ---

Hi,

Below are my platform details:

ubuntu@ubuntu:~/code$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

ubuntu@ubuntu:~/code$ uname -m
aarch64
ubuntu@ubuntu:~/code$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.6 LTS
Release:        20.04
Codename:       focal

I am running ubuntu on windows using Qemu emulator. I tried the fowlloing
simple code:

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
    double x = -9311848.013224;
    printf("x %.6lf cosx_1 %.6f\n",x, cos(x));
    printf("x %.6lf cosx_2 %.6f\n",x, cos(x));
}

I got different values as output. The output is:

x -9311848.013224 cosx_1 -0.634393
x -9311848.013224 cosx_2 -0.999992

Any thoughts, what is going on?

Thanks,
Vish.

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

* [Bug middle-end/111646] cos function giving different result for the same input value
  2023-09-30  8:37 [Bug c/111646] New: cos function giving different result for the same input value vishwambhar.rathi at puresoftware dot com
@ 2023-09-30  8:45 ` pinskia at gcc dot gnu.org
  2023-09-30  9:31 ` vishwambhar.rathi at puresoftware dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-30  8:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111646

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2023-09-30

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Works for me on a physical hardware:
```
ubuntu@ubuntu:~/src\# gcc t.c -lm
ubuntu@ubuntu:~/src\# ./a.out
x -9311848.013224 cosx_1 -0.634393
x -9311848.013224 cosx_2 -0.634393
ubuntu@ubuntu:~/src\# gcc t.c -lm -O1
ubuntu@ubuntu:~/src\# ./a.out
x -9311848.013224 cosx_1 -0.634393
x -9311848.013224 cosx_2 -0.634393
ubuntu@ubuntu:~/src\# gcc t.c -lm -O2
ubuntu@ubuntu:~/src\# ./a.out
x -9311848.013224 cosx_1 -0.634393
x -9311848.013224 cosx_2 -0.634393
ubuntu@ubuntu:~/src\# uname -a
Linux ubuntu 5.4.74-10348-gabddb56e7886 #1 SMP PREEMPT Fri Mar 5 18:58:46 PST
2021 aarch64 aarch64 aarch64 GNU/Linux
ubuntu@ubuntu:~/src\# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.1 LTS
Release:        18.04
Codename:       bionic
ubuntu@ubuntu:~/src\# lscpu
Architecture:        aarch64
Byte Order:          Little Endian
CPU(s):              24
On-line CPU(s) list: 0-23
Thread(s) per core:  1
Core(s) per socket:  24
Socket(s):           1
Vendor ID:           Cavium
Model:               0
Stepping:            0x2
BogoMIPS:            200.00
L1d cache:           41K
L1i cache:           66K
L2i cache:           1280K
L3 cache:            14336K
Flags:               fp asimd aes pmull sha1 sha2 crc32 atomics cpuid asimdrdm
dcpop
```

Maybe this is a bug in qemu.

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

* [Bug middle-end/111646] cos function giving different result for the same input value
  2023-09-30  8:37 [Bug c/111646] New: cos function giving different result for the same input value vishwambhar.rathi at puresoftware dot com
  2023-09-30  8:45 ` [Bug middle-end/111646] " pinskia at gcc dot gnu.org
@ 2023-09-30  9:31 ` vishwambhar.rathi at puresoftware dot com
  2023-09-30 14:18 ` xry111 at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: vishwambhar.rathi at puresoftware dot com @ 2023-09-30  9:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111646

--- Comment #2 from vishwambhar.rathi at puresoftware dot com ---
Thanks. I am using Ubuntu 20.04. Could this be related to that? Or should I
post it on qemu?

________________________________
From: pinskia at gcc dot gnu.org <gcc-bugzilla@gcc.gnu.org>
Sent: 30 September 2023 14:15
To: Vishwambhar Rathi <vishwambhar.rathi@puresoftware.com>
Subject: [Bug middle-end/111646] cos function giving different result for the
same input value

[You don't often get email from gcc-bugzilla@gcc.gnu.org. Learn why this is
important at https://aka.ms/LearnAboutSenderIdentification ]

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111646

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2023-09-30

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Works for me on a physical hardware:
```
ubuntu@ubuntu:~/src\# gcc t.c -lm
ubuntu@ubuntu:~/src\# ./a.out
x -9311848.013224 cosx_1 -0.634393
x -9311848.013224 cosx_2 -0.634393
ubuntu@ubuntu:~/src\# gcc t.c -lm -O1
ubuntu@ubuntu:~/src\# ./a.out
x -9311848.013224 cosx_1 -0.634393
x -9311848.013224 cosx_2 -0.634393
ubuntu@ubuntu:~/src\# gcc t.c -lm -O2
ubuntu@ubuntu:~/src\# ./a.out
x -9311848.013224 cosx_1 -0.634393
x -9311848.013224 cosx_2 -0.634393
ubuntu@ubuntu:~/src\# uname -a
Linux ubuntu 5.4.74-10348-gabddb56e7886 #1 SMP PREEMPT Fri Mar 5 18:58:46 PST
2021 aarch64 aarch64 aarch64 GNU/Linux
ubuntu@ubuntu:~/src\# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.1 LTS
Release:        18.04
Codename:       bionic
ubuntu@ubuntu:~/src\# lscpu
Architecture:        aarch64
Byte Order:          Little Endian
CPU(s):              24
On-line CPU(s) list: 0-23
Thread(s) per core:  1
Core(s) per socket:  24
Socket(s):           1
Vendor ID:           Cavium
Model:               0
Stepping:            0x2
BogoMIPS:            200.00
L1d cache:           41K
L1i cache:           66K
L2i cache:           1280K
L3 cache:            14336K
Flags:               fp asimd aes pmull sha1 sha2 crc32 atomics cpuid asimdrdm
dcpop
```

Maybe this is a bug in qemu.

--
You are receiving this mail because:
You reported the bug.

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

* [Bug middle-end/111646] cos function giving different result for the same input value
  2023-09-30  8:37 [Bug c/111646] New: cos function giving different result for the same input value vishwambhar.rathi at puresoftware dot com
  2023-09-30  8:45 ` [Bug middle-end/111646] " pinskia at gcc dot gnu.org
  2023-09-30  9:31 ` vishwambhar.rathi at puresoftware dot com
@ 2023-09-30 14:18 ` xry111 at gcc dot gnu.org
  2023-10-01  5:50 ` vishwambhar.rathi at puresoftware dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-09-30 14:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111646

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |xry111 at gcc dot gnu.org

--- Comment #3 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
Are you compiling with optimization?  If you are not enabling any optimization,
the result of cos actually comes from Glibc and it's not a GCC issue.

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

* [Bug middle-end/111646] cos function giving different result for the same input value
  2023-09-30  8:37 [Bug c/111646] New: cos function giving different result for the same input value vishwambhar.rathi at puresoftware dot com
                   ` (2 preceding siblings ...)
  2023-09-30 14:18 ` xry111 at gcc dot gnu.org
@ 2023-10-01  5:50 ` vishwambhar.rathi at puresoftware dot com
  2023-10-01  9:37 ` xry111 at gcc dot gnu.org
  2024-03-17  3:48 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: vishwambhar.rathi at puresoftware dot com @ 2023-10-01  5:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111646

--- Comment #4 from vishwambhar.rathi at puresoftware dot com ---
I am not using any optimization flag in compiling. Where should I post about
this bug? Thanks.
________________________________
From: xry111 at gcc dot gnu.org <gcc-bugzilla@gcc.gnu.org>
Sent: 30 September 2023 19:48
To: Vishwambhar Rathi <vishwambhar.rathi@puresoftware.com>
Subject: [Bug middle-end/111646] cos function giving different result for the
same input value

[You don't often get email from gcc-bugzilla@gcc.gnu.org. Learn why this is
important at https://aka.ms/LearnAboutSenderIdentification ]

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111646

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |xry111 at gcc dot gnu.org

--- Comment #3 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
Are you compiling with optimization?  If you are not enabling any optimization,
the result of cos actually comes from Glibc and it's not a GCC issue.

--
You are receiving this mail because:
You reported the bug.

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

* [Bug middle-end/111646] cos function giving different result for the same input value
  2023-09-30  8:37 [Bug c/111646] New: cos function giving different result for the same input value vishwambhar.rathi at puresoftware dot com
                   ` (3 preceding siblings ...)
  2023-10-01  5:50 ` vishwambhar.rathi at puresoftware dot com
@ 2023-10-01  9:37 ` xry111 at gcc dot gnu.org
  2024-03-17  3:48 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-10-01  9:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111646

--- Comment #5 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(In reply to vishwambhar.rathi from comment #4)
> I am not using any optimization flag in compiling. Where should I post about
> this bug? Thanks.

I don't know because maybe this is a Glibc issue or a QEMU issue.

You can try changing Glibc version of QEMU version to figure out.

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

* [Bug middle-end/111646] cos function giving different result for the same input value
  2023-09-30  8:37 [Bug c/111646] New: cos function giving different result for the same input value vishwambhar.rathi at puresoftware dot com
                   ` (4 preceding siblings ...)
  2023-10-01  9:37 ` xry111 at gcc dot gnu.org
@ 2024-03-17  3:48 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-17  3:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111646

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|---                         |WORKSFORME

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
[apinski@xeond2 upstream-cross-aarch64]$ ./install/bin/aarch64-linux-gnu-gcc
-static  t67.c -lm
[apinski@xeond2 upstream-cross-aarch64]$ ./install-qemu/bin/qemu-aarch64 a.out
x -9311848.013224 cosx_1 -0.634393
x -9311848.013224 cosx_2 -0.634393


Works for me with the trunk gcc, glibc and qemu.

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

end of thread, other threads:[~2024-03-17  3:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-30  8:37 [Bug c/111646] New: cos function giving different result for the same input value vishwambhar.rathi at puresoftware dot com
2023-09-30  8:45 ` [Bug middle-end/111646] " pinskia at gcc dot gnu.org
2023-09-30  9:31 ` vishwambhar.rathi at puresoftware dot com
2023-09-30 14:18 ` xry111 at gcc dot gnu.org
2023-10-01  5:50 ` vishwambhar.rathi at puresoftware dot com
2023-10-01  9:37 ` xry111 at gcc dot gnu.org
2024-03-17  3:48 ` pinskia 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).