-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed as not planned
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
Rounding an int by a large positive ndigits is instantaneous, while a by a large negative number takes ages, only to return zero:
>>> large_number = 2**31
>>> large_negative_number = -2**31
>>> d = 17000
>>> d.__round__(large_number) # Instant result, returns d
17000
>>> d.__round__(large_negative_number) # Takes forever, calculating divmod(d, int(pow(10, large_negative_number)))
It could be almost as fast as the positive ndigits case by checking:
int(math.log10(d)) < abs(large_negative_number)
And returning zero if it's True.
A similar optimization is possible for Fraction
: #132472
I realize there may not be a real use case for these enhancements.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
It was very briefly discussed on Discord.
Linked PRs
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement