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 2021/06/09 23:56:19 UTC
[commons-numbers] 03/05: Use new BigDecimal(double) and not
BigDecimal.valueOf(double)
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
commit ee1152cd88666716bda3f86f4a0a4a6a031f273c
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Thu Jun 10 00:26:53 2021 +0100
Use new BigDecimal(double) and not BigDecimal.valueOf(double)
The constructor version creates the exact representation of the double.
---
.../src/test/java/org/apache/commons/numbers/core/SummationTest.java | 2 +-
.../commons/numbers/examples/jmh/core/EuclideanNormAlgorithms.java | 2 +-
.../commons/numbers/examples/jmh/core/EuclideanNormEvaluator.java | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/SummationTest.java b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/SummationTest.java
index af41c9b..fd67160 100644
--- a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/SummationTest.java
+++ b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/SummationTest.java
@@ -275,7 +275,7 @@ class SummationTest {
private static double computeExact(final double... values) {
BigDecimal sum = BigDecimal.ZERO;
for (double value : values) {
- sum = sum.add(BigDecimal.valueOf(value), MathContext.UNLIMITED);
+ sum = sum.add(new BigDecimal(value), MathContext.UNLIMITED);
}
return sum.doubleValue();
diff --git a/commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/core/EuclideanNormAlgorithms.java b/commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/core/EuclideanNormAlgorithms.java
index 703f096..ec8f689 100644
--- a/commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/core/EuclideanNormAlgorithms.java
+++ b/commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/core/EuclideanNormAlgorithms.java
@@ -40,7 +40,7 @@ public final class EuclideanNormAlgorithms {
BigDecimal sum = BigDecimal.ZERO;
BigDecimal n;
for (int i = 0; i < v.length; ++i) {
- n = BigDecimal.valueOf(Double.isFinite(v[i]) ? v[i] : 0d);
+ n = Double.isFinite(v[i]) ? new BigDecimal(v[i]) : BigDecimal.ZERO;
sum = sum.add(n.multiply(n, ctx), ctx);
}
diff --git a/commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/core/EuclideanNormEvaluator.java b/commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/core/EuclideanNormEvaluator.java
index 77227b9..06b0153 100644
--- a/commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/core/EuclideanNormEvaluator.java
+++ b/commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/core/EuclideanNormEvaluator.java
@@ -96,7 +96,7 @@ public class EuclideanNormEvaluator {
BigDecimal sum = BigDecimal.ZERO;
for (final double v : vec) {
- sum = sum.add(BigDecimal.valueOf(v).pow(2), ctx);
+ sum = sum.add(new BigDecimal(v).pow(2), ctx);
}
return sum.sqrt(ctx).doubleValue();