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