Extra Functions and Operators » History » Revision 1
Revision 1/11
| Next »
Federico Vera, 2018-06-10 00:01
Extra Functions and Operators¶
There are a number of extra functions and operators included in this version of exp4j, non of this are enabled by default, they are in the net.objecthunter.exp4j.extras package.
Comparison Operators¶
Aside from the arithmetic operators several comparison operators are included:
<, <=, >, >=, != and ==. Please note that since exp4j itself has
no concept of boolean, the results given by all of the comparison operators
will be 1.0 if true and 0.0 if false. Let it be noted that due to
rounding, equality operators use a radix in which they consider numbers to be
"equal", that is:
Let a and b be two real numbers, a == b will evaluate to true if and
only if the distance between a and b (dist(a, b) := abs(a - b)) is less or
equal than 1e-12 (0.000000000001) and false otherwise.
Precedence¶
Operator precedence is altered when using the comparison operators, the new precedence is:
FIRST-> * / % - + > >= < <= ¬ & | == != <-LAST
----- --- --------- - - - -----
^^^ The dashes indicate groups with the same precedence
Boolean Functions¶
Even though we have boolean operators, there are also a number of boolean functions that can be used (some people prefer functions)
-
and(a, b): Logical and equivalent toa & b -
or(a, b): Logical or equivalent toa | b -
xor(a, b): Exclusive or -
nand(a, b): equivalent to¬(a & b) -
nor(a, b): equivalent to¬(a | b) -
xnor(a, b): Negated exclusive or -
not(a): equivalent to¬a
Boolean Constants¶
-
true(): true value1.0(true is actually any value different than zero, but this is the value returned by comparison operators, boolean operators and boolean functions. -
false(): false value0.0
Extra Functions¶
-
if(e, v_true, v_false): Branches the formula, it will be evaluated asv_trueife == true()andv_falseife == false() -
equals(a, b): Equivalent toa == b, so the same conditions apply. -
sinc(x): Cardinal sine ofx(not normalized), equivalent tosin(x)/x
Code¶
Updated by Federico Vera over 7 years ago · 11 revisions