From 9e9e856c24b5643110bd46bd9969fa95e392362a Mon Sep 17 00:00:00 2001 From: serso Date: Sat, 16 Apr 2016 21:09:47 +0200 Subject: [PATCH] Use primitive types in number formatting --- jscl/src/main/java/jscl/JsclMathEngine.java | 17 ++++++++++------- jscl/src/main/java/jscl/MathContext.java | 4 ++-- .../main/java/jscl/math/numeric/Numeric.java | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/jscl/src/main/java/jscl/JsclMathEngine.java b/jscl/src/main/java/jscl/JsclMathEngine.java index 8a59b2fe..5b7ddee5 100644 --- a/jscl/src/main/java/jscl/JsclMathEngine.java +++ b/jscl/src/main/java/jscl/JsclMathEngine.java @@ -143,16 +143,16 @@ public class JsclMathEngine implements MathEngine { } @Nonnull - public String format(@Nonnull Double value) throws NumeralBaseException { + public String format(double value) throws NumeralBaseException { return format(value, numeralBase); } @Nonnull - public String format(@Nonnull Double value, @Nonnull NumeralBase nb) throws NumeralBaseException { - if (value.isInfinite()) { + public String format(double value, @Nonnull NumeralBase nb) throws NumeralBaseException { + if (Double.isInfinite(value)) { return formatInfinity(value); } - if (value.isNaN()) { + if (Double.isNaN(value)) { // return "NaN" return String.valueOf(value); } @@ -184,14 +184,17 @@ public class JsclMathEngine implements MathEngine { } @Nullable - private IConstant findConstant(@Nonnull Double value) { + private IConstant findConstant(double value) { final IConstant constant = findConstant(constantsRegistry.getSystemEntities(), value); if (constant != null) { return constant; } final IConstant piInv = constantsRegistry.get(Constants.PI_INV.getName()); - if (piInv != null && value.equals(piInv.getDoubleValue())) { - return piInv; + if (piInv != null) { + final Double piInvValue = piInv.getDoubleValue(); + if (piInvValue != null && piInvValue == value) { + return piInv; + } } return null; } diff --git a/jscl/src/main/java/jscl/MathContext.java b/jscl/src/main/java/jscl/MathContext.java index 30400a29..45d9e330 100644 --- a/jscl/src/main/java/jscl/MathContext.java +++ b/jscl/src/main/java/jscl/MathContext.java @@ -44,10 +44,10 @@ public interface MathContext { void setGroupingSeparator(char groupingSeparator); @Nonnull - String format(@Nonnull Double value) throws NumeralBaseException; + String format(double value) throws NumeralBaseException; @Nonnull - String format(@Nonnull Double value, @Nonnull NumeralBase nb) throws NumeralBaseException; + String format(double value, @Nonnull NumeralBase nb) throws NumeralBaseException; @Nonnull String addGroupingSeparators(@Nonnull NumeralBase nb, @Nonnull String ungroupedIntValue); diff --git a/jscl/src/main/java/jscl/math/numeric/Numeric.java b/jscl/src/main/java/jscl/math/numeric/Numeric.java index e30d75af..3ef0a3c1 100644 --- a/jscl/src/main/java/jscl/math/numeric/Numeric.java +++ b/jscl/src/main/java/jscl/math/numeric/Numeric.java @@ -324,7 +324,7 @@ public abstract class Numeric implements Arithmetic, INumeric, @Nonnull protected String toString(final double value) { - return JsclMathEngine.getInstance().format(value, JsclMathEngine.getInstance().getNumeralBase()); + return JsclMathEngine.getInstance().format(value); } public BigInteger toBigInteger() {