Mathematical Functions and Operators

This page documents mathematical operators and functions available in Polars SQL.

Mathematical Operators

Operator

Description

+

Addition

-

Subtraction

*

Multiplication

/

Division. Integer division performs truncation. Division by zero returns NULL.

%

Modulus (remainder). Division by zero returns NULL.

Mathematical Functions

abs(x) -> [same as input]()

Returns the absolute value of x.

ceil(x) -> [same integer type for integer input, double otherwise]()

Returns x rounded up to the nearest integer.

ceiling(x) -> double()

Returns x rounded up to the nearest integer.

degrees(x) -> double()

Converts angle x in radians to degrees.

exp(x) -> double()

Returns Euler’s number raised to the power of x.

floor(x) -> [same integer type for integer input, double otherwise]()

Returns x rounded down to the nearest integer.

ln(x) -> double()

Returns the natural logarithm of x.

log10(x) -> double()

Returns the base 10 logarithm of x.

log(x) -> double()

Equivalent to log10().

log(x, base) -> double()

Returns the logarithm of x using the supplied base.

mod(n, m) -> [common numeric type]()

Returns the modulus (remainder) of n divided by m. Division by zero returns NULL.

power(x, p) -> double()

Returns x raised to the power of p.

radians(x) -> double()

Converts angle x in degrees to radians.

round(x) -> double()

Returns x rounded to the nearest integer.

round(x, d) -> double()

Returns x rounded to d decimal places. d must be an integer and can be negative.

sqrt(x) -> double()

Returns the square root of x.

fact(x) -> bigint()

Returns the factorial of x after casting it to an integer. Values outside the supported integer factorial range return NULL.

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.

sin(x) -> double()

Returns the sine of x.

tan(x) -> double()

Returns the tangent of x.