# Siddhi Execution Math

The siddhi-execution-math extension is a Siddhi extension that provides useful mathematical functions such as power, round, random, cos, log, etc.

For information on Siddhi and it's features refer Siddhi Documentation.

• Versions 5.x and above with group id `io.siddhi.extension.*` from here.
• Versions 4.x and lower with group id `org.wso2.extension.siddhi.*` from here.

## Latest API Docs

Latest API Docs is 5.0.5.

## Features

• percentile (Aggregate Function)

This functions returns the pth percentile value of a given argument.

• abs (Function)

This function returns the absolute value of the given parameter. It wraps the `java.lang.Math.abs()` function.

• acos (Function)

If -1 <= p1 <= 1, this function returns the arc-cosine (inverse cosine) value of p1.If the domain is invalid, it returns NULL. The value returned is in radian scale. This function wraps the java.lang.Math.acos() function.

• asin (Function)

If -1 <= p1 <= 1, this function returns the arc-sin (inverse sine) value of p1. If the domain is invalid, it returns NULL. The value returned is in radian scale. This function wraps the java.lang.Math.asin() function.

• atan (Function)

1. If a single `p1` is received, this function returns the arc-tangent (inverse tangent) value of `p1`.
2. If `p1` is received along with an optional `p1`, it considers them as x and y coordinates and returns the arc-tangent (inverse tangent) value.
The returned value is in radian scale. This function wraps the `java.lang.Math.atan()` function.

• bin (Function)

This function returns a string representation of the p1 argument, that is of either 'integer' or 'long' data type, as an unsigned integer in base 2. It wraps the `java.lang.Integer.toBinaryString` and java.lang.Long.toBinaryString` methods.

• cbrt (Function)

This function returns the cube-root of 'p1' which is in radians. It wraps the `java.lang.Math.cbrt()` function.

• ceil (Function)

This function returns the smallest double value, i.e., the closest to the negative infinity, that is greater than or equal to the `p1` argument, and is equal to a mathematical integer. It wraps the `java.lang.Math.ceil()` method.

• conv (Function)

This function converts `a` from the `fromBase` base to the `toBase` base.

• copySign (Function)

This function returns a value of an input with the received `magnitude` and `sign` of another input. It wraps the `java.lang.Math.copySign()` function.

• cos (Function)

This function returns the cosine of `p1` which is in radians. It wraps the `java.lang.Math.cos()` function.

• cosh (Function)

This function returns the hyperbolic cosine of `p1` which is in radians. It wraps the `java.lang.Math.cosh()` function.

• e (Function)

This function returns the `java.lang.Math.E` constant, which is the closest double value to e, where e is the base of the natural logarithms.

• exp (Function)

This function returns the Euler's number `e` raised to the power of `p1`. It wraps the `java.lang.Math.exp()` function.

• floor (Function)

This function wraps the `java.lang.Math.floor()` function and returns the largest value, i.e., closest to the positive infinity, that is less than or equal to `p1`, and is equal to a mathematical integer.

• getExponent (Function)

This function returns the unbiased exponent that is used in the representation of `p1`. This function wraps the `java.lang.Math.getExponent()` function.

• hex (Function)

This function wraps the `java.lang.Double.toHexString() function. It returns a hexadecimal string representation of the input, `p1`.

• isInfinite (Function)

This function wraps the `java.lang.Float.isInfinite()` and `java.lang.Double.isInfinite()` and returns `true` if `p1` is infinitely large in magnitude and `false` if otherwise.

• isNan (Function)

This function wraps the `java.lang.Float.isNaN()` and `java.lang.Double.isNaN()` functions and returns `true` if `p1` is NaN (Not-a-Number), and returns `false` if otherwise.

• ln (Function)

This function returns the natural logarithm (base e) of `p1`.

• log (Function)

This function returns the logarithm of the received `number` as per the given `base`.

• log10 (Function)

This function returns the base 10 logarithm of `p1`.

• log2 (Function)

This function returns the base 2 logarithm of `p1`.

• max (Function)

This function returns the greater value of `p1` and `p2`.

• min (Function)

This function returns the smaller value of `p1` and `p2`.

• oct (Function)

This function converts the input parameter `p1` to octal.

• parseDouble (Function)

This function returns the double value of the string received.

• parseFloat (Function)

This function returns the float value of the received string.

• parseInt (Function)

This function returns the integer value of the received string.

• parseLong (Function)

This function returns the long value of the string received.

• pi (Function)

This function returns the `java.lang.Math.PI` constant, which is the closest value to pi, i.e., the ratio of the circumference of a circle to its diameter.

• power (Function)

This function raises the given value to a given power.

• rand (Function)

This returns a stream of pseudo-random numbers when a sequence of calls are sent to the `rand()`. Optionally, it is possible to define a seed, i.e., `rand(seed)` using which the pseudo-random numbers are generated. These functions internally use the `java.util.Random` class.

• round (Function)

This function returns the value of the input argument rounded off to the closest integer/long value.

• signum (Function)

This returns +1, 0, or -1 for the given positive, zero and negative values respectively. This function wraps the `java.lang.Math.signum()` function.

• sin (Function)

This returns the sine of the value given in radians. This function wraps the `java.lang.Math.sin()` function.

• sinh (Function)

This returns the hyperbolic sine of the value given in radians. This function wraps the `java.lang.Math.sinh()` function.

• sqrt (Function)

This function returns the square-root of the given value. It wraps the `java.lang.Math.sqrt()`s function.

• tan (Function)

This function returns the tan of the given value in radians. It wraps the `java.lang.Math.tan()` function.

• tanh (Function)

This function returns the hyperbolic tangent of the value given in radians. It wraps the `java.lang.Math.tanh()` function.

• toDegrees (Function)

This function converts the value given in radians to degrees. It wraps the `java.lang.Math.toDegrees()` function.

This function converts the value given in degrees to radians. It wraps the `java.lang.Math.toRadians()` function.

## Dependencies

There are no other dependencies needed for this extension.

## Installation

For installing this extension on various siddhi execution environments refer Siddhi documentation section on adding extensions.

## Support and Contribution

• We encourage users to ask questions and get support via StackOverflow, make sure to add the `siddhi` tag to the issue for better response.

• If you find any issues related to the extension please report them on the issue tracker.

• For production support and other contribution related information refer Siddhi Community documentation.