This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git


The following commit(s) were added to refs/heads/master by this push:
     new bb02fad  Avoid redundant computations.
bb02fad is described below

commit bb02fad3e3663062e563c29302375279fcd0cb45
Author: Gilles Sadowski <gillese...@gmail.com>
AuthorDate: Wed Oct 28 03:21:33 2020 +0100

    Avoid redundant computations.
---
 src/main/java/org/apache/commons/math4/util/MathArrays.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/math4/util/MathArrays.java 
b/src/main/java/org/apache/commons/math4/util/MathArrays.java
index a7488e2..864dbcf 100644
--- a/src/main/java/org/apache/commons/math4/util/MathArrays.java
+++ b/src/main/java/org/apache/commons/math4/util/MathArrays.java
@@ -912,11 +912,12 @@ public class MathArrays {
         if (sum == 0) {
             throw new 
MathArithmeticException(LocalizedFormats.ARRAY_SUMS_TO_ZERO);
         }
+        final double scale = normalizedSum / sum;
         for (int i = 0; i < len; i++) {
             if (Double.isNaN(values[i])) {
                 out[i] = Double.NaN;
             } else {
-                out[i] = values[i] * normalizedSum / sum;
+                out[i] = values[i] * scale;
             }
         }
         return out;

Reply via email to