GeezerVison is showing github.com — bpo-38639: Optimize floor(), ceil() and trunc() for floats. by serhiy-storchaka · Pull Request #16991 · python/cpython
Conversation
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.
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.
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
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thank you for your review @mdickinson, I addressed your comments and added tests. Could you please take another look?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
mdickinson
pushed a commit
that referenced
this pull request
Feb 9, 2023
`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.
Reviewers
1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
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.
|