Skip to main content
Turso supports all SQLite math functions. These functions operate on numeric values and return REAL unless otherwise noted. If any argument is NULL, the function returns NULL. If any argument is non-numeric and cannot be converted, the function returns NULL.

Function Reference

Trigonometric

FunctionDescriptionReturns
acos(X)Inverse cosine of X in radians. X must be in [-1.0, 1.0]REAL
asin(X)Inverse sine of X in radians. X must be in [-1.0, 1.0]REAL
atan(X)Inverse tangent of X in radiansREAL
atan2(Y, X)Inverse tangent of Y/X, using signs of both arguments to determine quadrantREAL
cos(X)Cosine of X (in radians)REAL
sin(X)Sine of X (in radians)REAL
tan(X)Tangent of X (in radians)REAL

Hyperbolic

FunctionDescriptionReturns
acosh(X)Inverse hyperbolic cosine of X. X must be >= 1.0REAL
asinh(X)Inverse hyperbolic sine of XREAL
atanh(X)Inverse hyperbolic tangent of X. X must be in (-1.0, 1.0)REAL
cosh(X)Hyperbolic cosine of XREAL
sinh(X)Hyperbolic sine of XREAL
tanh(X)Hyperbolic tangent of X. Result is always in (-1.0, 1.0)REAL

Angle Conversion

FunctionDescriptionReturns
degrees(X)Convert X from radians to degreesREAL
radians(X)Convert X from degrees to radiansREAL

Rounding

FunctionDescriptionReturns
ceil(X)Smallest integer not less than XINTEGER
ceiling(X)Alias for ceil(X)INTEGER
floor(X)Largest integer not greater than XINTEGER
trunc(X)Integer part of X, truncated toward zeroINTEGER

Logarithmic and Exponential

FunctionDescriptionReturns
exp(X)e raised to the power XREAL
ln(X)Natural logarithm of X. X must be > 0REAL
log(X)Natural logarithm of X (same as ln(X))REAL
log(B, X)Logarithm of X in base B. Both must be > 0, B ≠ 1REAL
log10(X)Base-10 logarithm of X. X must be > 0REAL
log2(X)Base-2 logarithm of X. X must be > 0REAL
The single-argument log(X) returns the natural logarithm (base e), matching SQLite behavior. This differs from some other databases where log(X) returns the base-10 logarithm.

Arithmetic

FunctionDescriptionReturns
mod(X, Y)Remainder of X divided by Y. Returns NULL if Y is 0REAL
pow(X, Y)X raised to the power YREAL
power(X, Y)Alias for pow(X, Y)REAL
sqrt(X)Square root of X. X must be >= 0REAL

Constants

FunctionDescriptionReturns
pi()The mathematical constant π (3.141592653589793)REAL

Function Details

acos(X)

Returns the angle in radians whose cosine is X. Returns NULL if X is outside [-1.0, 1.0].

acosh(X)

Returns the inverse hyperbolic cosine of X. Returns NULL if X < 1.0.

asin(X)

Returns the angle in radians whose sine is X. Returns NULL if X is outside [-1.0, 1.0].

asinh(X)

Returns the inverse hyperbolic sine of X.

atan(X)

Returns the angle in radians whose tangent is X. Result is in the range (-π/2, π/2).

atan2(Y, X)

Returns the angle in radians between the positive x-axis and the point (X, Y). Result is in (-π, π]. Unlike atan(Y/X), atan2 correctly handles all quadrants and the case where X is zero.

atanh(X)

Returns the inverse hyperbolic tangent of X. Returns NULL if X is outside (-1.0, 1.0).

ceil(X) / ceiling(X)

Returns the smallest integer not less than X.
SELECT ceil(3.2);    -- 4
SELECT ceil(-3.2);   -- -3
SELECT ceiling(5.0); -- 5

cos(X)

Returns the cosine of X (X is in radians).

cosh(X)

Returns the hyperbolic cosine of X.

degrees(X)

