Built in Functions » Histórico » Versión 2
Federico Vera, 2018-06-09 23: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 | * `signum(x)`<sup>1</sup>: Signum of `x` (`-1, 0, 1` for `< 0`, `= 0` and `> 0` respectively) |
||
32 | * `abs(x)`: Absolute value of `x` |
||
33 | * `ceil(x)`: First integer closest to negative infinity greater than or equal `x` |
||
34 | * `floor(x)`: First integer closest to positive infinity less than or equal `x` |
||
35 | |||
36 | ## Constants |
||
37 | * `pi()`: Ratio of the circumference of a circle to its diameter `3.14159265358979323846` |
||
38 | * `e()`: Base of the natural logarithm `2.7182818284590452354` |
||
39 | |||
40 | ## Disabling built-in functions |
||
41 | Since version `0.6-riddler` ([commit](https://gitlab.com/riddler_arg/exp4j/commit/28c731ea9a6140871a2ee2e0373cd13751d2e494)) you can disable all built-in functions like this: |
||
42 | |||
43 | ~~~Java |
||
44 | Expression e = new ExpressionBuilder("x + 3") |
||
45 | .disableBuiltInFunctions() //<-- |
||
46 | .variable("x") |
||
47 | .build(); |
||
48 | ~~~ |
||
49 | |||
50 | Remember that since constants are also defined as functions this will also disable them. |
||
51 | |||
52 | ## Code |
||
53 | The code for the functions is [here](https://gitlab.com/riddler_arg/exp4j/blob/master/src/main/java/net/objecthunter/exp4j/function/Functions.java). |
||
54 | |||
55 | ## |
||
56 | <sup>1</sup> This is the only method not implemented using it's corresponding `java.util.Math` method. |