FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-119613: use C99+ functions instead of Py_IS_NAN/INFINITY/FINITE by skirpichev · Pull Request #119619 · python/cpython · GitHub

/ cpython Public

gh-119613: use C99+ functions instead of Py_IS_NAN/INFINITY/FINITE - #119619

Merged
vstinner merged 1 commit into
python:mainfrom
skirpichev:deprecate-py-is-nan-119613
May 29, 2024
Merged

gh-119613: use C99+ functions instead of Py_IS_NAN/INFINITY/FINITE#119619
vstinner merged 1 commit into
python:mainfrom
skirpichev:deprecate-py-is-nan-119613

Conversation

skirpichev commented May 27, 2024
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

This comment was marked as resolved.

Eclips4 commented May 27, 2024

Copy link
Copy Markdown
Member

This partially address #119613. I think this part doesn't require a news entry. CC @Eclips4

Yes, since this is a non-visible user change, I agreed.

rhettinger commented May 27, 2024
edited
Loading

Copy link
Copy Markdown
Contributor

@tim-one is there an on-going reason to have these portability macros? Are NaN values guaranteed to be supported?

rhettinger requested a review from mdickinson May 28, 2024 00:16

Copy link
Copy Markdown
Member Author

Since 194a952 these macros are just aliases for isnan, isinf, etc:

cpython/Include/pymath.h

Lines 30 to 40 in 3e8b609

// Py_IS_NAN(X)
// Return 1 if float or double arg is a NaN, else 0.
#define Py_IS_NAN(X) isnan(X)
// Py_IS_INFINITY(X)
// Return 1 if float or double arg is an infinity, else 0.
#define Py_IS_INFINITY(X) isinf(X)
// Py_IS_FINITE(X)
// Return 1 if float or double arg is neither infinite nor NAN, else 0.
#define Py_IS_FINITE(X) isfinite(X)

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM. Simple text replacement.

Copy link
Copy Markdown
Member

@rhettinger:

@tim-one is there an on-going reason to have these portability macros? Are NaN values guaranteed to be supported?

Python 3.10 and older supported platforms without IEEE 754, without NaN, and without C99 <math.h>. We had complex macros such as:

#ifndef Py_IS_NAN
#if defined HAVE_DECL_ISNAN && HAVE_DECL_ISNAN == 1
#define Py_IS_NAN(X) isnan(X)
#else
#define Py_IS_NAN(X) ((X) != (X))
#endif
#endif

Python 3.11 and newer requires IEEE 754, NaN and C99 <math.h>. Macros were kept for backward compatibility only:

#define Py_IS_NAN(X) isnan(X)

Issues:

See also this LWN article: CPython, C standards, and IEEE 754.

Copy link
Copy Markdown
Member

@mdickinson: Are you ok with this change? You wrote a comment about these macros there: #119457 (comment)

Copy link
Copy Markdown
Member

@mdickinson: Are you ok with this change?

Yes, absolutely. I'm fairly sure the macros were born out of (now somewhat ancient) portability needs that no longer apply, now that C99 (and later) adoption is sufficiently widespread.

I'd suggest running all buildbots on this PR, just to be on the safe side.

mdickinson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

mdickinson added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 28, 2024

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @mdickinson for commit 13dcd12 🤖

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 28, 2024

Copy link
Copy Markdown
Member Author

There are tests failures, but hardly it's related to the pr. Something expected, given there are not build bots for non-IEEE-754 platforms, right?

Copy link
Copy Markdown
Member

There are tests failures, but hardly it's related to the pr.

Agreed - the failures look unrelated.

vstinner merged commit cd11ff1 into python:main May 29, 2024

Copy link
Copy Markdown
Member

Merged, thanks.

skirpichev deleted the deprecate-py-is-nan-119613 branch May 29, 2024 07:52
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants


Back | FazBrowse Home | New Git URL