Funciones y Operadores adicionales » History » Revision 2

« Previous | Revision 2/8 (diff) | Next »
Federico Vera, 2018-07-12 17:41

Funciones y Operadores adicionales

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.


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

  • 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()
  • equals(a, b): Equivalente a a == b, por lo tanto se cumplen las mismas condiciones.
  • sinc(x): Seno cardinal de x (no normalizado), equivalente a sin(x)/x


El código está aquí, aquí u aquí.

Updated by Federico Vera almost 3 years ago · 2 revisions

Go to top