Unknown macro: {next_previous_links}
Skip to end of metadata
Go to start of metadata

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

Compare with Current View Page History

« Previous Version 6 Next »

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<double> math:abs(<float|double> p1)
Extension TypeFunction
DescriptionReturns the absolute value of p1. This function wraps the java.lang.Math.abs() function.
Examples

Both the following queries return 3 since the absolute value of both 3 and -3 is 3.

  • abs(3)
  • abs(-3)


acos  function

Syntax<double> math:acos(<float|double> p1)
Extension TypeFunction
DescriptionIf -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.
Exampleacos(0.5) returns 1.0471975511965979.

 

asin function

Syntax<double> math:asin (<float|double>  p1)
Extension TypeFunction
DescriptionIf -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.
Exampleasin(0.5) returns 0.5235987755982989.

 

atan function

Syntax<double> math:atan(<int|long|float|double> p1)
Extension TypeFunction
DescriptionReturns the arc-tangent (inverse tangent) of p1. The return value is in radian scale. This function wraps the java.lang.Math.atan() function.
Examplesatan(6d) returns 1.4056476493802699.
Syntax<double> math:atan (<int|long|float|double> p1, <int|long|float|double> p2)
Extension TypeFunction
DescriptionReturns 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.
Examplesatan(12d, 5d) returns 1.1760052070951352.

 

Binary function

Syntax<string>  math:bin(<int|long> p1)
Extension TypeFunction
DescriptionReturns a string representation of the integer/long p1 argument as an unsigned integer in base 2. This function wraps the java.lang.Integer.toBinaryString andjava.lang.Long.toBinaryString methods.
Examples bin(9) returns "1001".

 

Ceiling function

Syntax<double>  math:ceil(<float|double> p1)
Extension TypeFunction
DescriptionReturns 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 thejava.lang.Math.ceil() method.
Exampleceil(423.187d) returns 424.0.

 

Convert function

Syntax<string>  math:conv(<string> a, <int> fromBase, <int> toBase)
Extension TypeFunction
DescriptionConverts a from the fromBase base to the toBase base.
Exampleconv("7f", 16, 10) returns "127".

 

CopySign function

Syntax<double>  math:copySign(<int|long|float|double> magnitude, <int|long|float|double> sign)
Extension TypeFunction
DescriptionReturns the magnitude of magnitude with the sign of sign . This function wraps the java.lang.Math.copySign() function.
ExamplecopySign(5.6d, -3.0d) returns -5.6.

 

cos function

Syntax<double>  math:cos(<int|long|float|double> p1)
Extension TypeFunction
DescriptionReturns the cosine of p1 (p1 is in radians). This function wraps the java.lang.Math.cos() function.
Examplecos(6d) returns 0.9601702866503661.

 

cosh function

Syntax<double>  math:cosh(<int|long|float|double> p1)
Extension TypeFunction
DescriptionReturns the hyperbolic cosine of p1 (p1 is in radians). This function wraps the java.lang.Math.cosh() function.
Examplecosh (6d) returns 201.7156361224559.

 

Cube Root function

Syntax<double>  math:cbrt(<int|long|float|double> p1)
Extension TypeFunction
DescriptionReturns the cube-root of p1 (p1 is in radians). This function wraps the java.lang.Math.cbrt() function.
Examplecbrt(17d) returns 2.5712815906582356.

 

e function

Syntax<double>  math:e()
Extension TypeFunction
DescriptionReturns the java.lang.Math.E constant, which is the closest double value to e (which is the base of the natural logarithms).
Examplee() returns 2.7182818284590452354.

 

Exponential function

Syntax<double>  math:exp(<int|long|float|double> p1)
Extension TypeFunction
DescriptionReturns Euler's number e raised to the power of p1. This function wraps the java.lang.Math.exp() function.
Exampleexp(10.23) returns 27722.51006805505.

Floor function

Syntax<double>  math:floor(<int|long|float|double> p1)
Extension TypeFunction
DescriptionThis 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.
Examplefloor(10.23) returns 10.0.

 

Get Exponent function

Syntax<double>  math:getExponent(<int|long|float|double>  p1)
Extension TypeFunction
DescriptionReturns the unbiased exponent used in the representation of p1. This function wraps the java.lang.Math.getExponent() function.
ExamplegetExponent(60984.1) returns 15.

 

Hexadecimal function

Syntax<string>  math:hex(<int|long|float|double> p1)
Extension TypeFunction
DescriptionThis function wraps the java.lang.Double.toHexString() function that returns a hexadecimal string representation of p1.
Examplehex(200) returns "c8".

 

Is Infinite function

