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 ofx
.
cbrt
(x) → double
Returns the cube root ofx
.
ceil
(x) → [same as input]
This is an alias forceiling()
.
ceiling
(x) → [same as input]
Returnsx
rounded up to the nearest integer.
cosinesimilarity
(_x, y) → double
Returns the cosine similarity between the sparse vectorsx
andy
:- SELECT cosinesimilarity(MAP(ARRAY['a'], ARRAY[1.0]), MAP(ARRAY['a'], ARRAY[2.0])); — 1.0
- SELECT cosinesimilarity(MAP(ARRAY['a'], ARRAY[1.0]), MAP(ARRAY['a'], ARRAY[2.0])); — 1.0
degrees
(_x) → double
Converts anglex
in radians to degrees.
e
() → double
Returns the constant Euler’s number.
exp
(x) → double
Returns Euler’s number raised to the power ofx
.
floor
(x) → [same as input]
Returnsx
rounded down to the nearest integer.
frombase
(_string, radix) → bigint
Returns the value ofstring
interpreted as a base-radix
number.
inversenormal_cdf
(_mean, sd, p) → double
Compute 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) → 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 realand positive value.
ln
(x) → double
Returns the natural logarithm ofx
.
log2
(x) → double
Returns the base 2 logarithm ofx
.
log10
(x) → double
Returns the base 10 logarithm ofx
.
mod
(n, m) → [same as input]
Returns the modulus (remainder) ofn
divided bym
.
pi
() → double
Returns the constant Pi.
pow
(x, p) → double
This is an alias forpower()
.
power
(x, p) → double
Returnsx
raised to the power ofp
.
radians
(x) → double
Converts anglex
in degrees to radians.
rand
() → double
This is an alias forrandom()
.
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).
round
(x) → [same as input]
Returnsx
rounded to the nearest integer.
round
(x, d) → [same as input]
Returnsx
rounded tod
decimal places.
sign
(x) → [same as input]
Returns the signum function ofx
, 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 ofx
.
tobase
(_x, radix) → varchar
Returns the base-radix
representation ofx
.
truncate
(x) → double
Returnsx
rounded to integer by dropping digits after decimal point.
widthbucket
(_x, bound1, bound2, n) → bigint
Returns the bin number ofx
in an equi-width histogram with thespecifiedbound1
andbound2
bounds andn
number of buckets.
widthbucket
(_x, bins) → bigint
Returns the bin number ofx
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) → double
Returns the lower bound of the Wilson score interval of a Bernoulli trial processat a confidence specified by the z-scorez
.
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-scorez
.
Trigonometric Functions
All trigonometric function arguments are expressed in radians.See unit conversion functions degrees()
and radians()
.
acos
(x) → double
Returns the arc cosine ofx
.
asin
(x) → double
Returns the arc sine ofx
.
atan
(x) → double
Returns the arc tangent ofx
.
atan2
(y, x) → double
Returns the arc tangent ofy / x
.
cos
(x) → double
Returns the cosine ofx
.
cosh
(x) → double
Returns the hyperbolic cosine ofx
.
sin
(x) → double
Returns the sine ofx
.
tan
(x) → double
Returns the tangent ofx
.
tanh
(x) → double
Returns the hyperbolic tangent ofx
.
Floating Point Functions
infinity
() → double
Returns the constant representing positive infinity.
isfinite
(_x) → boolean
Determine ifx
is finite.
isinfinite
(_x) → boolean
Determine ifx
is infinite.
isnan
(_x) → boolean
Determine ifx
is not-a-number.
nan
() → double
Returns the constant representing not-a-number.