WSO2 Complex Event Processor is succeeded by WSO2 Stream Processor. To view the latest documentation for WSO2 SP, see WSO2 Stream Processor Documentation.

Go to start of banner

# Math Extension(math)

You are viewing an old version of this page. View the current version.

Version 6

Math extension provides basic mathematical functions such as calculating absolute value, sin, cos, tan, base conversion, parsing, etc. Following are the functions of the Math extension.

### Absolute Value function

Syntax ` math:abs( p1)` Function Returns the absolute value of `p1`. This function wraps the `java.lang.Math.abs()` function. Both the following queries return 3 since the absolute value of both `3` and `-3` is `3`.`abs(3)``abs(-3)`

### acos function

Syntax ` math:acos( p1)` Function If -1 <= p1 <= 1, this function returns the arc-cosine (inverse cosine) of `p1`. If not, it returns `NULL.` The return value is in radian scale. This function wraps the `java.lang.Math.acos()`function. `acos(0.5)` returns `1.0471975511965979`.

### asin function

Syntax ` math:asin (  p1)` Function If -1 <= p1 <= 1, this function returns the arc-sin (inverse sine) of `p1`. If not, it returns `NULL`. The return value is in radian scale. This function wraps the `java.lang.Math.asin()` function. `asin(0.5)` returns `0.5235987755982989`.

### atan function

Syntax ` math:atan( p1)` Function Returns the arc-tangent (inverse tangent) of `p1`. The return value is in radian scale. This function wraps the `java.lang.Math.atan()` function. `atan(6d)` returns `1.4056476493802699`.
Syntax ` math:atan ( p1,  p2)` Function Returns the arc-tangent (inverse tangent) of  `p1` and `p2` coordinates. The return value is in radian scale. This function wraps the` java.lang.Math.atan2()` function. `atan(12d, 5d)` returns `1.1760052070951352`.

### Binary function

Syntax `  math:bin( p1)` Function Returns a string representation of the integer/long p1 argument as an unsigned integer in base `2`. This function wraps the `java.lang.Integer.toBinaryString` and`java.lang.Long.toBinaryString` methods. ` bin(9)` returns `"1001"`.

### Ceiling function

Syntax `  math:ceil( p1)` Function Returns the smallest (closest to negative infinity) double value that is greater than or equal to the p1 argument, and is equal to a mathematical integer. This function wraps the`java.lang.Math.ceil()` method. `ceil(423.187d)` returns `424.0`.

### Convert function

Syntax `  math:conv( a,  fromBase,  toBase)` Function Converts `a` from the `fromBase` base to the `toBase` base. `conv("7f", 16, 10)` returns `"127"`.

### CopySign function

Syntax `  math:copySign( magnitude,  sign)` Function Returns the magnitude of `magnitude` with the sign of `sign` . This function wraps the `java.lang.Math.copySign()` function. `copySign(5.6d, -3.0d)` returns `-5.6`.

### cos function

Syntax `  math:cos( p1)` Function Returns the cosine of `p1` (`p1` is in radians). This function wraps the `java.lang.Math.cos()` function. `cos(6d)` returns `0.9601702866503661`.

### cosh function

Syntax `  math:cosh( p1)` Function Returns the hyperbolic cosine of `p1` (`p1` is in radians). This function wraps the `java.lang.Math.cosh()` function. `cosh (6d) `returns `201.7156361224559`.

### Cube Root function

Syntax `  math:cbrt( p1)` Function Returns the cube-root of `p1` (`p1` is in radians). This function wraps the `java.lang.Math.cbrt()` function. `cbrt(17d) `returns `2.5712815906582356`.

### e function

Syntax `  math:e()` Function Returns the `java.lang.Math.E` constant, which is the closest double value to `e` (which is the base of the natural logarithms). `e()` returns `2.7182818284590452354`.

### Exponential function

Syntax `  math:exp( p1)` Function Returns Euler's number `e` raised to the power of `p1`. This function wraps the `java.lang.Math.exp()` function. `exp(10.23)` returns `27722.51006805505`.

### Floor function

Syntax `  math:floor( p1)` Function This function wraps the `java.lang.Math.floor()` function that returns the largest (closest to positive infinity) value that is less that or equal to `p1`, and is equal to a mathematical integer. `floor(10.23)` returns `10.0.`

### Get Exponent function

Syntax `  math:getExponent(  p1)` Function Returns the unbiased exponent used in the representation of `p1`. This function wraps the `java.lang.Math.getExponent()` function. `getExponent(60984.1)` returns `15`.

Syntax `  math:hex( p1)` Function This function wraps the `java.lang.Double.toHexString()` function that returns a hexadecimal string representation of `p1`. `hex(200)` returns `"c8"`.

### Is Infinite function

Syntax `  math:isInfinite(  p1)` Function This function wraps the `java.lang.Float.isInfinite()` and `java.lang.Double.isInfinite() `functions that return `true` if `p1` is infinitely large in magnitude, or return `false`otherwise. `isInfinite(java.lang.Double.POSITIVE_INFINITY)` returns `true`.

### Is Not A Number function

Syntax `< boolean>  math:isNan(  p1)` Function This function wraps the `java.lang.Float.isNaN()` and `java.lang.Double.isNaN() `functions that return `true` if `p1` is a `NaN` (Not-a-Number) value, or return false otherwise. `isNan(java.lang.Math.log(-12d)`) returns` true`.

