GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-135853: add `math.signbit` by picnixz · Pull Request #135877 · python/cpython

Conversation

@picnixz

@picnixz picnixz commented Jun 24, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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.

  • Issue: Decide the fate of missing C99 functions in math #135853

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@picnixz
add math.signbit
5e4db08
@picnixz
picnixz requested a review from skirpichev June 24, 2025 08:54
@bedevere-app bedevere-app Bot added the awaiting core review label Jun 24, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Jun 24, 2025
Decide the fate of missing C99 functions in math #135853
Closed
@picnixz
picnixz requested a review from rhettinger June 24, 2025 08:54
skirpichev
skirpichev approved these changes Jun 24, 2025
View reviewed changes

@skirpichev skirpichev left a comment

Copy link
Copy Markdown
Member

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.

All reactions
Comment thread Doc/library/math.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_math.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/mathmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Misc/NEWS.d/next/Library/2025-06-24-10-23-37.gh-issue-135853.6xDNOG.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@picnixz
address review
1a2d3e4
@picnixz
picnixz requested a review from skirpichev June 24, 2025 09:29
skirpichev
skirpichev approved these changes Jun 24, 2025
View reviewed changes
Comment thread Modules/mathmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@picnixz
address review
f6a55ce
@picnixz
picnixz force-pushed the feat/math/signbit-135853 branch from b406151 to f6a55ce Compare June 24, 2025 09:55
vstinner
vstinner reviewed Jun 24, 2025
View reviewed changes
Comment thread Lib/test/test_math.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

nineteendo
nineteendo reviewed Jun 24, 2025
View reviewed changes
Comment thread Doc/library/math.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@picnixz
address review
bc362a3
@picnixz
picnixz requested review from nineteendo, skirpichev and vstinner June 27, 2025 13:51
skirpichev
skirpichev approved these changes Jun 27, 2025
View reviewed changes
vstinner
vstinner approved these changes Jun 27, 2025
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

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.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Jun 27, 2025
@picnixz

picnixz commented Jun 27, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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)

vstinner reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz picnixz self-assigned this Jun 27, 2025
@picnixz
picnixz merged commit 42ccac2 into python:main Jun 28, 2025
@picnixz
picnixz deleted the feat/math/signbit-135853 branch June 28, 2025 12:46
@bedevere-app bedevere-app Bot removed the awaiting merge label Jun 28, 2025
AndPuQing pushed a commit to AndPuQing/cpython that referenced this pull request Jul 11, 2025
@picnixz @AndPuQing
pythongh-135853: add math.signbit (python#135877)
820d7fc
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
@picnixz @Pranjal095
pythongh-135853: add math.signbit (python#135877)
6a1475e
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
@picnixz @taegyunkim
pythongh-135853: add math.signbit (python#135877)
dacdd60
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
@picnixz @Agent-Hellboy
pythongh-135853: add math.signbit (python#135877)
7050d27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner approved these changes
@skirpichev skirpichev skirpichev approved these changes
@rhettinger rhettinger Awaiting requested review from rhettinger
@nineteendo nineteendo Awaiting requested review from nineteendo

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@picnixz picnixz

Labels

None yet

Projects

None yet

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.

4 participants

@picnixz @vstinner @skirpichev @nineteendo
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.