Package com.singularsys.jep.functions
Class Comparative
java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.BinaryFunction
com.singularsys.jep.functions.Comparative
- All Implemented Interfaces:
PostfixMathCommandI
,Serializable
- Direct Known Subclasses:
BigDecRelational
,NullSafeEquals
Implements the comparative operations <, >, <=, >=, != and ==.
The <, >, <=, >= operators only work on Double type, while
the != and == operators also work on String and Vector arguments.
For other types, care might be needed.
Complex numbers are compared using a tolerance which can be set using setTolerance().
- Since:
- 2.3.0 beta 1 a bit of a rewrite to make sub classing easier, now allows Complex to be compared to Double i.e. 1+0 i == 1., 2.3.0 beta 2 changed the internal lt,gt,le,ge,ne and eq method to return boolean. If this breaks anything use if (lt(obj1,obj2)) inStack.push(Double.valueOf(1)); else inStack.push(Double.valueOf(0));
- Author:
- N Funk and R Morris
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, name, NaN, numberOfParameters
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
boolean
int
getId()
Return the ID of the comparative operatordouble
Returns the tolerance used for comparing complex numbersboolean
boolean
boolean
boolean
void
setTolerance
(double d) Sets the tolerance used for comparing complex numbersMethods inherited from class com.singularsys.jep.functions.BinaryFunction
instanceOf, instanceOf, run
Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, checkNumberOfParameters, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString, toString
-
Field Details
-
LT
public static final int LT- See Also:
-
GT
public static final int GT- See Also:
-
LE
public static final int LE- See Also:
-
GE
public static final int GE- See Also:
-
NE
public static final int NE- See Also:
-
EQ
public static final int EQ- See Also:
-
-
Constructor Details
-
Comparative
public Comparative(int id_in) Constructor. Sets the number of parameters to 2. Initializes the tolerance for comparing Complex values.- Parameters:
id_in
- The id of the comparative operator.
-
Comparative
public Comparative(int id, double tolerance) - Parameters:
id
- one of LT, GT, LE, GE, EQ, NEtolerance
- tolerance for comparing Complex values
-
-
Method Details
-
getId
public int getId()Return the ID of the comparative operator- Returns:
- the id code
- Since:
- 3.5
-
eval
- Specified by:
eval
in classBinaryFunction
- Throws:
EvaluationException
-
compare
- Throws:
EvaluationException
-
lt
- Throws:
EvaluationException
-
gt
- Throws:
EvaluationException
-
le
- Throws:
EvaluationException
-
ge
- Throws:
EvaluationException
-
eq
- Throws:
EvaluationException
-
ne
- Throws:
EvaluationException
-
getTolerance
public double getTolerance()Returns the tolerance used for comparing complex numbers- Returns:
- the tolerance
-
setTolerance
public void setTolerance(double d) Sets the tolerance used for comparing complex numbers- Parameters:
d
- the tolerance
-