QuestDB provides comprehensive mathematical functions for numeric types (INT, LONG, FLOAT, DOUBLE, DECIMAL).Documentation Index
Fetch the complete documentation index at: https://mintlify.com/questdb/questdb/llms.txt
Use this file to discover all available pages before exploring further.
Basic Math
abs
Returns absolute value. Signature:abs(N) where N is any numeric type
Returns: Same type as input
Example:
sign
Returns sign of value (-1, 0, or 1). Signature:sign(N) where N is any numeric type
Returns: Same type as input
Example:
sqrt
Computes square root. Signature:sqrt(D)
Parameters:
D- DOUBLE
DOUBLE
Example:
pow
Raises number to power. Signature:pow(DD) or power(DD)
Parameters:
- First
D- Base - Second
D- Exponent
DOUBLE
Example:
exp
Computes e raised to power. Signature:exp(D)
Parameters:
D- DOUBLE exponent
DOUBLE
Example:
ln
Computes natural logarithm (base e). Signature:ln(D)
Parameters:
D- DOUBLE
DOUBLE
Example:
log
Computes logarithm (base 10). Signature:log(D) or log10(D)
Parameters:
D- DOUBLE
DOUBLE
Example:
Rounding Functions
round
Rounds to specified decimal places. Signature:round(DI)
Parameters:
D- DOUBLE valueI- Number of decimal places
DOUBLE
Example:
round_down
Rounds down (toward negative infinity). Signature:round_down(DI)
Parameters:
D- DOUBLE valueI- Number of decimal places
DOUBLE
Example:
round_up
Rounds up (toward positive infinity). Signature:round_up(DI)
Parameters:
D- DOUBLE valueI- Number of decimal places
DOUBLE
Example:
round_half_even
Rounds using banker’s rounding (round half to even). Signature:round_half_even(DI)
Parameters:
D- DOUBLE valueI- Number of decimal places
DOUBLE
Example:
ceil
Rounds up to nearest integer. Signature:ceil(D) or ceiling(D)
Parameters:
D- DOUBLE
DOUBLE
Example:
floor
Rounds down to nearest integer. Signature:floor(D)
Parameters:
D- DOUBLE
DOUBLE
Example:
Trigonometric Functions
sin
Computes sine (radians). Signature:sin(D)
Parameters:
D- DOUBLE angle in radians
DOUBLE
Example:
cos
Computes cosine (radians). Signature:cos(D)
Parameters:
D- DOUBLE angle in radians
DOUBLE
Example:
tan
Computes tangent (radians). Signature:tan(D)
Parameters:
D- DOUBLE angle in radians
DOUBLE
Example:
asin
Computes arcsine (radians). Signature:asin(D)
Parameters:
D- DOUBLE value between -1 and 1
DOUBLE
Example:
acos
Computes arccosine (radians). Signature:acos(D)
Parameters:
D- DOUBLE value between -1 and 1
DOUBLE
Example:
atan
Computes arctangent (radians). Signature:atan(D)
Parameters:
D- DOUBLE
DOUBLE
Example:
atan2
Computes arctangent of y/x (radians). Signature:atan2(DD)
Parameters:
- First
D- y coordinate - Second
D- x coordinate
DOUBLE
Example:
cot
Computes cotangent (radians). Signature:cot(D)
Parameters:
D- DOUBLE angle in radians
DOUBLE
Example:
Angle Conversion
radians
Converts degrees to radians. Signature:radians(D)
Parameters:
D- DOUBLE degrees
DOUBLE
Example:
degrees
Converts radians to degrees. Signature:degrees(D)
Parameters:
D- DOUBLE radians
DOUBLE
Example:
Constants
pi
Returns π (pi). Signature:pi()
Returns: DOUBLE
Example:
Comparison Functions
greatest
Returns largest value from arguments. Signature:greatest(N, N, ...)
Parameters:
- Variable number of numeric arguments
least
Returns smallest value from arguments. Signature:least(N, N, ...)
Parameters:
- Variable number of numeric arguments
Arithmetic Operators
Addition
Subtraction
Multiplication
Division
Modulo
Negation
Bitwise Operations
Bitwise AND
Operator:&
Example:
Bitwise OR
Operator:|
Example:
Bitwise XOR
Operator:^
Example:
Bitwise NOT
Operator:~
Example:
Modulo and Remainder
mod
Computes modulo (remainder). Signature:mod(NN) where N is INT, LONG, FLOAT, or DOUBLE
Parameters:
- First
N- Dividend - Second
N- Divisor
rem
Computes remainder (same as mod for positive numbers). Signature:rem(NN)
Parameters:
- First
N- Dividend - Second
N- Divisor
Type Casting
QuestDB supports explicit casting with:: syntax:
NULL Handling
Most numeric functions return NULL if any input is NULL:Performance Notes
- Integer operations are faster than floating-point
- Use appropriate types: INT for small integers, LONG for large
- DECIMAL types provide precise decimal arithmetic
- Bitwise operations are highly optimized