diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2020-09-23 03:01:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-23 03:01:12 (GMT) |
commit | 438e9fc66f664eff0526a16a6d900349bfd1f9d2 (patch) | |
tree | ebe2c0d0384debd0c81517d677a8d83803dfddfa | |
parent | d986d1657e1e7b50807d0633cb31d96a2d866d42 (diff) | |
download | cpython-438e9fc66f664eff0526a16a6d900349bfd1f9d2.zip cpython-438e9fc66f664eff0526a16a6d900349bfd1f9d2.tar.gz cpython-438e9fc66f664eff0526a16a6d900349bfd1f9d2.tar.bz2 |
bpo-41513: Improve order of adding fractional values. Improve variable names. (GH-22368)
-rw-r--r-- | Modules/mathmodule.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index 935759e..5cd31b7 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 |