Math Functions
Turso provides 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 or 0.0 depending on the function.Function Reference
Trigonometric Functions
Hyperbolic Functions
Angle Conversion
Rounding and Truncation
Logarithmic and Exponential Functions
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 Functions
Constants
Signatures
acos()
Returns: REAL. The angle in radians whose cosine is X. Returns NULL if X is outside [-1.0, 1.0].
acosh()
Returns: REAL. The inverse hyperbolic cosine of X. Returns NULL if X < 1.0.
asin()
Returns: REAL. The angle in radians whose sine is X. Returns NULL if X is outside [-1.0, 1.0].
asinh()
Returns: REAL. The inverse hyperbolic sine of X.
atan()
Returns: REAL. The angle in radians whose tangent is X. Result is in the range (-pi/2, pi/2).
atan2()
Returns: REAL. The angle in radians between the positive x-axis and the point (X, Y). Result is in the range (-pi, pi]. Unlike
atan(Y/X), atan2 correctly handles all quadrants and the case where X is zero.
atanh()
Returns: REAL. The inverse hyperbolic tangent of X. Returns NULL if X is outside (-1.0, 1.0).
ceil() / ceiling()
Returns: INTEGER. The smallest integer not less than X.
cos()
Returns: REAL. The cosine of X.
cosh()
Returns: REAL. The hyperbolic cosine of X.
degrees()
Returns: REAL. X converted from radians to degrees.
exp()
Returns: REAL. The value of e raised to the power X.
floor()
Returns: INTEGER. The largest integer not greater than X.
ln()
Returns: REAL. The natural logarithm (base e) of X. Returns NULL if X <= 0.
log()
Returns: REAL. With one argument, returns the natural logarithm of X (same as
ln(X)). With two arguments, returns the logarithm of X in base B.
log10()
Returns: REAL. The base-10 logarithm of X. Returns NULL if X <= 0.
log2()
Returns: REAL. The base-2 logarithm of X. Returns NULL if X <= 0.
mod()
Returns: REAL. The remainder when X is divided by Y. Returns NULL if Y is 0.
pi()
pow() / power()
Returns: REAL. X raised to the power Y.
radians()
Returns: REAL. X converted from degrees to radians.
sign()
Returns: INTEGER. Returns -1 if X is negative, 0 if X is zero, and +1 if X is positive. Returns NULL if X is NULL.
sin()
Returns: REAL. The sine of X.
sinh()
Returns: REAL. The hyperbolic sine of X.
sqrt()
Returns: REAL. The square root of X. Returns NULL if X is negative.
tan()
Returns: REAL. The tangent of X.
tanh()
Returns: REAL. The hyperbolic tangent of X. Result is always in the range (-1.0, 1.0).
trunc()
Returns: INTEGER. The integer part of X, removing any fractional digits. Truncates toward zero.
Examples
Trigonometry
Rounding
Logarithms
Distance Calculation
See Also
- Expressions for arithmetic operators
- Aggregate Functions for SUM, AVG, MIN, MAX
- Data Types for REAL and INTEGER storage classes