6.6. 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) → doubleReturns the cube root of
x
.ceil
(x) → [same as input]This is an alias for
ceiling()
.ceiling
(x) → [same as input]Returns
x
rounded up to the nearest integer.cosinesimilarity
(_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
degrees
(x) → doubleConverts angle
x
in radians to degrees.e
() → doubleReturns the constant Euler’s number.
exp
(x) → doubleReturns Euler’s number raised to the power of
x
.floor
(x) → [same as input]Returns
x
rounded down to the nearest integer.frombase
(_string, radix) → bigintReturns the value of
string
interpreted as a base-radix
number.inversenormal_cdf
(_mean, sd, p) → doubleCompute the inverse of the Normal cdf with given mean and standarddeviation (sd) for the cumulative probability (p): P(N < n). The mean must bea real value and the standard deviation must be a real and positive value.The probability p must lie on the interval (0, 1).
normalcdf
(_mean, sd, v) → doubleCompute 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 realand positive value.
inversebeta_cdf
(_a, b, p) → doubleCompute the inverse of the Beta cdf with given a, b parameters for the cumulativeprobability (p): P(N < n). The a, b parameters must be positive real values.The probability p must lie on the interval [0, 1].
betacdf
(_a, b, v) → doubleCompute 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].
ln
(x) → doubleReturns the natural logarithm of
x
.log2
(x) → doubleReturns the base 2 logarithm of
x
.log10
(x) → doubleReturns the base 10 logarithm of
x
.mod
(n, m) → [same as input]Returns the modulus (remainder) of
n
divided bym
.pi
() → doubleReturns the constant Pi.
pow
(x, p) → doubleThis is an alias for
power()
.power
(x, p) → doubleReturns
x
raised to the power ofp
.radians
(x) → doubleConverts angle
x
in degrees to radians.rand
() → doubleThis is an alias for
random()
.random
() → doubleReturns 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).
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) → doubleReturns the square root of
x
.tobase
(_x, radix) → varcharReturns the base-
radix
representation ofx
.truncate
(x) → doubleReturns
x
rounded to integer by dropping digits after decimal point.widthbucket
(_x, bound1, bound2, n) → bigintReturns the bin number of
x
in an equi-width histogram with thespecifiedbound1
andbound2
bounds andn
number of buckets.widthbucket
(_x, bins) → bigint- Returns the bin number of
x
according to the bins specified by thearraybins
. Thebins
parameter must be an array of doubles and isassumed to be in sorted ascending order.
Statistical Functions
wilsoninterval_lower
(_successes, trials, z) → doubleReturns the lower bound of the Wilson score interval of a Bernoulli trial processat a confidence specified by the z-score
z
.wilsoninterval_upper
(_successes, trials, z) → double- Returns the upper bound of the Wilson score interval of a Bernoulli trial processat a confidence specified by the z-score
z
.
Trigonometric Functions
All trigonometric function arguments are expressed in radians.See unit conversion functions degrees()
and radians()
.
acos
(x) → doubleReturns the arc cosine of
x
.asin
(x) → doubleReturns the arc sine of
x
.atan
(x) → doubleReturns the arc tangent of
x
.atan2
(y, x) → doubleReturns the arc tangent of
y / x
.cos
(x) → doubleReturns the cosine of
x
.cosh
(x) → doubleReturns the hyperbolic cosine of
x
.sin
(x) → doubleReturns the sine of
x
.tan
(x) → doubleReturns the tangent of
x
.tanh
(x) → double- Returns the hyperbolic tangent of
x
.
Floating Point Functions
infinity
() → doubleReturns the constant representing positive infinity.
isfinite
(_x) → booleanDetermine if
x
is finite.isinfinite
(_x) → booleanDetermine if
x
is infinite.isnan
(_x) → booleanDetermine if
x
is not-a-number.nan
() → double- Returns the constant representing not-a-number.