public class Num extends ExprImpl implements INum
INum implementation which wraps a double value to
represent a numeric floating-point number.Catalan, Degree, EulerGamma, Glaisher, GoldenRatio, KhinchinASTID, BLANKID, COMPLEXID, DOUBLECOMPLEXID, DOUBLEID, FRACTIONID, INTEGERID, METHODSYMBOLID, PATTERNID, STRINGID, SYMBOLID| Modifier and Type | Method and Description |
|---|---|
<T> T |
accept(IVisitor<T> visitor)
Accept a visitor with return type T
|
boolean |
accept(IVisitorBoolean visitor)
Accept a visitor with return type
boolean |
int |
accept(IVisitorInt visitor)
Accept a visitor with return type
int |
long |
accept(IVisitorLong visitor)
Accept a visitor with return type
long |
INum |
add(INum val) |
ApcomplexNum |
apcomplexNumValue(long precision)
Get a
Apcomplex number wrapped into an
ApcomplexNum object. |
org.apfloat.Apcomplex |
apcomplexValue(long precision) |
ApfloatNum |
apfloatNumValue(long precision)
Get a
Apfloat number wrapped into an ApfloatNum object. |
IInteger |
ceilFraction()
Returns the smallest (closest to negative infinity)
IInteger
value that is not less than this and is equal to a
mathematical integer. |
int |
compareAbsValueToOne()
Compare the absolute value of this number with
1 and return
1, if the absolute value is greater than 1
0, if the absolute value equals 1
-1, if the absolute value is less than 1
|
int |
compareTo(double that) |
int |
compareTo(IExpr expr)
Compares this expression with the specified expression for order.
|
ComplexNum |
complexNumValue()
Get a
ComplexNum number bject. |
int |
complexSign()
Gets the signum value of a complex number
|
double |
divide(double that) |
ISignedNumber |
divideBy(ISignedNumber that)
Divide
this signed number by that signed number. |
double |
doubleValue() |
Num |
eabs()
Get the absolute value for a given number
|
boolean |
equals(java.lang.Object arg0)
Test if this is equal to b.
|
boolean |
equalsInt(int i)
Check if this number equals the given
int number? |
IExpr |
evaluate(EvalEngine engine)
Evaluate an expression
|
double |
exp() |
IInteger |
floorFraction()
Returns the largest (closest to positive infinity)
IInteger
value that is not greater than this and is equal to a
mathematical integer. |
ISignedNumber |
getIm()
Returns the imaginary part of a complex number
|
double |
getImaginary()
Returns the imaginary part of a complex number
|
ISignedNumber |
getRe()
Returns the real part of a complex number
|
double |
getReal()
Returns the real part of a complex number
|
double |
getRealPart() |
int |
hashCode()
Hashcode of this Element.
|
ISymbol |
head()
If this object is an instance of
IAST get the first element
(offset 0) of the IAST list (i.e. get(0) ). |
int |
hierarchy()
A unique integer ID for the implementation of this expression
|
java.lang.String |
internalFormString(boolean symbolsAsFactoryMethod,
int depth)
Return the internal Java form of this expression.
|
java.lang.String |
internalJavaString(boolean symbolsAsFactoryMethod,
int depth,
boolean useOperators)
Return the internal Java form of this expression.
|
java.lang.String |
internalScalaString(boolean symbolsAsFactoryMethod,
int depth)
Return the internal Scala form of this expression.
|
int |
intValue()
Returns the value of this number as an
int (by simply casting to type int). |
ISignedNumber |
inverse()
Returns the multiplicative inverse of this object.
|
boolean |
isE()
Test if this expression equals
E (base of the natural
logarithm; approximately equal to 2.71828...) in symbolic or numeric
mode. |
boolean |
isGreaterThan(ISignedNumber that)
Test if
this signed number is greater than that signed number.. |
boolean |
isInfinite() |
boolean |
isLessThan(ISignedNumber that)
Test if
this signed number is less than that signed number.. |
boolean |
isMinusOne()
Test if this expression equals
-1 in symbolic or numeric
mode. |
boolean |
isNaN() |
boolean |
isNegative()
Test if this number is negative.
|
boolean |
isNumEqualInteger(IInteger value)
Check if this expression equals an
IInteger value. |
boolean |
isNumEqualRational(IRational value)
Check if this expression equals an
IRational value. |
boolean |
isNumIntValue()
Check if this expression represents an
int value. |
boolean |
isOne()
Test if this expression equals
1 in symbolic or numeric
mode. |
boolean |
isPi()
Test if this expression equals
Pi (the ratio of a circle's
circumference to its diameter, approx. 3.141592...) in symbolic or
numeric mode. |
boolean |
isPositive()
Test if this number is positive.
|
boolean |
isRationalValue(IRational value)
Test if this expression equals
value in symbolic or numeric
mode. |
boolean |
isSame(IExpr expression,
double epsilon)
Test if this expression equals the given expression.
|
boolean |
isZero()
Test if this expression equals
0 in symbolic or numeric
mode. |
double |
log() |
long |
longValue() |
double |
minus(double that) |
INum |
multiply(INum val) |
ISignedNumber |
negate()
Negate this.
|
protected static Num |
newInstance(double value)
Be cautious with this method, no new internal rational is created
|
Num |
numValue()
Get a Java double number wrapped into a
Num object. |
ISignedNumber |
opposite()
Returns an
IExpr whose value is (-1) * this. |
double |
plus(double that) |
IExpr |
plus(IExpr that)
Returns an
IExpr whose value is (this + that). |
double |
pow(double that) |
double |
pow(int exp) |
INum |
pow(INum val) |
IInteger |
round()
Returns the closest
IInteger to the argument. |
int |
sign()
Returns the signum function of this number (i.e., -1, 0 or 1 as the value of this number is negative, zero or positive).
|
double |
sqrt() |
ISignedNumber |
subtractFrom(ISignedNumber that)
Subtract
that signed number from this signed number |
double |
times(double that) |
IExpr |
times(IExpr that)
Returns an
IExpr whose value is (this * that). |
int |
toInt()
Converts this double value to an
int value; unlike INum.intValue() this method raises
ArithmeticException if this integer cannot be represented by an int type. |
long |
toLong()
Converts this number to
long; unlike #longValue this method raises ArithmeticException if this
number cannot be represented by an long type. |
java.lang.String |
toString() |
static Num |
valueOf(double doubleValue) |
static double |
valueOf(java.lang.String chars) |
$div, $minus, $plus, $times, $up, abs, and, apply, apply, asType, conjugate, copy, dec, divide, egcd, evalComplex, evalDouble, evalNumber, evalSignedNumber, factory, fullFormString, gcd, getAt, inc, leafCount, leaves, minus, mod, multiply, negative, optional, or, power, power, remainder, replaceAll, replaceAll, replacePart, replaceRepeated, replaceRepeated, replaceRepeated, replaceSlots, signum, subtract, sum, topHead, toScript, toScriptFactory, variables2Slotsclone, finalize, getClass, notify, notifyAll, wait, wait, wait$div, $minus, $plus, $times, $up, and, apply, apply, asType, dec, divide, evalComplex, evalDouble, evalNumber, evalSignedNumber, evaluateHead, fullFormString, getAt, getField, ifPresent, inc, isAllExpanded, isAnd, isArcCos, isArcCosh, isArcSin, isArcSinh, isArcTan, isArcTanh, isAST, isAST, isAST, isAST, isAST, isAST, isAST, isASTSizeGE, isAtom, isBlank, isComplex, isComplexInfinity, isComplexNumeric, isCondition, isConstant, isCos, isCosh, isDerivative, isDirectedInfinity, isExpanded, isFalse, isFlatAST, isFraction, isFree, isFree, isFree, isFreeAST, isFreeAST, isFreeOfPatterns, isFunction, isGEOrdered, isGTOrdered, isIndeterminate, isInfinity, isInteger, isIntegerResult, isLEOrdered, isList, isListOfLists, isLog, isLTOrdered, isMatrix, isMember, isMember, isModule, isNegativeInfinity, isNegativeResult, isNonNegativeResult, isNot, isNumber, isNumeric, isNumericFunction, isNumericMode, isONE, isOr, isOrderlessAST, isPattern, isPatternDefault, isPatternExpr, isPatternSequence, isPlus, isPlusTimesPower, isPolynomial, isPolynomial, isPolynomialOfMaxDegree, isPositiveResult, isPower, isPresent, isRational, isRationalResult, isRealResult, isRuleAST, isSame, isSequence, isSignedNumber, isSin, isSinh, isSlot, isSlotSequence, isSpan, isSymbol, isTan, isTanh, isTimes, isTrue, isUnit, isValue, isVariable, isVector, isZERO, leafCount, leaves, minus, mod, multiply, multiply, negative, ofNullable, optional, or, orElse, orElseGet, orElseThrow, power, power, reciprocal, replaceAll, replaceAll, replacePart, replaceRepeated, replaceRepeated, replaceSlots, signum, subtract, sum, timesDistributed, topHead, variables2Slotsprotected static Num newInstance(double value)
numerator - public int hierarchy()
IExprpublic boolean isNumEqualInteger(IInteger value) throws java.lang.ArithmeticException
IInteger value. The value
of an INum or the value of an IInteger object
can be equal to value.isNumEqualInteger in interface IExprjava.lang.ArithmeticExceptionpublic boolean isNumEqualRational(IRational value) throws java.lang.ArithmeticException
IRational value. The
value of an IInteger, IFraction or the value of
an INum object can be equal to value.isNumEqualRational in interface IExprjava.lang.ArithmeticExceptionIExpr.isRational()public boolean isNumIntValue()
int value. The value
of an INum object can be an int value.isNumIntValue in interface IExprisNumIntValue in interface INumpublic boolean isNegative()
isNegative in interface IExprisNegative in interface ISignedNumbertrue, if this < 0public boolean isPositive()
isPositive in interface IExprisPositive in interface ISignedNumbertrue, if this > 0public boolean isRationalValue(IRational value)
value in symbolic or numeric
mode.isRationalValue in interface IExprpublic boolean equalsInt(int i)
INumberint number?public IExpr evaluate(EvalEngine engine)
IExprpublic static double valueOf(java.lang.String chars)
chars - public static Num valueOf(double doubleValue)
doubleValue - public Num eabs()
public int compareAbsValueToOne()
1 and return
1, if the absolute value is greater than 10, if the absolute value equals 1-1, if the absolute value is less than 1compareAbsValueToOne in interface INumberpublic double plus(double that)
that - public IExpr plus(IExpr that)
ExprImplIExpr whose value is (this + that).
Calculates F.eval(F.Plus(this, that)) in the common case and
uses a specialized implementation for derived number classes.public ISignedNumber divideBy(ISignedNumber that)
ISignedNumberthis signed number by that signed number.divideBy in interface ISignedNumberthat - a signed numberpublic ISignedNumber subtractFrom(ISignedNumber that)
ISignedNumberthat signed number from this signed numbersubtractFrom in interface ISignedNumberthat - a signed numberpublic int compareTo(double that)
that - public double divide(double that)
that - public double doubleValue()
doubleValue in interface ISignedNumberpublic boolean equals(java.lang.Object arg0)
edu.jas.structure.Elementequals in interface edu.jas.structure.Element<IExpr>equals in class java.lang.Objectpublic boolean isSame(IExpr expression, double epsilon)
IExprpublic double exp()
public final int hashCode()
edu.jas.structure.ElementhashCode in interface edu.jas.structure.Element<IExpr>hashCode in class java.lang.Objectpublic int intValue()
INumint (by simply casting to type int).public int toInt()
throws java.lang.ArithmeticException
int value; unlike INum.intValue() this method raises
ArithmeticException if this integer cannot be represented by an int type.toInt in interface INumtoInt in interface ISignedNumberint.java.lang.ArithmeticException - if conversion to int is not possible.public long toLong()
throws java.lang.ArithmeticException
long; unlike #longValue this method raises ArithmeticException if this
number cannot be represented by an long type.toLong in interface ISignedNumberlong.java.lang.ArithmeticException - if conversion to int is not possible.public boolean isInfinite()
public boolean isNaN()
public double log()
public long longValue()
public double times(double that)
that - public IExpr times(IExpr that)
ExprImplIExpr whose value is (this * that).
Calculates F.eval(F.Times(this, that)) in the common case
and uses a specialized implementation for derived number classes.public ISignedNumber negate()
ExprImplpublic ISignedNumber opposite()
ExprImplIExpr whose value is (-1) * this.
Calculates F.eval(F.Times(F.CN1, this)) in the common case
and uses a specialized implementation for derived number classes.opposite in interface IExpropposite in interface INumberopposite in interface ISignedNumberopposite in class ExprImplIExpr.negative()public double pow(double that)
that - public double pow(int exp)
exp - public ISignedNumber inverse()
ExprImplthis.times(this.inverse()) == ONE , with ONE
being the multiplicative identity. Calculates
F.eval(F.Power(this, F.CN1)) in the common case and uses a
specialized implmentation for derived number classes.public double sqrt()
public double minus(double that)
that - public double getRealPart()
getRealPart in interface INumpublic boolean isE()
E (base of the natural
logarithm; approximately equal to 2.71828...) in symbolic or numeric
mode.
public boolean isOne()
1 in symbolic or numeric
mode.public boolean isMinusOne()
-1 in symbolic or numeric
mode.isMinusOne in interface IExprpublic boolean isPi()
Pi (the ratio of a circle's
circumference to its diameter, approx. 3.141592...) in symbolic or
numeric mode.
public boolean isZero()
0 in symbolic or numeric
mode.isZero in interface IExprisZero in interface ISignedNumberpublic IInteger round()
ISignedNumberIInteger to the argument. The result is rounded to an integer by adding 1/2 and taking the
floor of the result.ArithmeticException if a numeric value cannot be represented by an long type.round in interface ISignedNumberpublic int sign()
ISignedNumbersign in interface ISignedNumberpublic int complexSign()
complexSign in interface INumberthis == 0; +1 for
real(this) > 0 or
( real(this)==0 && imaginary(this) > 0 );
-1 for real(this) < 0 || ( real(this) == 0 &&
imaginary(this) < 0 )public IInteger ceilFraction()
IInteger
value that is not less than this and is equal to a
mathematical integer. This method raises ArithmeticException if a
numeric value cannot be represented by an long type.ceilFraction in interface INumberIInteger
value that is not less than this and is equal to a
mathematical integer.public IInteger floorFraction()
IInteger
value that is not greater than this and is equal to a
mathematical integer. ArithmeticException if a numeric value cannot
be represented by an long type.floorFraction in interface INumberIInteger
value that is not greater than this and is equal to
a mathematical integer.public int compareTo(IExpr expr)
public boolean isLessThan(ISignedNumber that)
ISignedNumberthis signed number is less than that signed number..isLessThan in interface ISignedNumberthis < thatpublic boolean isGreaterThan(ISignedNumber that)
ISignedNumberthis signed number is greater than that signed number..isGreaterThan in interface ISignedNumberthis > thatpublic ISymbol head()
ExprImplIAST get the first element
(offset 0) of the IAST list (i.e. get(0) ).public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String internalFormString(boolean symbolsAsFactoryMethod,
int depth)
ExprImplinternalFormString in interface IExprinternalFormString in class ExprImplsymbolsAsFactoryMethod - if true use the F.symbol() method,
otherwise print the symbol name.depth - the recursion depth of this call. 0 indicates
"recurse without a limit".public java.lang.String internalScalaString(boolean symbolsAsFactoryMethod,
int depth)
ExprImplinternalScalaString in interface IExprinternalScalaString in class ExprImplsymbolsAsFactoryMethod - if true use the F.symbol() method,
otherwise print the symbol name.depth - the recursion depth of this call. 0 indicates
"recurse without a limit".public java.lang.String internalJavaString(boolean symbolsAsFactoryMethod,
int depth,
boolean useOperators)
ExprImplinternalJavaString in interface IExprinternalJavaString in class ExprImplsymbolsAsFactoryMethod - if true use the F.symbol() method,
otherwise print the symbol name.depth - the recursion depth of this call. 0 indicates
"recurse without a limit".useOperators - use operators instead of function names for representation of
Plus, Times, Power,...public <T> T accept(IVisitor<T> visitor)
public boolean accept(IVisitorBoolean visitor)
booleanpublic int accept(IVisitorInt visitor)
intpublic long accept(IVisitorLong visitor)
longpublic ISignedNumber getIm()
public ISignedNumber getRe()
public ApfloatNum apfloatNumValue(long precision)
ISignedNumberApfloat number wrapped into an ApfloatNum object.apfloatNumValue in interface ISignedNumberprecision - set the precision of the resulting ApfloatNumpublic Num numValue()
ISignedNumberNum object.numValue in interface ISignedNumberpublic org.apfloat.Apcomplex apcomplexValue(long precision)
public ApcomplexNum apcomplexNumValue(long precision)
INumberApcomplex number wrapped into an
ApcomplexNum object.apcomplexNumValue in interface INumberprecision - set the precision of the resulting ApcomplexNumpublic ComplexNum complexNumValue()
INumberComplexNum number bject.complexNumValue in interface INumberpublic double getImaginary()
INumbergetImaginary in interface INumber