From 438e9fc66f664eff0526a16a6d900349bfd1f9d2 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 22 Sep 2020 20:01:12 -0700 Subject: [PATCH] bpo-41513: Improve order of adding fractional values. Improve variable names. (GH-22368) --- Modules/mathmodule.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index 935759ec671..5cd31b7dd4a 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -2502,8 +2502,8 @@ References: static inline double vector_norm(Py_ssize_t n, double *vec, double max, int found_nan) { - const double T27 = 134217729.0; /* ldexp(1.0, 27)+1.0) */ - double x, csum = 1.0, oldcsum, scale, frac=0.0, frac_mid=0.0, frac_lo=0.0; + const double T27 = 134217729.0; /* ldexp(1.0, 27) + 1.0) */ + double x, scale, oldcsum, csum = 1.0, frac1 = 0.0, frac2 = 0.0, frac3 = 0.0; double t, hi, lo, h; int max_e; Py_ssize_t i; @@ -2539,18 +2539,18 @@ 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; + frac1 += (oldcsum - csum) + x; x = 2.0 * hi * lo; assert(fabs(csum) >= fabs(x)); oldcsum = csum; csum += x; - frac_mid += (oldcsum - csum) + x; + frac2 += (oldcsum - csum) + x; assert(csum + lo * lo == csum); - frac_lo += lo * lo; + frac3 += lo * lo; } - h = sqrt(csum - 1.0 + (frac_lo + frac_mid + frac)); + h = sqrt(csum - 1.0 + (frac1 + frac2 + frac3)); x = h; t = x * T27; @@ -2562,21 +2562,21 @@ 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; + frac1 += (oldcsum - csum) + x; x = -2.0 * hi * lo; assert(fabs(csum) >= fabs(x)); oldcsum = csum; csum += x; - frac_mid += (oldcsum - csum) + x; + frac2 += (oldcsum - csum) + x; x = -lo * lo; assert(fabs(csum) >= fabs(x)); oldcsum = csum; csum += x; - frac_lo += (oldcsum - csum) + x; + frac3 += (oldcsum - csum) + x; - x = csum - 1.0 + (frac_lo + frac_mid + frac); + x = csum - 1.0 + (frac1 + frac2 + frac3); return (h + x / (2.0 * h)) / scale; } /* When max_e < -1023, ldexp(1.0, -max_e) overflows. @@ -2591,9 +2591,9 @@ 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; + frac1 += (oldcsum - csum) + x; } - return max * sqrt(csum - 1.0 + frac); + return max * sqrt(csum - 1.0 + frac1); } #define NUM_STACK_ELEMS 16