Proyecto

General

Perfil

Built in Operators » Histórico » Revisión 3

Revisión 2 (Federico Vera, 2018-07-08 05:57) → Revisión 3/6 (Federico Vera, 2018-07-08 05:58)

# Built in Operators 


 There are three basic sets of operators available: 

 ## Arithmetic 
 All of the arithmetic operators are included and available: `+`, `-`, `*`, `/` 
 and of course `%` (modulo). 

 ## Boolean 
 Boolean operators will consider `false` every value equal to zero ([`0 ± 0.000000000001`](https://redmine.riddler.com.ar/projects/exp4j/repository/revisions/master/entry/src/main/java/net/objecthunter/exp4j/operator/Operator.java#L70)), and `true` every other value.  

 But they are warrantied to return `1.0` for `true` and `0.0` for `false`. The 
 available operators are: `&` (and), `|` (or), `¬` (not). 

 There are also a set of [[Extra Functions|Extra Functions and Operators]] 

 ## Precedence 
 For those who don't know, precedence of operators refers to which of the 
 operators will be evaluated first when left alone. I won't bother you with 
 numbers, the order of evaluation is as follows: 
 ``` 
 FIRST->    * / %    - +    ¬    &    |    == !=     <-LAST 
          -----    ---    -    -    -    -----     
          ^^^ The dashes indicate groups with the same precedence 
 ``` 
 When operators have the same precedence they will be evaluated from left to 
 right. 

 ***Note:*** as in primary school (and beyond) you can always alter the 
 precedence of operators with the use of parentheses. 

 ## Factorial 
 Factorial isn't technically an operator... it's a function but since it's so common, it's implemented by using the `!` symbol and with more precedence than the arithmetic multiplication. Even though the implementation of operators is trivial in `exp4j` the factorial is the only postfix unary operator, so it deserves a [special case](https://redmine.riddler.com.ar/projects/exp4j/repository/revisions/master/entry/src/main/java/net/objecthunter/exp4j/operator/Operator2.java#L183). 

 **Note:** Factorials from `0!` to `21!` are guaranteed to be correct, bigger than `21!` may suffer lost of precision because of `double` rounding. 
 **Note 2:** Factorials bigger than `170!` will rise an `IllegalArgumentException` since the value will be `Double.INFINITY`. 

 ## Code 
 The code for the operators is [here](https://redmine.riddler.com.ar/projects/exp4j/repository/revisions/master/entry/src/main/java/net/objecthunter/exp4j/operator/Operators.java).
Volver al inicio