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

gh-135853: add `math.signbit` by picnixz · Pull Request #135877 · python/cpython · GitHub

Repository navigation

gh-135853: add math.signbit - #135877

Merged
picnixz merged 4 commits into
python:mainfrom
picnixz:feat/math/signbit-135853
Jun 28, 2025
Merged

picnixz merged 4 commits into
python:mainfrom
picnixz:feat/math/signbit-135853

Conversation

picnixz commented Jun 24, 2025 •
edited
Loading

Copy link
Copy Markdown
Member

cc @mdickinson @skirpichev @rhettinger

I made the choice of returning True/False like numpy rather than the nonzero value itself as in C. If you want me to have another function that returns a boolean and keep signbit as in C, please tell me.


📚 Documentation preview 📚: https://cpython-previews--135877.org.readthedocs.build/

skirpichev 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

Some nitpicks, based on wording in the C17.

Comment thread Doc/library/math.rst Outdated
Comment thread Lib/test/test_math.py Outdated
Comment thread Modules/mathmodule.c Outdated
picnixz requested a review from skirpichev June 24, 2025 09:29
Comment thread Modules/mathmodule.c Outdated
picnixz force-pushed the feat/math/signbit-135853 branch from b406151 to f6a55ce Compare June 24, 2025 09:55
Comment thread Lib/test/test_math.py Outdated
Comment thread Doc/library/math.rst

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.

IMO it's ok to cast C signint() int result into a Python boolean, since it's unlikely that the signbit() will return values others than 0 and 1 in the future. The manual page says:

RETURN VALUE
       The signbit() macro returns nonzero if the sign of x is negative; other-
       wise it returns zero.

picnixz commented Jun 27, 2025 •
edited
Loading

Copy link
Copy Markdown
Member Author

IMO it's ok to cast C signint() int result into a Python boolean, since it's unlikely that the signbit() will return values others than 0 and 1 in the future. The manual page says:

Actually, signbit does return something else than 0/1 (in C) at least on some platforms, but that's what all predicate functions do in math.h (they are all specified as returning nonzero value if the condition holds). However, in C++, they return true/false. Note that https://en.cppreference.com/w/c/numeric/math/signbit shows an example where signbit() returns 128 for a negative zero.

However, since we return booleans for isfinite() etc, I also returned a boolean for signbit() (and in practice, people don't care about the return value, they only care about the test)

picnixz self-assigned this Jun 27, 2025
picnixz merged commit 42ccac2 into python:main Jun 28, 2025
picnixz deleted the feat/math/signbit-135853 branch June 28, 2025 12:46
AndPuQing pushed a commit to AndPuQing/cpython that referenced this pull request Jul 11, 2025
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL