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