Package net.objecthunter.exp4j.extras
Class OperatorsComparison
- java.lang.Object
-
- net.objecthunter.exp4j.extras.OperatorsComparison
-
public final class OperatorsComparison extends java.lang.Object
This class contains the implementation of comparison and equality operators.The returned values will always be 1.0 for
The precedence of this operators is as follows:true
and 0.0 forfalse
.- All comparison operators have the same precedence
- Comparison operators have higher precedence than boolean operators
- Comparison operators have lower precedence than arithmetic operators
- Equality operators have the lowest precedence (they should always be the last ones to be evaluated)
- Equality operators will consider numbers closer than
EQUALITY_THRESHOLD
to be equal (and viceversa)
To clarify the full evaluation order is: FIRST-> * / % - + > >= < <= ¬ & | == != <-LAST ----- --- --------- - - - ----- ^^^ The dashes indicate the ones with the same precedence So: a + b * c > d / e & f < g == (((a + (b * c)) > (d / e)) & (f < g))
WARNING: Concatenating comparison operators should be avoided! This is a brutal and very common error. Imagine the following equation:
a < b < c
, now let's seta = 1
,b = 3
andc = 2
so it will roughly translate to1 < 3 < 2
. Those of you not familiarized with operator precedence evaluation might think that this will result infalse
but it will actually returntrue
. Why?Well:
a < b < c -> ((a < b) < c)
So the example will become:
1 < 3 < 2 -> ((1 < 3) < 2) -> ((1) < 2) -> 1
So the morality of this tale is: if unsure, DON'T CONCATENATE OPERATORS
-
-
Field Summary
Fields Modifier and Type Field Description static double
EQUALITY_THRESHOLD
This is the threshold used to consider values equal, that is, if two valuesa
andb
are separated by less than this threshold they will be considered to be equal, it has a default value of 1.0E-12static Operator
OP_EQU
Operator Equality=
.static Operator
OP_GOE
Operator Greater Or Equal Than>=
.static Operator
OP_GT
Operator Greater Than>
.static Operator
OP_LOE
Operator Less Or Equal Than<=
.static Operator
OP_LT
Operator Less Than<
.static Operator
OP_NEQ
Operator Inequality!=
.static int
PRECEDENCE_COMPARISON
Precedence for the comparison operators (Value 450).static int
PRECEDENCE_EQUAL
Precedence for the equality operators (Value 50).
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Operator
getOperator(java.lang.String symbol)
Retrieves an operator by it's symbol.static Operator[]
getOperators()
Retrieves all the available operators.
-
-
-
Field Detail
-
PRECEDENCE_COMPARISON
public static final int PRECEDENCE_COMPARISON
Precedence for the comparison operators (Value 450).- See Also:
OP_GOE
,OP_GT
,OP_LOE
,OP_LT
, Constant Field Values
-
PRECEDENCE_EQUAL
public static final int PRECEDENCE_EQUAL
Precedence for the equality operators (Value 50).- See Also:
OP_EQU
,OP_NEQ
, Constant Field Values
-
OP_GT
public static final Operator OP_GT
Operator Greater Than>
.- Since:
- 0.6-riddler
-
OP_GOE
public static final Operator OP_GOE
Operator Greater Or Equal Than>=
.- Since:
- 0.6-riddler
-
OP_LT
public static final Operator OP_LT
Operator Less Than<
.- Since:
- 0.6-riddler
-
OP_LOE
public static final Operator OP_LOE
Operator Less Or Equal Than<=
.- Since:
- 0.6-riddler
-
OP_EQU
public static final Operator OP_EQU
Operator Equality=
.- Since:
- 0.6-riddler
-
OP_NEQ
public static final Operator OP_NEQ
Operator Inequality!=
.- Since:
- 0.6-riddler
-
EQUALITY_THRESHOLD
public static final double EQUALITY_THRESHOLD
This is the threshold used to consider values equal, that is, if two valuesa
andb
are separated by less than this threshold they will be considered to be equal, it has a default value of 1.0E-12- See Also:
- Constant Field Values
-
-