Make fractional value accumulation consistent inside and outside the loop. (GH-22315)

This commit is contained in:
Raymond Hettinger 2020-09-18 17:57:28 -07:00 committed by GitHub
parent 8394500cca
commit ec8a15b034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 5 deletions

View File

@ -2550,8 +2550,7 @@ vector_norm(Py_ssize_t n, double *vec, double max, int found_nan)
assert(csum + lo * lo == csum); assert(csum + lo * lo == csum);
frac_lo += lo * lo; frac_lo += lo * lo;
} }
frac += frac_lo + frac_mid; h = sqrt(csum - 1.0 + (frac_lo + frac_mid + frac));
h = sqrt(csum - 1.0 + frac);
x = h; x = h;
t = x * T27; 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)); assert(fabs(csum) >= fabs(x));
oldcsum = csum; oldcsum = csum;
csum += x; csum += x;
frac += (oldcsum - csum) + x; frac_mid += (oldcsum - csum) + x;
x = -lo * lo; x = -lo * lo;
assert(fabs(csum) >= fabs(x)); assert(fabs(csum) >= fabs(x));
oldcsum = csum; oldcsum = csum;
csum += x; 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; return (h + x / (2.0 * h)) / scale;
} }
/* When max_e < -1023, ldexp(1.0, -max_e) overflows. /* When max_e < -1023, ldexp(1.0, -max_e) overflows.