Use primitive types in number formatting

This commit is contained in:
serso 2016-04-16 21:09:47 +02:00
parent f7e2229687
commit 9e9e856c24
3 changed files with 13 additions and 10 deletions

View File

@ -143,16 +143,16 @@ public class JsclMathEngine implements MathEngine {
} }
@Nonnull @Nonnull
public String format(@Nonnull Double value) throws NumeralBaseException { public String format(double value) throws NumeralBaseException {
return format(value, numeralBase); return format(value, numeralBase);
} }
@Nonnull @Nonnull
public String format(@Nonnull Double value, @Nonnull NumeralBase nb) throws NumeralBaseException { public String format(double value, @Nonnull NumeralBase nb) throws NumeralBaseException {
if (value.isInfinite()) { if (Double.isInfinite(value)) {
return formatInfinity(value); return formatInfinity(value);
} }
if (value.isNaN()) { if (Double.isNaN(value)) {
// return "NaN" // return "NaN"
return String.valueOf(value); return String.valueOf(value);
} }
@ -184,14 +184,17 @@ public class JsclMathEngine implements MathEngine {
} }
@Nullable @Nullable
private IConstant findConstant(@Nonnull Double value) { private IConstant findConstant(double value) {
final IConstant constant = findConstant(constantsRegistry.getSystemEntities(), value); final IConstant constant = findConstant(constantsRegistry.getSystemEntities(), value);
if (constant != null) { if (constant != null) {
return constant; return constant;
} }
final IConstant piInv = constantsRegistry.get(Constants.PI_INV.getName()); final IConstant piInv = constantsRegistry.get(Constants.PI_INV.getName());
if (piInv != null && value.equals(piInv.getDoubleValue())) { if (piInv != null) {
return piInv; final Double piInvValue = piInv.getDoubleValue();
if (piInvValue != null && piInvValue == value) {
return piInv;
}
} }
return null; return null;
} }

View File

@ -44,10 +44,10 @@ public interface MathContext {
void setGroupingSeparator(char groupingSeparator); void setGroupingSeparator(char groupingSeparator);
@Nonnull @Nonnull
String format(@Nonnull Double value) throws NumeralBaseException; String format(double value) throws NumeralBaseException;
@Nonnull @Nonnull
String format(@Nonnull Double value, @Nonnull NumeralBase nb) throws NumeralBaseException; String format(double value, @Nonnull NumeralBase nb) throws NumeralBaseException;
@Nonnull @Nonnull
String addGroupingSeparators(@Nonnull NumeralBase nb, @Nonnull String ungroupedIntValue); String addGroupingSeparators(@Nonnull NumeralBase nb, @Nonnull String ungroupedIntValue);

View File

@ -324,7 +324,7 @@ public abstract class Numeric implements Arithmetic<Numeric>, INumeric<Numeric>,
@Nonnull @Nonnull
protected String toString(final double value) { protected String toString(final double value) {
return JsclMathEngine.getInstance().format(value, JsclMathEngine.getInstance().getNumeralBase()); return JsclMathEngine.getInstance().format(value);
} }
public BigInteger toBigInteger() { public BigInteger toBigInteger() {