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));, Jep 4.1
List<Object>are compared for equality and inequality by comparing their elements pairwise, so vectors with positive zero and negative zero are considered equal, - Author:
- N Funk and R Morris
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.singularsys.jep.functions.BinaryFunction
BinaryFunction.BiFunctionWithException<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intFields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, description, name, NaN, numberOfParameters -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanCompares the two arguments.booleanEvaluate the functionbooleanReturn a description of the function from the properties file.intgetId()Return the ID of the comparative operatordoubleReturns the tolerance used for comparing complex numbersbooleanbooleanbooleanbooleanvoidsetTolerance(double d) Sets the tolerance used for comparing complex numbersMethods inherited from class com.singularsys.jep.functions.BinaryFunction
instanceOf, instanceOf, instanceOf, instanceOf, runMethods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, asType, checkNumberOfParameters, getDescription, getDescriptionWithType, getName, getNumberOfParameters, setCurNumberOfParameters, setDescription, 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
Description copied from class:BinaryFunctionEvaluate the function- Specified by:
evalin classBinaryFunction- Parameters:
l- lhs argumentr- rhs argument- Returns:
- the results
- Throws:
EvaluationException- if the function cannot be evaluated.
-
compare
Compares the two arguments. Result depend on which comparative option has been selected.- Parameters:
param1-param2-- Returns:
- 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
-
getDescription
Description copied from class:PostfixMathCommandReturn a description of the function from the properties file. The property name is the class name followed by ".description". The property is found using theJepMessagesclass, which can be configured to add additional properties files. IfPostfixMathCommand.setDescription(String)has been called, return the description set by that method instead.- Specified by:
getDescriptionin interfacePostfixMathCommandI- Overrides:
getDescriptionin classPostfixMathCommand- Returns:
- the description of the function
-