Funciones y Operadores adicionales » Histórico » Revisión 2
Revisión 1 (Federico Vera, 2018-07-12 17:38) → Revisión 2/8 (Federico Vera, 2018-07-12 17:41)
# Funciones y Operadores adicionales {{>toc}} 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. ## 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`)](https://redmine.riddler.com.ar/projects/exp4j/repository/revisions/master/entry/src/main/java/net/objecthunter/exp4j/extras/FunctionsMisc.java#L38) 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 ~~~ ## Funciones lógicas 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)`: Y lógico _equivalente a `a & b`_ * `or(a, b)`: O lógico _equivalente a `a | b`_ * `xor(a, b)`: O exclusivo * `nand(a, b)`: _equivalente a `¬(a & b)`_ * `nor(a, b)`: _equivalente a `¬(a | b)`_ * `xnor(a, b)`: O exclusivo negado * `not(a)`: _equivalente a `¬a`_ ## Constantes lógicas * `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. * `false()`: falso (`0.0`) ## Funciones adicionales Extra Functions * `if(e, v_true, v_false)`: Ramifica la expresión, se evalúa como Branches the formula, it will be evaluated as `v_true` si if `e == true()` y and `v_false` si if `e == false()` * `equals(a, b)`: Equivalente a Equivalent to `a == b`, por lo tanto se cumplen las mismas condiciones. so the same conditions apply. * `sinc(x)`: [Seno cardinal de [Cardinal sine of `x`](https://en.wikipedia.org/wiki/Sinc_function) (no normalizado), equivalente a (not normalized), equivalent to `sin(x)/x` ## Código Code 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).Volver al inicio