-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
Accuracy issues of sum() specialization for floats/complexes #122234
Comments
CC @rhettinger for the second part (integer values). Is this an issue or a feature? |
Actually, even without the >>> x = 10 ** 100
>>> 1.0 + x + 1.0 - x
0.0 |
Hmm, with PyLong_AsDouble() + compensated summation it's even faster!
while in the main:
|
* Use compensated summation for complex sums with floating-point items. This amends python#121176. * sum() specializations for floats and complexes now use PyLong_AsDouble() instead of PyLong_AsLongAndOverflow() and compensated summation as well.
PR is ready for review: #122236 It combines fixes for floats and integers. If second case requires more discussion or is "a feature", I can quickly revert that part. |
The added error returns leak references. This was caught by the noGIL refleak buildbot (which runs more often than refleaks for regular-builds): https://buildbot.python.org/#/builders/1226/builds/2352/steps/6/logs/stdio |
PR is ready: #122405 |
My PR #122406 looks exactly the same :) |
Co-Authored-By: Kirill Podoprigora <kirill.bast9@mail.ru>
Closing since the refleak is now fixed. |
Bug report
Bug description:
Unfortunately, #121176 was merged with a bug:
cpython/Python/bltinmodule.c
Lines 2749 to 2755 in e968121
L2751 lacks cs_add(). Sorry for that. Reproducer:
sum([2j, 1., 10E100, 1., -10E100])
(should be2+2j
). I'll provide a patch.But maybe cases for integer arguments also should use compensated summation? E.g.:
cpython/Python/bltinmodule.c
Lines 2689 to 2698 in e968121
on L2694 (and use
PyLong_AsDouble()
). An example:I would guess, that integer values in this case are treated as exact and they are allowed to smash floating-point result to garbage. But... This looks as a bug for me.
fsum()
also chooses2.0
:CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: