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
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;
}

View File

@ -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);

View File

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