8000 GH-100425: Improve accuracy of builtin sum() for float inputs by rhettinger · Pull Request #100426 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-100425: Improve accuracy of builtin sum() for float inputs #100426

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

Merged
merged 13 commits into from
Dec 23, 2022
Merged
Prev Previous commit
Next Next commit
Move local declarations inside the block where they are used.
  • Loading branch information
rhettinger committed Dec 23, 2022
commit 4da0b8ff2e83ecea46bab85d56850851ea3c7eec
5 changes: 2 additions & 3 deletions Python/bltinmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2533,7 +2533,6 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
if (PyFloat_CheckExact(result)) {
double f_result = PyFloat_AS_DOUBLE(result);
double c = 0.0;
double x, t;
Py_SETREF(result, NULL);
while(result == NULL) {
item = PyIter_Next(iter);
Expand All @@ -2552,8 +2551,8 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
if (PyFloat_CheckExact(item)) {
// Improved Kahan–Babuška algorithm by Arnold Neumaier
// https://www.mat.univie.ac.at/~neum/scan/01.pdf
x = PyFloat_AS_DOUBLE(item);
t = f_result + x;
double x = PyFloat_AS_DOUBLE(item);
double t = f_result + x;
if (fabs(f_result) >= fabs(x)) {
c += (f_result - t) + x;
} else {
Expand Down
0