-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-91851: Trivial optimizations in Fraction #100791
Conversation
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.
Thanks! Microbenchmarks confirm that this is about 2x as fast.
LGTM. That's a pretty clunky implementation of round-ties-to-even in the d = self._denominator
rounded, remainder = divmod(self._numerator + (d >> 1), d)
if not remainder and not (d & 1): # tie case
rounded &= -2
return rounded EDIT: A bit more streamlined, and avoiding unnecessary d = self._denominator
rounded, remainder = divmod(self._numerator + (d >> 1), d)
return rounded if remainder or d & 1 else rounded & -2 |
Misc/NEWS.d/next/Library/2023-01-05-23-04-15.gh-issue-91851.AuCzU5.rst
Outdated
Show resolved
Hide resolved
Turns out not, at least on my machine. |
NB: this is the first commit from #25518