Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-135853: addmath.signbit#135877

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
picnixz wants to merge4 commits intopython:main
base:main
Choose a base branch
Loading
frompicnixz:feat/math/signbit-135853

Conversation

picnixz
Copy link
Member

@picnixzpicnixz commentedJun 24, 2025
edited
Loading

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/

Copy link
Contributor

@skirpichevskirpichev left a comment

Choose a reason for hiding this comment

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

LGTM

Some nitpicks, based on wording in the C17.

@picnixzpicnixz requested a review fromskirpichevJune 24, 2025 09:29
@picnixzpicnixzforce-pushed thefeat/math/signbit-135853 branch fromb406151 tof6a55ceCompareJune 24, 2025 09:55
Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

IMO it's ok to cast Csignint()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
Copy link
MemberAuthor

picnixz commentedJun 27, 2025
edited
Loading

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 thathttps://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)

@picnixzpicnixz self-assigned thisJun 27, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@vstinnervstinnervstinner approved these changes

@skirpichevskirpichevskirpichev approved these changes

@rhettingerrhettingerAwaiting requested review from rhettinger

@nineteendonineteendoAwaiting requested review from nineteendo

Assignees

@picnixzpicnixz

Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@picnixz@vstinner@skirpichev@nineteendo

[8]ページ先頭

©2009-2025 Movatter.jp