Proyecto

General

Perfil

Extra Functions and Operators » Histórico » Versión 1

Federico Vera, 2018-06-10 00:01

1 1 Federico Vera
# Extra Functions and Operators
2
3
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`](https://gitlab.com/riddler_arg/exp4j/tree/master/src/main/java/net/objecthunter/exp4j/extras) package.
4
5
## Comparison Operators
6
Aside from the arithmetic operators several comparison operators are included:
7
`<`, `<=`, `>`, `>=`, `!=` and `==`. Please note that since `exp4j` itself has
8
no concept of `boolean`, the results given by all of the comparison operators
9
will be `1.0` if `true` and `0.0` if `false`. Let it be noted that due to
10
rounding, equality operators use a radix in which they consider numbers to be
11
"equal", that is:
12
13
Let `a` and `b` be two real numbers, `a == b` will evaluate to `true` if and
14
only if the distance between `a` and `b` (`dist(a, b) := abs(a - b)`) is less or
15
equal than [`1e-12` (`0.000000000001`)](https://gitlab.com/riddler_arg/exp4j/blob/master/src/main/java/net/objecthunter/exp4j/extras/FunctionsMisc.java#L38) and `false` otherwise.
16
17
### Precedence
18
Operator precedence is altered when using the comparison operators, the new precedence is:
19
~~~
20
FIRST->  * / %  - +  > >= < <=  ¬  &  |  == !=   <-LAST
21
         -----  ---  ---------  -  -  -  -----    
22
         ^^^ The dashes indicate groups with the same precedence
23
~~~
24
25
## Boolean Functions
26
Even though we have boolean operators, there are also a number of boolean functions that can be used (some people prefer functions)
27
* `and(a, b)`: Logical and _equivalent to `a & b`_
28
* `or(a, b)`: Logical or _equivalent to `a | b`_
29
* `xor(a, b)`: Exclusive or
30
* `nand(a, b)`: _equivalent to `¬(a & b)`_
31
* `nor(a, b)`: _equivalent to `¬(a | b)`_
32
* `xnor(a, b)`: Negated exclusive or 
33
* `not(a)`: _equivalent to `¬a`_
34
35
## Boolean Constants
36
* `true()`: true value `1.0` (true is actually any value different than zero, but this is the value returned by comparison operators, boolean operators and boolean functions.
37
* `false()`: false value `0.0`
38
39
## Extra Functions
40
* `if(e, v_true, v_false)`: Branches the formula, it will be evaluated as `v_true` if `e == true()` and `v_false`  if `e == false()` 
41
* `equals(a, b)`: Equivalent to `a == b`, so the same conditions apply.
42
* `sinc(x)`: [Cardinal sine of `x`](https://en.wikipedia.org/wiki/Sinc_function) (not normalized), equivalent to `sin(x)/x`
43
44
## Code
45
The code for the functions is [here](https://gitlab.com/riddler_arg/exp4j/blob/master/src/main/java/net/objecthunter/exp4j/extras/OperatorsComparison.java), [here](https://gitlab.com/riddler_arg/exp4j/blob/master/src/main/java/net/objecthunter/exp4j/extras/FunctionsMisc.java) and [here](https://gitlab.com/riddler_arg/exp4j/blob/master/src/main/java/net/objecthunter/exp4j/extras/FunctionsBoolean.java).
Volver al inicio