Mathematical functions and operators#
Mathematical operators#
Operator |
Description |
---|---|
|
Addition |
|
Subtraction |
|
Multiplication |
|
Division (integer division performs truncation) |
|
Modulus (remainder) |
Mathematical functions#
-
abs
(x) β [same as input]# Returns the absolute value of
x
.
-
cbrt
(x) β double# Returns the cube root of
x
.
-
ceiling
(x) β [same as input]# Returns
x
rounded up to the nearest integer.
-
degrees
(x) β double# Converts angle
x
in radians to degrees.
-
e
() β double# Returns the constant Eulerβs number.
-
exp
(x) β double# Returns Eulerβs number raised to the power of
x
.
-
floor
(x) β [same as input]# Returns
x
rounded down to the nearest integer.
-
ln
(x) β double# Returns the natural logarithm of
x
.
-
log
(b, x) β double# Returns the base
b
logarithm ofx
.
-
log2
(x) β double# Returns the base 2 logarithm of
x
.
-
log10
(x) β double# Returns the base 10 logarithm of
x
.
-
mod
(n, m) β [same as input]# Returns the modulus (remainder) of
n
divided bym
.
-
pi
() β double# Returns the constant Pi.
-
power
(x, p) β double# Returns
x
raised to the power ofp
.
-
radians
(x) β double# Converts angle
x
in degrees to radians.
-
round
(x) β [same as input]# Returns
x
rounded to the nearest integer.
-
round
(x, d) β [same as input] Returns
x
rounded tod
decimal places.
-
sign
(x) β [same as input]# Returns the signum function of
x
, that is:0 if the argument is 0,
1 if the argument is greater than 0,
-1 if the argument is less than 0.
For double arguments, the function additionally returns:
NaN if the argument is NaN,
1 if the argument is +Infinity,
-1 if the argument is -Infinity.
-
sqrt
(x) β double# Returns the square root of
x
.
-
truncate
(x) β double# Returns
x
rounded to integer by dropping digits after decimal point.
-
width_bucket
(x, bound1, bound2, n) β bigint# Returns the bin number of
x
in an equi-width histogram with the specifiedbound1
andbound2
bounds andn
number of buckets.
-
width_bucket
(x, bins) β bigint Returns the bin number of
x
according to the bins specified by the arraybins
. Thebins
parameter must be an array of doubles and is assumed to be in sorted ascending order.
Random functions#
-
random
() β double# Returns a pseudo-random value in the range 0.0 <= x < 1.0.
-
random
(n) β [same as input] Returns a pseudo-random number between 0 and n (exclusive).
-
random
(m, n) β [same as input] Returns a pseudo-random number between m and n (exclusive).
Trigonometric functions#
All trigonometric function arguments are expressed in radians.
See unit conversion functions degrees()
and radians()
.
-
acos
(x) β double# Returns the arc cosine of
x
.
-
asin
(x) β double# Returns the arc sine of
x
.
-
atan
(x) β double# Returns the arc tangent of
x
.
-
atan2
(y, x) β double# Returns the arc tangent of
y / x
.
-
cos
(x) β double# Returns the cosine of
x
.
-
cosh
(x) β double# Returns the hyperbolic cosine of
x
.
-
sin
(x) β double# Returns the sine of
x
.
-
tan
(x) β double# Returns the tangent of
x
.
-
tanh
(x) β double# Returns the hyperbolic tangent of
x
.
Floating point functions#
-
infinity
() β double# Returns the constant representing positive infinity.
-
is_finite
(x) β boolean# Determine if
x
is finite.
-
is_infinite
(x) β boolean# Determine if
x
is infinite.
-
is_nan
(x) β boolean# Determine if
x
is not-a-number.
-
nan
() β double# Returns the constant representing not-a-number.
Base conversion functions#
-
from_base
(string, radix) β bigint# Returns the value of
string
interpreted as a base-radix
number.
-
to_base
(x, radix) β varchar# Returns the base-
radix
representation ofx
.
Statistical functions#
-
cosine_similarity
(x, y) β double# Returns the cosine similarity between the sparse vectors
x
andy
:SELECT cosine_similarity(MAP(ARRAY['a'], ARRAY[1.0]), MAP(ARRAY['a'], ARRAY[2.0])); -- 1.0
-
wilson_interval_lower
(successes, trials, z) β double# Returns the lower bound of the Wilson score interval of a Bernoulli trial process at a confidence specified by the z-score
z
.
-
wilson_interval_upper
(successes, trials, z) β double# Returns the upper bound of the Wilson score interval of a Bernoulli trial process at a confidence specified by the z-score
z
.
Cumulative distribution functions#
-
beta_cdf
(a, b, v) β double# Compute the Beta cdf with given a, b parameters: P(N < v; a, b). The a, b parameters must be positive real numbers and value v must be a real value. The value v must lie on the interval [0, 1].
-
inverse_beta_cdf
(a, b, p) β double# Compute the inverse of the Beta cdf with given a, b parameters for the cumulative probability (p): P(N < n). The a, b parameters must be positive real values. The probability p must lie on the interval [0, 1].
-
inverse_normal_cdf
(mean, sd, p) β double# Compute the inverse of the Normal cdf with given mean and standard deviation (sd) for the cumulative probability (p): P(N < n). The mean must be a real value and the standard deviation must be a real and positive value. The probability p must lie on the interval (0, 1).
-
normal_cdf
(mean, sd, v) β double# Compute the Normal cdf with given mean and standard deviation (sd): P(N < v; mean, sd). The mean and value v must be real values and the standard deviation must be a real and positive value.