Package org.nfunk.jep.function
Class Comparative
java.lang.Object
org.nfunk.jep.function.PostfixMathCommand
org.nfunk.jep.function.Comparative
- All Implemented Interfaces:
PostfixMathCommandI
- Direct Known Subclasses:
ElementComparative
Implements the comparative operations <, >, ≤, ≥, != and ==.
Caverts should work where arguments are Double, Complex or String
for the last two only != and == work.
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
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
protected int
static final int
static final int
static final int
Fields inherited from class org.nfunk.jep.function.PostfixMathCommand
curNumberOfParameters, numberOfParameters
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
double
Returns the tolerance used for comparing complex numbersboolean
boolean
boolean
boolean
void
Throws an exception because this method should never be called under normal circumstances.void
setTolerance
(double d) Sets the tolerance used for comparing complex numbersMethods inherited from class org.nfunk.jep.function.PostfixMathCommand
checkNumberOfParameters, checkStack, getNumberOfParameters, setCurNumberOfParameters
-
Field Details
-
id
protected int id -
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.
-
-
Method Details
-
run
Description copied from class:PostfixMathCommand
Throws an exception because this method should never be called under normal circumstances. Each function should use it's own run() method for evaluating the function. This includes popping off the parameters from the stack, and pushing the result back on the stack.- Specified by:
run
in interfacePostfixMathCommandI
- Overrides:
run
in classPostfixMathCommand
- Throws:
ParseException
-
lt
- Throws:
ParseException
-
gt
- Throws:
ParseException
-
le
- Throws:
ParseException
-
ge
- Throws:
ParseException
-
eq
- Throws:
ParseException
-
ne
- Throws:
ParseException
-
getTolerance
public double getTolerance()Returns the tolerance used for comparing complex numbers -
setTolerance
public void setTolerance(double d) Sets the tolerance used for comparing complex numbers- Parameters:
d
-
-