Syntax<boolean>  math:isInfinite(<float|double>  p1)
Extension TypeFunction
DescriptionThis 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 falseotherwise.
ExampleisInfinite(java.lang.Double.POSITIVE_INFINITY) returns true.

 

Is Not A Number function 

Syntax< boolean>  math:isNan(<float|double>  p1)
Extension TypeFunction
DescriptionThis 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.
ExampleisNan(java.lang.Math.log(-12d)) returns true.

 

ln function

Syntax<double> math:ln (< int|long|float|double > p1)
Extension TypeFunction
DescriptionReturns the natural logarithm (base e) of p1.
Exampleln(11.453) returns 2.438251704415579.

 

log2 function

Syntax<double> math:log2 (< int|long|float|double >  p1)
Extension TypeFunction
DescriptionReturns the base 2 logarithm of p1.
Examplelog2(91d) returns 6.507794640198696.

 

log10 function

Syntax<double> math:log10 ( < int|long|float|double >  p1 )
Extension TypeFunction
DescriptionReturns the base 10 logarithm of p1.
Examplelog10(19.234) returns 1.2840696117100832.

 

log function

Syntax<double> math:log (< int|long|float|double >  number, < int|long|float|double >  base )
Extension TypeFunction
DescriptionReturns the logarithm (base=base) of number.
Examplelog(34, 2f) returns 5.08746284125034.

 

Max function

Syntax<double> math:max (< int|long|float|double >  p1,  <int|long|float|double>   p2 )
Extension TypeFunction
DescriptionReturns the greater value out of p1 and p2.
Examplemax(123.67d, 91) returns 123.67.

 

Min function

Syntax<double> math:min (< int|long|float|double >  p1,  <int|long|float|double>   p2 )
Extension TypeFunction
DescriptionReturns the smaller value out of p1 and p2.
Examplemin(123.67d, 91) returns 91.

 

Octal function

Syntax<string> math:oct (<int|long>  p1)
Extension TypeFunction
DescriptionConverts p1 to octal.
Exampleoct(99l) returns "143".

 

Parse Double function

Syntax<double> math:parseDouble (<string>  str)
Extension TypeFunction
DescriptionReturns str as a double.
ExampleparseDouble("123") returns 123.0.

 

Parse Float function

Syntax<float> math:parseFloat (<string>  str)
Extension TypeFunction
DescriptionReturns str as a float.
ExampleparseFloat("123") returns 123.0.

 

Parse Int function

Syntax<int> math:parseInt (<string>  str)
Extension TypeFunction
DescriptionReturns str as an int.
ExampleparseInt("123") returns 123.

 

Parse Long function

Syntax<long> math:parseLong (<string>  str)
Extension TypeFunction
DescriptionReturns str as a long.
ExampleparseLong("123") returns 123.

 

Percentile function

Syntax<double> math:percentile (<int|long|float|double>  arg,  <double> p)
Extension TypeFunction
DescriptionReturns the pth percentile value of the arg values. 
Example

from inputStream#window.length(100)

select math:percentile(temperature, 97.0) as percentile

insert into outputStream;

returns 97th percentile value of last 100 temperature values. 

 

pi function

Syntax<double> math:pi ( )
Extension TypeFunction
DescriptionReturns 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). 
Examplepi() always returns 3.141592653589793.

 

Power function

Syntax<double> math:power ( < int|long|float|double>  value,  <int|long|float|double>   toPower )
Extension TypeFunction
DescriptionReturns value raised to the power of toPower.
Examplepower(5.6d, 3.0d) returns 175.61599999999996.

 

Random function

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

 

Round function

Syntax

<int> math:round (<float> value )

Extension TypeFuncion
DescriptionReturns the closest integer value to the argument.
Exampleround(3.35) returns 3.
Syntax<long> math:round (<double> value )
Extension TypeFunction
DescriptionReturns the closest long value to the argument.
Exampleround(3252.353) returns 3252.

 

Sign of Number function

Syntax<int> math:signum (< int|long|float|double >  p1)
Extension TypeFunction
Description
  • 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.

Examplesignum(-6.32d) returns -1.

 

sin function

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

 

sinh function

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

 

Square Root function

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

 

tan  function

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

 

tanh function

Syntax<double> math:tanh (<int|long|float|double>  p1)
Extension TypeFunction
DescriptionReturns the hyperbolic tangent of p1 (p1 is in radians). This function wraps the java.lang.Math.tanh() function. 
Exampletanh(6d) returns 0.9999877116507956.

 

To Degrees function

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

 

To Radians function

Syntax<double> math:toRadians (< int|long|float|double >  p1)
Extension TypeFunction
DescriptionConverts p1 from degrees to radians. This function wraps the java.lang.Math.toRadians() function.
ExampletoRadians(6d) returns 0.10471975511965977.
  • No labels