Skip to content

bpo-47031: Improve documentation for math.nan #32170

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

Merged
merged 4 commits into from
Apr 2, 2022

Conversation

CharlieZhao95
Copy link
Contributor

@CharlieZhao95 CharlieZhao95 commented Mar 29, 2022

Documentation improvements for math.nan with following points:

  • Explain that NANs are never equal to anything, even to themselves.
  • Use math.isnan(x) to check whether a number is a NaN.
  • Add some simple doc examples.

https://bugs.python.org/issue47031

@bedevere-bot bedevere-bot added the docs Documentation in the Doc dir label Mar 29, 2022
False
>>> math.nan is math.nan
True
>>> float('nan') is float('nan')
Copy link
Member

Choose a reason for hiding this comment

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

Not too happy about this example because I could see us change this behavior in the future to return the same NaN object.

Copy link
Contributor Author

@CharlieZhao95 CharlieZhao95 Mar 29, 2022

Choose a reason for hiding this comment

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

Not too happy about this example because I could see us change this behavior in the future to return the same NaN object.

I feel the same way, this example is confusing. This phenomenon is simply due to the differences in function implementations, not related to any standard.

Maybe we should omit the example about is and just keep docs to remind users not use is to check if a number is a NaN.

CharlieZhao95 and others added 3 commits March 29, 2022 11:30
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@CharlieZhao95 CharlieZhao95 marked this pull request as ready for review March 29, 2022 07:23
@JelleZijlstra JelleZijlstra added needs backport to 3.9 only security fixes needs backport to 3.10 only security fixes labels Apr 2, 2022
@JelleZijlstra JelleZijlstra merged commit 182e93c into python:main Apr 2, 2022
@miss-islington
Copy link
Contributor

Thanks @CharlieZhao95 for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-32263 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed needs backport to 3.10 only security fixes needs backport to 3.9 only security fixes labels Apr 2, 2022
@bedevere-bot
Copy link

GH-32264 is a backport of this pull request to the 3.9 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 2, 2022
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 182e93c)

Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com>
miss-islington added a commit that referenced this pull request Apr 2, 2022
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 182e93c)

Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com>
miss-islington added a commit that referenced this pull request Apr 2, 2022
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 182e93c)

Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com>
hello-adam pushed a commit to hello-adam/cpython that referenced this pull request Jun 2, 2022
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 182e93c)

Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants