Built in Operators » Histórico » Versión 5
Federico Vera, 2018-07-09 17:45
1 | 1 | Federico Vera | # Built in Operators |
---|---|---|---|
2 | |||
3 | |||
4 | There are three basic sets of operators available: |
||
5 | |||
6 | ## Arithmetic |
||
7 | 5 | Federico Vera | All of the arithmetic operators are included and available: `+`, `-`, `*`, `/` and of course `%` (modulo). |
8 | 1 | Federico Vera | |
9 | ## Boolean |
||
10 | 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. |
||
11 | |||
12 | 5 | Federico Vera | But they are warrantied to return `1.0` for `true` and `0.0` for `false`. The available operators are: `&` (and), `|` (or), `¬` (not). |
13 | 1 | Federico Vera | |
14 | There are also a set of [[Extra Functions and Operators]] |
||
15 | |||
16 | ## Precedence |
||
17 | 5 | Federico Vera | For those who don't know, precedence of operators refers to which of theoperators will be evaluated first when left alone. I won't bother you with numbers, the order of evaluation is as follows: |
18 | 1 | Federico Vera | ``` |
19 | FIRST-> * / % - + ¬ & | == != <-LAST |
||
20 | ----- --- - - - ----- |
||
21 | ^^^ The dashes indicate groups with the same precedence |
||
22 | ``` |
||
23 | 5 | Federico Vera | When operators have the same precedence they will be evaluated from left to right. |
24 | 1 | Federico Vera | |
25 | 5 | Federico Vera | ***Note:*** as in primary school (and beyond) you can always alter the precedence of operators with the use of parentheses. |
26 | 1 | Federico Vera | |
27 | ## Factorial |
||
28 | 4 | Federico Vera | 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/Operators.java#L183). |
29 | 1 | Federico Vera | |
30 | **Note:** Factorials from `0!` to `21!` are guaranteed to be correct, bigger than `21!` may suffer lost of precision because of `double` rounding. |
||
31 | **Note 2:** Factorials bigger than `170!` will rise an `IllegalArgumentException` since the value will be `Double.INFINITY`. |
||
32 | |||
33 | ## Code |
||
34 | 2 | Federico Vera | 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). |