Proyecto

General

Perfil

Built in Functions » Histórico » Versión 10

Federico Vera, 2018-07-12 06:01

1 2 Federico Vera
# Built in Functions
2 10 Federico Vera
3 9 Federico Vera
{{>toc}}
4 10 Federico Vera
5 1 Federico Vera
There are a number of built-in functions, that usually just map with the corresponding [`java.util.Math`](https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html) methods (so all of the same restrictions apply), this functions are:
6
7
## Trigonometric Functions:
8
* `sin(x)`: Sine of an angle expressed in radians
9
* `cos(x)`: Cosine of an angle expressed in radians
10
* `tan(x)`: Tangent of an angle expressed in radians
11
12
## Inverse Trigonometric:
13
* `asin(x)`: Arc sine in the range [-π/2, π/2)
14
* `acos(x)`: Arc cosine in the range [0, π)
15
* `atan(x)`: Arc tangent in the range [-π/2, π/2) 
16
17
## Hyperbolic Functions:
18
* `sinh(x)`: Hyperbolic sine `(e^x - e^(-x)) / 2`
19
* `cosh(x)`: Hyperbolic cosine `(e^x + e^(-x)) / 2`
20
* `tanh(x)`: Hyperbolic tangent `(e^x - e^(-x)) / (e^x + e^(-x))`
21
22
## Logarithms
23
* `log(x)`: Base 10 logarithm of `x` 
24
* `log1p(x)`: Base 10 logarithm of `(x + 1)`
25
* `log10(x)`: Base 10 logarithm of `x`
26
* `log2(x)`: Base 2 logarithm of `x`
27
28
## Misc
29
* `pow(b, e)`: `b` to the power of `e`
30
* `sqrt(x)`: Square root of `x`
31
* `cbrt(x)`: Cube root of `x`
32
* `exp(x)`: `e` to the power of `x`
33
* `expm1(x)`: `e` to the power of `x` minus 1 (`e^x - 1`)
34 6 Federico Vera
* `signum(x)`:{{collapse(Note)
35 8 Federico Vera
*This is the only method not implemented using it's corresponding `java.util.Math` method.*
36 6 Federico Vera
}} Signum of `x` (`-1, 0, 1` for `< 0`, `= 0` and `> 0` respectively)
37 1 Federico Vera
* `abs(x)`: Absolute value of `x`
38
* `ceil(x)`: First integer closest to negative infinity greater than or equal `x` 
39
* `floor(x)`: First integer closest to positive infinity less than or equal `x` 
40
41
## Constants
42
* `pi()`: Ratio of the circumference of a circle to its diameter `3.14159265358979323846`
43
* `e()`: Base of the natural logarithm `2.7182818284590452354`
44
45
## Disabling built-in functions
46 3 Federico Vera
Since version `0.6-riddler` (commit:28c731ea) you can disable all built-in functions like this:
47 1 Federico Vera
48
~~~Java
49
    Expression e = new ExpressionBuilder("x + 3")
50
                      .disableBuiltInFunctions() //<--
51
                      .variable("x")
52
                      .build();
53
~~~
54
55
Remember that since constants are also defined as functions this will also disable them.
56
57
## Code
58 3 Federico Vera
The code for the functions is [here](https://redmine.riddler.com.ar/projects/exp4j/repository/revisions/master/entry/src/main/java/net/objecthunter/exp4j/function/Functions.java).
Volver al inicio