Mathematical Functions
This page lists the mathematical functions that are available in the GSQL query language. They are divided into three categories:
-
General
-
Logarithmic
-
Trigonometric
General
abs()
Syntax
abs( num )
Description
Returns the absolute value of a number.
Return type
Number
Parameters
Parameter | Description | Data type |
---|---|---|
|
The number to return the absolute value for |
Number |
ceil()
Syntax
ceil(num)
Description
Rounds a number up to the smallest integer that’s greater than or equal to the number.
Return type
INT
Parameters
Parameter | Description | Data type |
---|---|---|
|
The number to round up from |
num |
exp()
Syntax
exp(num)
Description
Returns the base-e exponential of a number.
Return type
FLOAT
Parameters
Parameter | Description | Data type |
---|---|---|
|
The exponent |
Number |
float_to_int()
Syntax
float_to_int (num)
Description
Converts a floating-point number to an integer by truncating the floating part.
Return type
INT
Parameters
Parameter | Description | Data type |
---|---|---|
|
The floating-point number to convert to integer |
|
floor()
Syntax
floor(num)
Description
Rounds a number down to the biggest integer that is smaller than or equal to the number.
Return type
INT
Parameter
Parameter | Description | Data type |
---|---|---|
|
The number to round down from |
Number |
fmod()
Syntax
fmod(numer, denom)
Description
Returns the floating-point remainder of numer
divided by denom
Return type
FLOAT
Parameters
Parameter | Description | Data type |
---|---|---|
|
The dividend |
Number |
|
The divisor |
Number |
ldexp()
Syntax
ldexp(x, exp)
Description
Returns x
multiplied by 2 raised to the power of exp
Return type
FLOAT
Parameters
Parameter | Description | Data type |
---|---|---|
|
The base |
Number |
|
The exponent of 2 |
Number |
PI()
Syntax
PI()
Description
Returns the value of π.
Return type
DOUBLE
Parameters
None.
Example
PI() * 1000000000 -> 3.141592653589793E9
pow()
Syntax
pow(base, exp)
Description
Returns the power of a number.
Return type
FLOAT
Parameters
Parameter | Description | Data type |
---|---|---|
|
The base |
Number |
|
The exponent |
Number |
rand()
Syntax
rand( [seed] )
Description
Returns a completely random number >= 0 and <1. If seed
is specified, it returns a repeatable sequence of random numbers. If no seed is specified, it returns a completely random number.
Return type
DOUBLE
Parameters
Parameter | Description | Data type |
---|---|---|
|
Optional. If |
|
Example
rand(5) -> 0.05518
rand(5) -> 0.83133
rand(5) -> 0.36374
round()
Syntax
round ( num[, integer] )
Description
Rounds a number to a specified place relative to the decimal point and returns the result.
Return type
A numeric type.
Parameters
Parameter | Description | Data type |
---|---|---|
|
The number to be rounded |
|
|
Optional. An integer value indicating the place to round the first
argument to. + If |
|
Examples
round(15.213) => 15
round(15.213, -1) => 20
round(2.15, 1) => 2.2
round(2.25, 1) => 2.3
sign()
Syntax
sign( num )
Description
Returns the sign of a number. If the number is positive, return 1
; if the number is negative, return -1
; if the number is 0
, return 0
Return type
INT
Parameters
Parameter | Description | Data type |
---|---|---|
|
A numeric value |
|
Examples
sign(100) => 1
sign(0) => 0
sign(-1.23) => -1
square()
Syntax
square( num )
Description
Returns the square of a number.
Return type
A numeric type.
Parameters
Parameter | Description | Data type |
---|---|---|
|
A numeric value. |
|
Examples
square(0) => 0
square(50) => 2500
square(-50) => 2500
sqrt()
Syntax
sqrt(num)
Description
Returns the square root of a number
Return type
FLOAT
Parameters
Parameter | Description | Data type |
---|---|---|
|
The number to get square root for. |
Number |
trunc()
Syntax
trunc( num, [decimal_place] )
Description
Returns a number truncated to a specified decimal place.
Return type
A numeric type.
Parameters
Parameter | Description | Data type |
---|---|---|
|
The number to be truncated |
|
|
Optional. The integer indicating the decimal place to truncate the number to. If |
|
Examples
trunc(9.99) => 9
trunc(-9.99) => 9
trunc(99.999. -1) => 90
trunc(9.99, 1) => 9.9
Logarithmic
log()
Syntax
log(num)
Description
Returns the natural logarithm of a number (base e).
Return type
DOUBLE
Parameters
Parameter | Description | Data type |
---|---|---|
|
The number to compute natural logarithm for |
Number |
Trigonometric
acos()
Syntax
acos(num)
Description
Returns the arc cosine of a number.
Return type
FLOAT
Parameters
Parameter | Description | Data type |
---|---|---|
|
The number to compute arccosine for |
Number |
asin()
Syntax
asin(num)
Description
Returns the arc sine of a number.
Return type
FLOAT
Parameters
Parameter | Description | Data type |
---|---|---|
|
The number to compute arcsine for |
Number |
atan()
Syntax
atan(num)
Description
Returns the arctangent of a number.
Return type
FLOAT
Parameters
Parameter | Description | Data type |
---|---|---|
|
The number to compute arctangent for |
Number |
atan2()
Syntax
atan2(y, x)
Description
Returns the arctangent of a fraction.
Return type
FLOAT
Parameters
Parameter | Description | Data type |
---|---|---|
|
The dividend of the fraction to compute arctangent for |
Number |
|
The divisor of the fraction to compute arctangent for |
Number |
cos()
Syntax
cos(num)
Description
Returns the cosine of a number.
Return type
FLOAT
Parameters
Parameter | Description | Data type |
---|---|---|
|
The number to return cosine for |
Number |
cosh()
Syntax
cosh(num)
Description
Returns the hyperbolic cosine of a number.
Return type
FLOAT
Parameters
Parameter | Description | Data type |
---|---|---|
|
The number to compute hyperbolic cosine for |
Number |
cot()
Syntax
cot( num )
Description
Returns the cotangent of a number.
Return type
DOUBLE
Parameters
Parameter | Description | Data type |
---|---|---|
|
A numeric value |
|
Examples
cot(6) => -3.4363530041801278
cot(-1) => -0.64209261593433065
degrees()
Syntax
degrees( num )
Description
Converts a value in radians to degrees.
Return type
DOUBLE
Parameters
Parameter | Description | Data type |
---|---|---|
|
A numeric value |
|
Examples
degrees(2) => 114.59155902616465
degrees(1) => -57.29577951308232
radians()
Syntax
radians( num )
Description
Converts a value in degrees to radians.
Return type
DOUBLE
Parameters
Parameter | Description | Data type |
---|---|---|
|
A numeric value |
|
Examples
radians( 45 ) => -0.7853981633974483
radians( 30 ) => 0.5235987755982988
radians( 50 ) => 0.8726646259971648
sin()
Syntax
sin(num)
Description
Returns the sine of a number.
Return type
FLOAT
Parameters
Parameter | Description | Data type |
---|---|---|
|
The number to compute sine for |
Number |
sinh()
Syntax
sinh(num)
Description
Returns the hyperbolic sine of a number.
Return type
FLOAT
Parameters
Parameter | Description | Data type |
---|---|---|
|
The number to compute hyperbolic sine for |
Number |