Converts X from radians to degrees.
SELECT degrees(pi());    -- 180.0
SELECT degrees(pi()/2);  -- 90.0

exp(X)

Returns e raised to the power X.
SELECT exp(0);  -- 1.0
SELECT exp(1);  -- 2.718281828459045

floor(X)

Returns the largest integer not greater than X.
SELECT floor(3.7);   -- 3
SELECT floor(-3.2);  -- -4

ln(X)

Returns the natural logarithm of X. Returns NULL if X is less than or equal to 0.
SELECT ln(1);       -- 0.0
SELECT ln(exp(1));  -- 1.0
SELECT ln(2);       -- 0.6931471805599453

log(X) / log(B, X)

With one argument, returns the natural logarithm of X (same as ln(X)). With two arguments, returns the logarithm of X in base B.
SELECT log(10);       -- 2.302585... (natural log)
SELECT log(10, 100);  -- 2.0 (log base 10 of 100)
SELECT log(2, 256);   -- 8.0 (log base 2 of 256)

log10(X)

Returns the base-10 logarithm of X. Returns NULL if X is less than or equal to 0.
SELECT log10(100);   -- 2.0
SELECT log10(1000);  -- 3.0

log2(X)

Returns the base-2 logarithm of X. Returns NULL if X is less than or equal to 0.
SELECT log2(256);   -- 8.0
SELECT log2(1024);  -- 10.0

mod(X, Y)

Returns the remainder when X is divided by Y. Returns NULL if Y is 0.
SELECT mod(10, 3);    -- 1.0
SELECT mod(10.5, 3);  -- 1.5
SELECT mod(-10, 3);   -- -1.0

pi()

Returns the mathematical constant π.
SELECT pi();           -- 3.141592653589793
SELECT 2 * pi() * 5;   -- 31.41592653589793

pow(X, Y) / power(X, Y)

Returns X raised to the power Y.
SELECT pow(2, 10);     -- 1024.0
SELECT power(3, 3);    -- 27.0
SELECT pow(100, 0.5);  -- 10.0 (square root)

radians(X)

Converts X from degrees to radians.
SELECT radians(180);  -- 3.141592653589793
SELECT radians(90);   -- 1.5707963267948966

sin(X)

Returns the sine of X (X is in radians).

sinh(X)

Returns the hyperbolic sine of X.

sqrt(X)

Returns the square root of X. Returns NULL if X is negative.
SELECT sqrt(144);  -- 12.0
SELECT sqrt(2);    -- 1.4142135623730951

tan(X)

Returns the tangent of X (X is in radians).

tanh(X)

Returns the hyperbolic tangent of X. Result is always in (-1.0, 1.0).

trunc(X)

Returns the integer part of X, truncated toward zero.
SELECT trunc(3.7);   -- 3
SELECT trunc(-3.7);  -- -3
SELECT trunc(5.0);   -- 5

Examples

Trigonometry

-- Sine and cosine of 45 degrees
SELECT sin(radians(45));  -- 0.7071067811865475
SELECT cos(radians(45));  -- 0.7071067811865476

-- Angle from coordinates
SELECT degrees(atan2(1, 1));  -- 45.0

-- Pythagorean identity: sin²(x) + cos²(x) = 1
SELECT pow(sin(1.0), 2) + pow(cos(1.0), 2);  -- 1.0

Rounding Comparison

SELECT ceil(2.3),  floor(2.3),  trunc(2.3);   -- 3, 2, 2
SELECT ceil(-2.3), floor(-2.3), trunc(-2.3);  -- -2, -3, -2

Logarithms

-- Number of bits needed to represent N
SELECT ceil(log2(1000));  -- 10

-- Decibel conversion
SELECT 10 * log10(100);  -- 20.0

-- Verify log identity
SELECT ln(exp(5));  -- 5.0

Euclidean Distance

-- Distance between two points
SELECT sqrt(pow(3 - 0, 2) + pow(4 - 0, 2));
-- 5.0

See Also

Build docs developers (and LLMs) love