Proyecto

General

Perfil

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

Federico Vera, 2018-07-12 06:01

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