GeezerVison is showing github.com — gh-135853: add `math.signbit` by picnixz · Pull Request #135877 · python/cpython
Conversation
picnixz
commented
Jun 24, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this 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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this 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 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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
picnixz
commented
Jun 27, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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)
|
vstinner reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|