Skip to content

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

@skirpichevskirpichev commented May 27, 2024

Copy link
Copy Markdown
Member

@skirpichev

This comment was marked as resolved.

@Eclips4

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

rhettinger commented May 27, 2024

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?

@skirpichev

Copy link
Copy Markdown
MemberAuthor

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

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

@vstinnervstinner 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.

LGTM. Simple text replacement.

@vstinner

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:

#ifndefPy_IS_NAN#if defined HAVE_DECL_ISNAN&&HAVE_DECL_ISNAN==1#definePy_IS_NAN(X) isnan(X)
#else#definePy_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:

#definePy_IS_NAN(X) isnan(X)

Issues:

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

@vstinner

Copy link
Copy Markdown
Member

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

@mdickinson

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.

@mdickinsonmdickinson 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.

LGTM

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

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

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
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:mainMay 29, 2024
@vstinner

Copy link
Copy Markdown
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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@skirpichev@Eclips4@rhettinger@vstinner@mdickinson@bedevere-bot