Avoid redundant computations.
This commit is contained in:
parent
43b77ffabb
commit
bb02fad3e3
|
@ -912,11 +912,12 @@ public class MathArrays {
|
||||||
if (sum == 0) {
|
if (sum == 0) {
|
||||||
throw new MathArithmeticException(LocalizedFormats.ARRAY_SUMS_TO_ZERO);
|
throw new MathArithmeticException(LocalizedFormats.ARRAY_SUMS_TO_ZERO);
|
||||||
}
|
}
|
||||||
|
final double scale = normalizedSum / sum;
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
if (Double.isNaN(values[i])) {
|
if (Double.isNaN(values[i])) {
|
||||||
out[i] = Double.NaN;
|
out[i] = Double.NaN;
|
||||||
} else {
|
} else {
|
||||||
out[i] = values[i] * normalizedSum / sum;
|
out[i] = values[i] * scale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
|
|
Loading…
Reference in New Issue