/** * Be cautious with this method, no new internal rational is created * * @param numerator * @return */ protected static Num newInstance(final double value) { Num d; // if (Config.SERVER_MODE) { // d = FACTORY.object(); // } else { d = new Num(0.0); // } d.fDouble = value; return d; }
@Override public IExpr plus(final IExpr that) { if (that instanceof Num) { return add((Num) that); } return super.plus(that); }
@Override public double reDoubleValue() { return doubleValue(); }
@Override public IExpr numericEvalD1(final Num arg1) { try { return Num.valueOf(org.apache.commons.math3.special.Erf.erf(arg1.getRealPart())); } catch (final MaxCountExceededException e) { } return null; }
@Override public ISignedNumber divideBy(ISignedNumber that) { return Num.valueOf(doubleValue() / that.doubleValue()); }
/** {@inheritDoc} */ @Override public IExpr dec() { return valueOf(fDouble - 1.0); }
/** {@inheritDoc} */ @Override public ISignedNumber fractionalPart() { return F.num(getRealPart() % 1); }
@Override public IExpr plus(final IExpr that) { if (that instanceof ApfloatNum) { return add(ApfloatNum.valueOf(fDouble, ((ApfloatNum) that).fApfloat.precision())); } if (that instanceof Num) { return valueOf(fDouble + ((Num) that).fDouble); } if (that instanceof ApcomplexNum) { return ApcomplexNum.valueOf(fDouble, ((ApcomplexNum) that).fApcomplex.precision()).add((ApcomplexNum) that); } if (that instanceof ComplexNum) { return ComplexNum.valueOf(fDouble).add((ComplexNum) that); } return INum.super.plus(that); }
@Override public IExpr times(final IExpr that) { if (that instanceof ApfloatNum) { return multiply(ApfloatNum.valueOf(fDouble, ((ApfloatNum) that).fApfloat.precision())); } if (that instanceof Num) { return valueOf(fDouble * ((Num) that).fDouble); } if (that instanceof ApcomplexNum) { return ApcomplexNum.valueOf(fDouble, ((ApcomplexNum) that).fApcomplex.precision()) .multiply((ApcomplexNum) that); } if (that instanceof ComplexNum) { return ComplexNum.valueOf(fDouble).multiply((ComplexNum) that); } return INum.super.times(that); }
/** {@inheritDoc} */ @Override public int complexSign() { return sign(); }
@Override public String internalFormString(boolean symbolsAsFactoryMethod, int depth) { return internalJavaString(symbolsAsFactoryMethod, depth, false, false, false); }
/** * Compares this expression with the specified expression for order. Returns a * negative integer, zero, or a positive integer as this expression is * canonical less than, equal to, or greater than the specified expression. */ public int compareTo(final IExpr obj) { if (obj instanceof Num) { return Double.compare(fDouble, ((Num) obj).fDouble); } return (hierarchy() - (obj).hierarchy()); }
@Override public ApcomplexNum apcomplexNumValue(long precision) { return ApcomplexNum.valueOf(apcomplexValue(precision)); }
/** * @return */ @Override public ISignedNumber opposite() { return valueOf(-fDouble); }
@Override public IExpr numericEvalD1(final Num arg1) { final double d = arg1.getRealPart(); if (d < 0) { return F.num(Math.PI); } else if (d > 0) { return F.CD0; } return null; }
@Override public ISignedNumber subtractFrom(ISignedNumber that) { return valueOf(doubleValue() - that.doubleValue()); }
public int complexSign() { return sign(); }
@Override public String internalScalaString(boolean symbolsAsFactoryMethod, int depth) { return internalJavaString(symbolsAsFactoryMethod, depth, true, false, false); }
/** * Create a numeric value * * @param d * @return */ public static Num num(final double d) { return Num.valueOf(d); }