Proyecto

General

Perfil

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

Federico Vera, 2018-06-09 23: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
Boolean operators will consider `false` every value equal to zero ([`0 ± 0.000000000001`](https://gitlab.com/riddler_arg/exp4j/blob/master/src/main/java/net/objecthunter/exp4j/operator/Operator.java#L70)), and `true` every other value. 
12
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
There are also a set of [[Extra Functions|Extra Functions and Operators]]
17
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
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://gitlab.com/riddler_arg/exp4j/blob/master/src/main/java/net/objecthunter/exp4j/operator/Operators.java#L183).
35
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
The code for the operators is [here](https://gitlab.com/riddler_arg/exp4j/blob/master/src/main/java/net/objecthunter/exp4j/operator/Operators.java).
Volver al inicio