gh-140443: Use fma in loghelper to improve accuracy of log for very large integers#140469
Merged
Conversation
4457f4e to
de6ba0d
Compare
Member
|
Please add your name to |
de6ba0d to
33acf47
Compare
33acf47 to
760614c
Compare
…ery large integers
Replaced the expression computing the final result in loghelper with an
fma() call:
result = fma(func(2.0), (double)e, func(x));
This change reduces rounding error and improves the ULP distribution of
math.log10() for very large integer inputs.
760614c to
f05b4b2
Compare
tim-one
approved these changes
Oct 23, 2025
tim-one
left a comment
Member
There was a problem hiding this comment.
It's been a joy! Thank you for your efforts and patience. It's amazing how much "busy work" there is to make a 1-line change 🤣, eh?
It all looks good to me. I'll merge it tomorrow. Perhaps @StanFromIreland knows more than me about what kind of markup decorations are wanted in NEWS entries. I can never remember that stuff
Contributor
Author
|
Thank you, @tim-one and @StanFromIreland, for your guidance throughout this PR (and thank you for pointing out my mistakes.) I’ve learned a great deal from your feedback and reviews. |
StanFromIreland
approved these changes
Oct 23, 2025
…e-140443.wT5i1A.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
skirpichev
reviewed
Oct 23, 2025
skirpichev
approved these changes
Oct 23, 2025
StanFromIreland
added a commit
to StanFromIreland/cpython
that referenced
this pull request
Dec 6, 2025
…for very large integers (python#140469) * pythongh-140443:use fma in loghelper to improve accuracy of log for very large integers Use fused multiply-add in log_helper() for huge ints. Saving a rounding here is remarkably effective. Across some millions of randomized test cases with ints up to a billion bits, on Windows and using log10, the ULP error distribution was dramatically flattened, and its range was nearly cut in half. In fact, the largest error Tim saw was under 0.6 ULP. --------- Co-authored-by: abhi210 <27881020+Abhi210@users.noreply.github.com> Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Replaced the expression computing the final result in loghelper with an fma() call:
This change reduces rounding error and improves the ULP distribution of math.log for very large integer inputs.