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 — bpo-38639: Optimize floor(), ceil() and trunc() for floats. by serhiy-storchaka · Pull Request #16991 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Oct 30, 2019 •
edited by bedevere-bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

https://bugs.python.org/issue38639

Sorry, something went wrong.

Uh oh!

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

All reactions
@serhiy-storchaka
bpo-38639: Optimize floor(), ceil() and trunc() for floats.
d80f7bd
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Oct 30, 2019
@bedevere-bot bedevere-bot added the awaiting core review label Oct 30, 2019
mdickinson
mdickinson reviewed Oct 30, 2019
View reviewed changes
Comment thread Modules/mathmodule.c Resolved

Uh oh!

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

mdickinson
mdickinson approved these changes Oct 30, 2019
View reviewed changes

@mdickinson mdickinson 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.

Proposed changes LGTM. For things of exact type float (and possibly also for float subclasses), I think we could dispense with the math_1_to_int complications to get even more speedup. But that doesn't have to happen in this PR.

Do we have tests for the various cases of floats, float subclasses that don't override __floor__, float subclasses that do override __floor__, things that aren't floats but provide a __float__ method, etc.? If not, would it be worth adding such tests?

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Oct 30, 2019
@mdickinson

mdickinson commented Oct 30, 2019

Copy link
Copy Markdown
Member

Do we have tests for the various cases ...

It occurs to me that I don't know how a subclass of float that implements its own __float__ should behave.

>>> class MyFloat(float):
...     def __float__(self):
...         return 9.0
... 
>>> x = MyFloat(16)
>>> math.sqrt(x)
4.0
>>> float(x)
9.0
All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka serhiy-storchaka mentioned this pull request Oct 30, 2019
bpo-38629: implement __floor__ and __ceil__ for float #16985
Merged
serhiy-storchaka added 2 commits October 30, 2019 22:23
@serhiy-storchaka
Get rid of math_1_to_int.
265271a
@serhiy-storchaka
Add tests.
864845a
@serhiy-storchaka

serhiy-storchaka commented Nov 7, 2019

Copy link
Copy Markdown
Member Author

I think that it would be better to not call __float__ for float subclasses, __int__ and __index__ for int subclasses, __complex__ for complex subclasses, __str__ for str subclasses, etc. We already have a content of corresponding class and can convert it to a C value or to a new Python instance.

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka

serhiy-storchaka commented Nov 7, 2019

Copy link
Copy Markdown
Member Author

Thank you for your review @mdickinson, I addressed your comments and added tests. Could you please take another look?

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka
serhiy-storchaka merged commit 5fd5cb8 into python:master Nov 16, 2019
@serhiy-storchaka
serhiy-storchaka deleted the math-floor-float branch November 16, 2019 16:00
@bedevere-bot bedevere-bot removed the awaiting merge label Nov 16, 2019
jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this pull request Dec 5, 2019
@serhiy-storchaka Jake Taylor
bpo-38639: Optimize floor(), ceil() and trunc() for floats. (pythonGH…
cd75b1f
…-16991)
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
@serhiy-storchaka @shihai1991
bpo-38639: Optimize floor(), ceil() and trunc() for floats. (pythonGH…
0166988
…-16991)
@mdickinson mdickinson mentioned this pull request Feb 9, 2023
gh-101678: Merge math_1_to_whatever() and math_1() #101730
Merged
mdickinson pushed a commit that referenced this pull request Feb 9, 2023
@skirpichev
gh-101678: Merge math_1_to_whatever() and math_1() (#101730)
45fa12a
`math_1_to_whatever()` is no longer useful, since all existing uses of it convert to `float`.
Earlier versions of Python used `math_1_to_whatever` with an integer target; see
gh-16991 for the PR where that use was removed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@mdickinson mdickinson mdickinson approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

No one assigned

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

@serhiy-storchaka @mdickinson @the-knights-who-say-ni @bedevere-bot
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.