diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2018-08-12 14:18:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-12 14:18:56 -0700 |
commit | a47f394af83c4bc29fac65c31e04091f87b98b35 (patch) | |
tree | b0320770be6809eec270788ce97798c3e78cbffa /Modules/mathmodule.c | |
parent | 00414597b43b78c059f3741e7b1a98adf87a3ed3 (diff) | |
download | cpython-git-a47f394af83c4bc29fac65c31e04091f87b98b35.tar.gz |
Minor code clean-up. Don't alter the input vector. Use variables instead. GH-8748
Diffstat (limited to 'Modules/mathmodule.c')
-rw-r--r-- | Modules/mathmodule.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index ab49dcef28..2d483afff5 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -2056,7 +2056,7 @@ the *vec* is a NaN. static inline double vector_norm(Py_ssize_t n, double *vec, double max, int found_nan) { - double x, csum = 0.0, oldcsum, frac = 0.0; + double x, csum = 0.0, oldcsum, frac = 0.0, last; Py_ssize_t i; if (Py_IS_INFINITY(max)) { @@ -2069,12 +2069,13 @@ vector_norm(Py_ssize_t n, double *vec, double max, int found_nan) return 0.0; } assert(n > 0); + last = vec[n-1]; for (i=0 ; i < n-1 ; i++) { x = vec[i]; assert(Py_IS_FINITE(x) && x >= 0.0 && x <= max); if (x == max) { - x = vec[n-1]; - vec[n-1] = max; + x = last; + last = max; } x /= max; x = x*x - frac; @@ -2082,7 +2083,7 @@ vector_norm(Py_ssize_t n, double *vec, double max, int found_nan) csum += x; frac = (csum - oldcsum) - x; } - assert(vec[n-1] == max); + assert(last == max); csum += 1.0 - frac; return max * sqrt(csum); } |