Skip to main content

Numeric Functions

Numeric Operators

The table below shows the available mathematical operators for numeric types.

OperatorDescriptionExampleResult
+addition2 + 35
-subtraction2 - 3-1
*multiplication2 * 36
/float division5 / 22.5
//division5 // 22
%modulo (remainder)5 % 41
**exponent3 ** 481
^exponent (alias for **)3 ^ 481
&bitwise AND91 & 1511
``bitwise OR`32
<<bitwise shift left1 << 416
>>bitwise shift right8 >> 22
~bitwise negation~15-16
!factorial of x. Computes the product of the current integer and all integers below it4!24

There are two division operators: / and //. They are equivalent when at least one of the operands is a FLOAT or a DOUBLE. When both operands are integers, / performs floating points division (5 / 2 = 2.5) while // performs integer division (5 // 2 = 2).

The modulo, bitwise, and negation and factorial operators work only on integral data types, whereas the others are available for all numeric data types.

Numeric Functions

The table below shows the available mathematical functions.

FunctionDescriptionExampleResult
abs(x)absolute valueabs(-17.4)17.4
acos(x)computes the arccosine of xacos(0.5)1.0471975511965976
asin(x)computes the arcsine of xasin(0.5)0.5235987755982989
atan(x)computes the arctangent of xatan(0.5)0.4636476090008061
atan2(x, y)computes the arctangent (x, y)atan2(0.5, 0.5)0.7853981633974483
bit_count(x)returns the number of bits that are setbit_count(31)5
cbrt(x)returns the cube root of the numbercbrt(8)2
ceil(x)rounds the number upceil(17.4)18
ceiling(x)rounds the number up. Alias of ceil.ceiling(17.4)18
cos(x)computes the cosine of xcos(90)-0.4480736161291701
cot(x)computes the cotangent of xcot(0.5)1.830487721712452
degrees(x)converts radians to degreesdegrees(pi())180
even(x)round to next even number by rounding away from zero.even(2.9)4
factorial(x)See ! operator. Computes the product of the current integer and all integers below itfactorial(4)24
floor(x)rounds the number downfloor(17.4)17
gamma(x)interpolation of (x-1) factorial (so decimal inputs are allowed)gamma(5.5)52.34277778455352
gcd(x, y)computes the greatest common divisor of x and ygcd(42, 57)3
greatest_common_divisor(x, y)computes the greatest common divisor of x and ygreatest_common_divisor(42, 57)3
greatest(x1, x2, ...)selects the largest valuegreatest(3, 2, 4, 4)4
isfinite(x)Returns true if the floating point value is finite, false otherwiseisfinite(5.5)true
isinf(x)Returns true if the floating point value is infinite, false otherwiseisinf('Infinity'::float)true
isnan(x)Returns true if the floating point value is not a number, false otherwiseisnan('NaN'::float)true
lcm(x, y)computes the least common multiple of x and ylcm(42, 57)798
least_common_multiple(x, y)computes the least common multiple of x and yleast_common_multiple(42, 57)798
least(x1, x2, ...)selects the smallest valueleast(3, 2, 4, 4)2
lgamma(x)computes the log of the gamma function.lgamma(2)0
ln(x)computes the natural logarithm of xln(2)0.693
log(x)computes the 10-log of xlog(100)2
log2(x)computes the 2-log of xlog2(8)3
log10(x)alias of log. computes the 10-log of xlog10(1000)3
nextafter(x, y)return the next floating point value after x in the direction of ynextafter(1::float, 2::float)1.0000001
pi()returns the value of pipi()3.141592653589793
pow(x, y)computes x to the power of ypow(2, 3)8
power(x, y)Alias of pow. computes x to the power of ypower(2, 3)8
radians(x)converts degrees to radiansradians(90)1.5707963267948966
random()returns a random number between 0 and 1random()various
round(v numeric, s int)round to s decimal placesround(42.4332, 2)42.43
setseed(x)sets the seed to be used for the random functionsetseed(0.42)
sin(x)computes the sin of xsin(90)0.8939966636005579
sign(x)returns the sign of x as -1, 0 or 1sign(-349)-1
signbit(x)returns whether the signbit is set or notsignbit(-0.0)true
sqrt(x)returns the square root of the numbersqrt(9)3
xor(x)bitwise XORxor(17, 5)20
tan(x)computes the tangent of xtan(90)-1.995200412208242
@absolute value (parentheses optional if operating on a column)@(-2)2