Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 29, 2024

Conversation

skirpichev
Copy link
Member

@skirpichev skirpichev commented May 27, 2024

@skirpichev

This comment was marked as resolved.

@Eclips4
Copy link
Member

Eclips4 commented May 27, 2024

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
Copy link
Contributor

rhettinger commented May 27, 2024

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

@rhettinger rhettinger requested a review from mdickinson May 28, 2024 00:16
@skirpichev
Copy link
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)

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM. Simple text replacement.

@vstinner
Copy link
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.

@vstinner
Copy link
Member

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

@mdickinson
Copy link
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.

Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

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

LGTM

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

🤖 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 bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 28, 2024
@skirpichev
Copy link
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?

@mdickinson
Copy link
Member

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

Agreed - the failures look unrelated.

@vstinner vstinner merged commit cd11ff1 into python:main May 29, 2024
113 of 126 checks passed
@vstinner
Copy link
Member

Merged, thanks.

@skirpichev 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
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