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