Project

General

Profile

Funciones y Operadores adicionales » History » Version 2

Federico Vera, 2018-07-12 17:41

1 1 Federico Vera
# Funciones y Operadores adicionales
2
3
{{>toc}}
4
5
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://redmine.riddler.com.ar/projects/exp4j/repository/revisions/master/show/src/main/java/net/objecthunter/exp4j/extras) package.
6
7
## Comparison Operators
8
Aside from the arithmetic operators several comparison operators are included: `<`, `<=`, `>`, `>=`, `!=` and `==`. 
9
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:
10
11
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`)](https://redmine.riddler.com.ar/projects/exp4j/repository/revisions/master/entry/src/main/java/net/objecthunter/exp4j/extras/FunctionsMisc.java#L38) and `false` otherwise.
12
13
### Precedence
14
Operator precedence is altered when using the comparison operators, the new precedence is:
15
~~~
16
FIRST->  * / %  - +  > >= < <=  ¬  &  |  == !=   <-LAST
17
         -----  ---  ---------  -  -  -  -----    
18
         ^^^ The dashes indicate groups with the same precedence
19
~~~
20
21
## Funciones lógicas
22
Even though we have boolean operators, there are also a number of boolean functions that can be used (some people prefer functions)
23
* `and(a, b)`: Y lógico _equivalente a `a & b`_
24
* `or(a, b)`: O lógico _equivalente a `a | b`_
25
* `xor(a, b)`: O exclusivo
26
* `nand(a, b)`: _equivalente a `¬(a & b)`_
27
* `nor(a, b)`: _equivalente a `¬(a | b)`_
28
* `xnor(a, b)`: O exclusivo negado 
29
* `not(a)`: _equivalente a `¬a`_
30
31
## Constantes lógicas
32
* `true()`: verdadero (`1.0`) (se considera como verdadero a cualquier valor distinto de cero, pero la función `true()` devuelve `1.0` así como los operadores booleans y de comparación.
33
* `false()`: falso (`0.0`)
34
35 2 Federico Vera
## Funciones adicionales
36
* `if(e, v_true, v_false)`: Ramifica la expresión, se evalúa como `v_true` si `e == true()` y `v_false`  si `e == false()` 
37
* `equals(a, b)`: Equivalente a `a == b`, por lo tanto se cumplen las mismas condiciones.
38
* `sinc(x)`: [Seno cardinal de `x`](https://en.wikipedia.org/wiki/Sinc_function) (no normalizado), equivalente a `sin(x)/x`
39 1 Federico Vera
40 2 Federico Vera
## Código
41 1 Federico Vera
El código está [aquí](https://redmine.riddler.com.ar/projects/exp4j/repository/revisions/master/entry/src/main/java/net/objecthunter/exp4j/extras/OperatorsComparison.java), [aquí](https://redmine.riddler.com.ar/projects/exp4j/repository/revisions/master/entry/src/main/java/net/objecthunter/exp4j/extras/FunctionsMisc.java) u [aquí](https://redmine.riddler.com.ar/projects/exp4j/repository/revisions/master/entry/src/main/java/net/objecthunter/exp4j/extras/FunctionsBoolean.java).
Go to top