You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2023/09/04 13:27:01 UTC
[commons-numbers] branch master updated: Optimise Norm to initialise to the first square
This is an automated email from the ASF dual-hosted git repository.
aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git
The following commit(s) were added to refs/heads/master by this push:
new 5106583f Optimise Norm to initialise to the first square
5106583f is described below
commit 5106583f98fd14b3de16b542b8396f17b0c2116e
Author: aherbert <ah...@apache.org>
AuthorDate: Mon Sep 4 13:51:28 2023 +0100
Optimise Norm to initialise to the first square
There is no requirement to add to the existing sum and compensation
which are zero.
---
.../java/org/apache/commons/numbers/core/Norm.java | 23 ++++++----------------
1 file changed, 6 insertions(+), 17 deletions(-)
diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Norm.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Norm.java
index d2583e49..03ea2222 100644
--- a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Norm.java
+++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Norm.java
@@ -302,16 +302,10 @@ public enum Norm {
rescale = 1d;
}
- double sum = 0d;
- double comp = 0d;
-
- // add scaled x
+ // initialise sum and compensation using scaled x
final double sx = xabs * scale;
- final double px = sx * sx;
- comp += DD.twoSquareLow(sx, px);
- final double sumPx = sum + px;
- comp += DD.twoSumLow(sum, px, sumPx);
- sum = sumPx;
+ double sum = sx * sx;
+ double comp = DD.twoSquareLow(sx, sum);
// add scaled y
final double sy = yabs * scale;
@@ -367,16 +361,11 @@ public enum Norm {
rescale = 1d;
}
- double sum = 0d;
- double comp = 0d;
- // add scaled x
+ // initialise sum and compensation using scaled x
final double sx = xabs * scale;
- final double px = sx * sx;
- comp += DD.twoSquareLow(sx, px);
- final double sumPx = sum + px;
- comp += DD.twoSumLow(sum, px, sumPx);
- sum = sumPx;
+ double sum = sx * sx;
+ double comp = DD.twoSquareLow(sx, sum);
// add scaled y
final double sy = yabs * scale;