### ln function

Syntax ` math:ln (< int|long|float|double > p1)` Function Returns the natural logarithm (base e) of `p1`. `ln(11.453)` returns `2.438251704415579`.

### log2 function

Syntax ` math:log2 (< int|long|float|double >  p1)` Function Returns the `base 2` logarithm of `p1`. `log2(91d)` returns `6.507794640198696`.

### log10 function

Syntax ` math:log10 ( < int|long|float|double >  p1 )` Function Returns the base 10 logarithm of p1. `log10(19.234)` returns` 1.2840696117100832`.

### log function

Syntax ` math:log (< int|long|float|double >  number, < int|long|float|double >  base )` Function Returns the logarithm (base=base) of `number`. `log(34, 2f)` returns `5.08746284125034`.

### Max function

Syntax ` math:max (< int|long|float|double >  p1,     p2 )` Function Returns the greater value out of `p1` and `p2`. `max(123.67d, 91) `returns `123.67`.

### Min function

Syntax ` math:min (< int|long|float|double >  p1,     p2 )` Function Returns the smaller value out of `p1` and `p2`. `min(123.67d, 91)` returns `91`.

### Octal function

Syntax ` math:oct (  p1)` Function Converts `p1` to octal. `oct(99l)` returns `"143"`.

### Parse Double function

Syntax ` math:parseDouble (  str)` Function Returns `str` as a double. `parseDouble("123")` returns `123.0`.

### Parse Float function

Syntax ` math:parseFloat (  str)` Function Returns `str `as a float. `parseFloat("123")` returns `123.0`.

### Parse Int function

Syntax ` math:parseInt (  str)` Function Returns `str` as an int. `parseInt("123")` returns `123`.

### Parse Long function

Syntax ` math:parseLong (  str)` Function Returns `str` as a long. `parseLong("123")` returns `123`.

### Percentile function

Syntax  math:percentile (  arg,   p) Function Returns the `p`th percentile value of the `arg` values. from inputStream#window.length(100)select math:percentile(temperature, 97.0) as percentileinsert into outputStream;returns 97th percentile value of last 100 `temperature` values.

### pi function

Syntax ` math:pi ( )` 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). `pi()` always returns `3.141592653589793`.

### Power function

Syntax ` math:power ( < int|long|float|double>  value,     toPower )` Function Returns `value` raised to the power of `toPower`. `power(5.6d, 3.0d)` returns `175.61599999999996`.

### Random function

Syntax ` math:rand ( )` Function A sequence of calls to `rand()` generates a stream of pseudo-random numbers. This function uses the `java.util.Random` class internally. Two sequential calls to `rand()` may return `0.8263929447650588` and `0.24425883860361197` respectively.
Syntax ` math:rand (< int|long >  seed)` Function A sequence of calls to `rand(seed`) generates a stream of pseudo-random numbers. This function uses the `java.util.Random` class internally. Two sequential calls to `rand(12)` may return `0.7298928061101974` and `0.2750691655200749`, respectively.

### Round function

Syntax ` math:round ( value )` Funcion Returns the closest integer value to the argument. `round(3.35)` returns `3`.
Syntax ` math:round ( value )` Function Returns the closest long value to the argument. `round(3252.353)` returns `3252`.

### Sign of Number function

Syntax ` math:signum (< int|long|float|double >  p1)` Function If `a` is a positive, this returns the sign of `p1` as `1.0`.If `a` is a negative, this returns the sign of `p1` as -`1.0`.If `a` is neither a positive or a negative, this returns the sign of `p1` as `0.0`.This function wraps the `java.lang.Math.signum()` function. `signum(-6.32d)` returns `-1`.

### sin function

Syntax ` math:sin (< int|long|float|double >  p1)` Function Returns the sine of `p1` (`p1` is in radians). This function wraps the `java.lang.Math.sin()` function. `sin(6d`) returns `-0.27941549819892586.`

### sinh function

Syntax ` math:sinh (< int|long|float|double >  p1)` Function Returns the hyperbolic sine of `p1` (`p1` is in radians). This function wraps the `java.lang.Math.sinh()` function. `sinh(6d)` returns `201.71315737027922`.

### Square Root function

Syntax ` math:sqrt (< int|long|float|double >  p1)` Function Returns the square-root of `p1`. This function wraps the` java.lang.Math.sqrt()` function. `sqrt(4d)` returns `2`.

### tan function

Syntax ` math:tan (< int|long|float|double >  p1)` Function Returns the tan of `p1` (`p1` is in radians). This function wraps the `java.lang.Math.tan()` function. `tan(6d)` returns `-0.29100619138474915`.

### tanh function

Syntax ` math:tanh (  p1)` Function Returns the hyperbolic tangent of `p1` (`p1` is in radians). This function wraps the `java.lang.Math.tanh()` function. `tanh(6d)` returns `0.9999877116507956`.

### To Degrees function

Syntax ` math:toDegrees (< int|long|float|double >  p1)` Function Converts `p1` from radians to degrees. This function wraps the `java.lang.Math.toDegrees()` function. `toDegrees(6d)` returns `343.77467707849394`.

Syntax ` math:toRadians (< int|long|float|double >  p1)` Function Converts `p1` from degrees to radians. This function wraps the `java.lang.Math.toRadians()` function. `toRadians(6d)` returns `0.10471975511965977`.