Proyecto

General

Perfil

Built in Operators » Histórico » Versión 6

Federico Vera, 2018-07-12 06:02

1 1 Federico Vera
# Built in Operators
2
3 6 Federico Vera
{{>toc}}
4 1 Federico Vera
5
There are three basic sets of operators available:
6
7
## Arithmetic
8 5 Federico Vera
All of the arithmetic operators are included and available: `+`, `-`, `*`, `/` and of course `%` (modulo).
9 1 Federico Vera
10
## Boolean
11
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
13 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).
14 1 Federico Vera
15
There are also a set of [[Extra Functions and Operators]]
16
17
## Precedence
18 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:
19 1 Federico Vera
```
20
FIRST->  * / %  - +  ¬  &  |  == !=   <-LAST
21
         -----  ---  -  -  -  -----    
22
         ^^^ The dashes indicate groups with the same precedence
23
```
24 5 Federico Vera
When operators have the same precedence they will be evaluated from left to right.
25 1 Federico Vera
26 5 Federico Vera
***Note:*** as in primary school (and beyond) you can always alter the precedence of operators with the use of parentheses.
27 1 Federico Vera
28
## Factorial
29 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).
30 1 Federico Vera
31
**Note:** Factorials from `0!` to `21!` are guaranteed to be correct, bigger than `21!` may suffer lost of precision because of `double` rounding.
32
**Note 2:** Factorials bigger than `170!` will rise an `IllegalArgumentException` since the value will be `Double.INFINITY`.
33
34
## Code
35 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).
Volver al inicio