summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2020-09-19 00:57:28 (GMT)
committerGitHub <noreply@github.com>2020-09-19 00:57:28 (GMT)
commitec8a15b034124f3b58d1addda789fa4c20313006 (patch)
tree1905da0b22010602db49bac20141ca9f0d6f5e63
parent8394500cca56490cc347604d39ca40abcdce46c3 (diff)
downloadcpython-ec8a15b034124f3b58d1addda789fa4c20313006.zip
cpython-ec8a15b034124f3b58d1addda789fa4c20313006.tar.gz
cpython-ec8a15b034124f3b58d1addda789fa4c20313006.tar.bz2
Make fractional value accumulation consistent inside and outside the loop. (GH-22315)
-rw-r--r--Modules/mathmodule.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index ecd291e..935759e 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -2550,8 +2550,7 @@ vector_norm(Py_ssize_t n, double *vec, double max, int found_nan)
assert(csum + lo * lo == csum);
frac_lo += lo * lo;
}
- frac += frac_lo + frac_mid;
- h = sqrt(csum - 1.0 + frac);
+ h = sqrt(csum - 1.0 + (frac_lo + frac_mid + frac));
x = h;
t = x * T27;
@@ -2569,15 +2568,15 @@ vector_norm(Py_ssize_t n, double *vec, double max, int found_nan)
assert(fabs(csum) >= fabs(x));
oldcsum = csum;
csum += x;
- frac += (oldcsum - csum) + x;
+ frac_mid += (oldcsum - csum) + x;
x = -lo * lo;
assert(fabs(csum) >= fabs(x));
oldcsum = csum;
csum += x;
- frac += (oldcsum - csum) + x;
+ frac_lo += (oldcsum - csum) + x;
- x = csum - 1.0 + frac;
+ x = csum - 1.0 + (frac_lo + frac_mid + frac);
return (h + x / (2.0 * h)) / scale;
}
/* When max_e < -1023, ldexp(1.0, -max_e) overflows.