public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/104389] New: HUGE_VAL * 0.0 is no longer a NaN
@ 2022-02-04 19:02 vstinner at redhat dot com
  2022-02-04 19:15 ` [Bug c/104389] [10/11/12 Regression] " jakub at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: vstinner at redhat dot com @ 2022-02-04 19:02 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104389
           Summary: HUGE_VAL * 0.0 is no longer a NaN
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vstinner at redhat dot com
  Target Milestone: ---

Created attachment 52352
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52352&action=edit
Reproducer: huge_val_0_nan.c

The Python project uses "HUGE_VAL * 0" to get a Not-a-Number (NaN) double
value. Pseudo-code:

#define Py_NAN (Py_HUGE_VAL * 0.)
double my_nan(void)
{ return Py_NAN; }

Until Fedora gcc-12.0.1-0.4.fc36.x86_64
(03182470d2d2b272f06500184acab6b8ed78d8ad), it worked well.

With Fedora gcc-12.0.1-0.5.fc36.x86_64
(fb6057a2be99e071993fb54a5d338ab0febba8ff), my_nan() now returns zero (0.0).

Try attached huge_val_0_nan.c.

gcc-12.0.1-0.5.fc36.x86_64 output:
---
(1) Compute HUGE_VAL * 0 in the C compiler
isnan? 0
bytes: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]

(2) Compute HUGE_VAL * 0 at runtime
isnan? 1
bytes: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfffffff8, 0xffffffff]
---

gcc-11.2.1-7.fc35.x86_64 output:
---
(1) Compute HUGE_VAL * 0 in the C compiler
isnan? 1
bytes: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfffffff8, 0x7f]

(2) Compute HUGE_VAL * 0 at runtime
isnan? 1
bytes: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfffffff8, 0xffffffff]
---

In Python, Py_NAN is defined as "#define Py_NAN (Py_HUGE_VAL * 0.)" at:

https://github.com/python/cpython/blob/bf95ff91f2c1fc5a57190491f9ccdc63458b089e/Include/pymath.h#L60

FYI diff of the Fedora package between -4 and -5, the most important part if
the Git commit which changed ;-)

https://src.fedoraproject.org/rpms/gcc/c/398138b5f3809856b98eb4241b3c9f70da3fce9b?branch=rawhide

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

end of thread, other threads:[~2022-02-07  7:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-04 19:02 [Bug c/104389] New: HUGE_VAL * 0.0 is no longer a NaN vstinner at redhat dot com
2022-02-04 19:15 ` [Bug c/104389] [10/11/12 Regression] " jakub at gcc dot gnu.org
2022-02-04 19:19 ` jakub at gcc dot gnu.org
2022-02-04 19:22 ` jakub at gcc dot gnu.org
2022-02-04 19:26 ` jakub at gcc dot gnu.org
2022-02-04 19:43 ` [Bug tree-optimization/104389] " jakub at gcc dot gnu.org
2022-02-04 22:28 ` glisse at gcc dot gnu.org
2022-02-05  9:54 ` cvs-commit at gcc dot gnu.org
2022-02-05 10:22 ` [Bug tree-optimization/104389] [12 " jakub at gcc dot gnu.org
2022-02-07  7:15 ` xry111 at mengyan1223 dot wang

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