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-156145: Don't rely on errno for float `pow` and `is_integer` by hpkfft · Pull Request #156551 · python/cpython

Conversation

@hpkfft

@hpkfft hpkfft commented Aug 29, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

This PR only addresses the Objects/floatobject.c portion of the linked issue.

Buy one get one free: I believe this PR allows closing #91290

  • Issue: Don't rely on errno values, coming from platform's math functions #156145

Sorry, something went wrong.

Uh oh!

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

All reactions
@hpkfft @skirpichev
pythongh-156145: Don't rely on errno for float pow and is_integer
bf36ba8
Co-authored-by: Sergey B Kirpichev <[email protected]>
@bedevere-app bedevere-app Bot added the awaiting review label Aug 29, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Aug 29, 2026
Don't rely on errno values, coming from platform's math functions #156145
Open
@skirpichev
skirpichev self-requested a review August 30, 2026 05:45
@skirpichev skirpichev added the skip news label Aug 30, 2026
skirpichev
skirpichev approved these changes Aug 30, 2026
View reviewed changes

@skirpichev skirpichev left a comment •
edited
Loading

Uh oh!

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

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.

There is one extra case in this file: double_round(). We use errno here to check overflows in _Py_dg_dtoa(), but can use isinf() as well.

On one hand, dtoa.c code bundled with the CPython and we can trust errno value here. On another hand, as discussed in the issue thread, we can get some performance boost with skipping errno checks (gcc v14.2, default configure flags):

Benchmark ref patch
round(31.4) 1.09 us 978 ns: 1.12x faster
benchmark and patch
import pyperf

x = 31.4

runner = pyperf.Runner()
runner.bench_func(f"round({x})", round, x, -1)
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 17e6a729dcd..8342dcbbd16 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -937,11 +936,10 @@ double_round(double x, int ndigits) {
                   buf, decpt - (int)buflen);
 
     /* and convert the resulting string back to a double */
-    errno = 0;
     _Py_SET_53BIT_PRECISION_START;
     rounded = _Py_dg_strtod(mybuf, NULL);
     _Py_SET_53BIT_PRECISION_END;
-    if (errno == ERANGE && fabs(rounded) >= 1.)
+    if (isinf(rounded))
         PyErr_SetString(PyExc_OverflowError,
                         "rounded value too large to represent");
     else

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 core review and removed awaiting review labels Aug 30, 2026
@skirpichev

skirpichev commented Aug 30, 2026

Copy link
Copy Markdown
Member

CC @picnixz

All reactions

Sorry, something went wrong.

Uh oh!

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

@skirpichev

skirpichev commented Aug 31, 2026

Copy link
Copy Markdown
Member

Another macro removed in #156694.

All reactions

Sorry, something went wrong.

Uh oh!

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

@hpkfft hpkfft mentioned this pull request Sep 5, 2026
gh-156695: Improve accuracy of complex div and pow #156968
Draft
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@skirpichev skirpichev skirpichev approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

awaiting core review skip news

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.

2 participants

@hpkfft @skirpichev
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.