Math functions
These functions can be used when analysing numeric data and numeric collections.
| Function | Description |
|---|---|
math::abs() | Returns the absolute value of a number |
math::acos() | Computes the arccosine (inverse cosine) of a value |
math::acot() | Computes the arccotangent (inverse cotangent) of an angle given in radians |
math::asin() | Computes the arcsine (inverse sine) of a value |
math::atan() | Computes the arctangent (inverse tangent) of a value |
math::bottom() | Returns the bottom X set of numbers in a set of numbers |
math::ceil() | Rounds a number up to the next largest integer |
math::clamp() | Clamps a value between a specified minimum and maximum |
math::cos() | Computes the cosine of an angle given in radians |
math::cot() | Computes the cotangent of an angle given in radians |
math::deg2rad() | Converts an angle from degrees to radians |
math::e | Constant representing the base of the natural logarithm (Euler's number) |
math::fixed() | Returns a number with the specified number of decimal places |
math::floor() | Rounds a number down to the nearest integer |
math::frac_1_pi | Constant representing the fraction 1/π |
math::frac_1_sqrt_2 | Constant representing the fraction 1/sqrt(2) |
math::frac_2_pi | Constant representing the fraction 2/π |
math::frac_2_sqrt_pi | Constant representing the fraction 2/sqrt(π) |
math::frac_pi_2 | Constant representing the fraction π/2 |
math::frac_pi_3 | Constant representing the fraction π/3 |
math::frac_pi_4 | Constant representing the fraction π/4 |
math::frac_pi_6 | Constant representing the fraction π/6 |
math::frac_pi_8 | Constant representing the fraction π/8 |
math::inf | Constant representing positive infinity |
math::interquartile() | Returns the interquartile of an array of numbers |
math::lerp() | Linearly interpolates between two values based on a factor |
math::lerpangle() | Linearly interpolates between two angles in degrees |
math::ln() | Computes the natural logarithm (base e) of a value |
math::ln_10 | Constant representing the natural logarithm (base e) of 10 |
math::ln_2 | Constant representing the natural logarithm (base e) of 2 |
math::log() | Computes the logarithm of a value with the specified base |
math::log10() | Computes the base-10 logarithm of a value |
math::log10_2 | Constant representing the base-10 logarithm of 2 |
math::log10_e | Constant representing the base-10 logarithm of e, the base of the natural logarithm (Euler’s number) |
math::log2() | Computes the base-2 logarithm of a value |
math::log2_10 | Constant representing the base-2 logarithm of 10 |
math::log2_e | Constant representing the base-2 logarithm of e, the base of the natural logarithm (Euler’s number) |
math::max() | Returns the greatest number from an array of numbers |
math::mean() | Returns the mean of a set of numbers |
math::median() | Returns the median of a set of numbers |
math::midhinge() | Returns the midhinge of a set of numbers |
math::min() | Returns the least number from an array of numbers |
math::mode() | Returns the value that occurs most often in a set of numbers |
math::nearestrank() | Returns the nearest rank of an array of numbers |
math::neg_inf | Constant representing negative infinity |
math::percentile() | Returns the value below which a percentage of data falls |
math::pi | Constant representing the mathematical constant π. |
math::pow() | Returns a number raised to a power |
math::product() | Returns the product of a set of numbers |
math::rad2deg() | Converts an angle from radians to degrees |
math::round() | Rounds a number up or down to the nearest integer |
math::sign() | Returns the sign of a value (-1, 0, or 1) |
math::sin() | Computes the sine of an angle given in radians |
math::spread() | Returns the spread of an array of numbers |
math::sqrt() | Returns the square root of a number |
math::sqrt_2 | Constant representing the square root of 2 |
math::stddev() | Calculates how far a set of numbers are away from the mean |
math::sum() | Returns the total sum of a set of numbers |
math::tan() | Computes the tangent of an angle given in radians. |
math::tau() | Represents the mathematical constant τ, which is equal to 2π |
math::top() | Returns the top X set of numbers in a set of numbers |
math::trimean() | The weighted average of the median and the two quartiles |
math::variance() | Calculates how far a set of numbers are spread out from the mean |
math::abs
The math::abs function returns the absolute value of a number.
The following example shows this function, and its output, when used in a RETURN statement:
math::acos
The math::acos function returns the arccosine (inverse cosine) of a number, which must be in the range -1 to 1. The result is expressed in radians.
The following example shows this function, and its output, when used in a RETURN statement:
math::acot
The math::acot function returns the arccotangent (inverse cotangent) of a number. The result is expressed in radians.
The following example shows this function, and its output, when used in a RETURN statement:
math::asin
The math::asin function returns the arcsine (inverse sine) of a number, which must be in the range -1 to 1. The result is expressed in radians.
The following example shows this function, and its output, when used in a RETURN statement:
math::atan
The math::atan function returns the arctangent (inverse tangent) of a number. The result is expressed in radians.
The following example shows this function, and its output, when used in a RETURN statement:
math::bottom
The math::bottom function returns the bottom X set of numbers in an array of numbers.
The following example shows this function, and its output, when used in a RETURN statement:
math::ceil
The math::ceil function rounds a number up to the next largest whole number.
The following example shows this function, and its output, when used in a RETURN statement:
math::clamp
The math::clamp function constrains a number within the specified range, defined by a minimum and a maximum value. If the number is less than the minimum, it returns the minimum. If it is greater than the maximum, it returns the maximum.
The following example shows this function, and its output, when used in a RETURN statement:
math::cos
The math::cos function returns the cosine of a number, which is assumed to be in radians. The result is a value between -1 and 1.
The following example shows this function, and its output, when used in a RETURN statement:
math::cot
The math::cot function returns the cotangent of a number, which is assumed to be in radians. The cotangent is the reciprocal of the tangent function.
The following example shows this function, and its output, when used in a RETURN statement:
math::deg2rad
The math::deg2rad function converts an angle from degrees to radians.
The following example shows this function, and its output, when used in a RETURN statement:
math::e
The math::e constant represents the base of the natural logarithm (Euler’s number).
The following example shows this function, and its output, when used in a RETURN statement:
math::fixed
The math::fixed function returns a number with the specified number of decimal places.
The following example shows this function, and its output, when used in a RETURN statement:
math::floor
The math::floor function rounds a number down to the nearest integer.
The following example shows this function, and its output, when used in a RETURN statement:
math::frac_1_pi
The math::frac_1_pi constant represents the fraction 1/π.
The following example shows this function, and its output, when used in a RETURN statement:
math::frac_1_sqrt_2
The math::frac_1_sqrt_2 constant represents the fraction 1/sqrt(2).
The following example shows this function, and its output, when used in a RETURN statement:
math::frac_2_pi
The math::frac_2_pi constant represents the fraction 2/π.
The following example shows this function, and its output, when used in a RETURN statement:
math::frac_2_sqrt_pi
The math::frac_2_sqrt_pi constant represents the fraction 2/sqrt(π).
The following example shows this function, and its output, when used in a RETURN statement:
math::frac_pi_2
The math::frac_pi_2 constant represents the fraction π/2.
The following example shows this function, and its output, when used in a RETURN statement:
math::frac_pi_3
The math::frac_pi_3 constant represents the fraction π/3.
The following example shows this function, and its output, when used in a RETURN statement:
math::frac_pi_4
The math::frac_pi_4 constant represents the fraction π/4.
The following example shows this function, and its output, when used in a RETURN statement:
math::frac_pi_6
The math::frac_pi_6 constant represents the fraction π/6.
The following example shows this function, and its output, when used in a RETURN statement:
math::frac_pi_8
The math::frac_pi_8 constant represents the fraction π/8.
The following example shows this function, and its output, when used in a RETURN statement:
math::inf
The math::inf constant represents positive infinity.
The following example shows this function, and its output, when used in a RETURN statement:
math::interquartile
The math::interquartile function returns the interquartile of an array of numbers.
The following example shows this function, and its output, when used in a RETURN statement:
math::lerp
The math::lerp function performs a linear interpolation between two numbers based on a given fraction. The fraction will usually be between 0 and 1, where 0 returns $num_1 and 1 returns $num_2.
The following example shows this function, and its output, when used in a RETURN statement:
The function will not return an error if the third argument is not in the range of 0 to 1. Instead, it will extrapolate linearly beyond the first two numbers.
math::lerpangle
The math::lerpangle function interpolates between two angles ($num_1 and $num_2) by the given fraction. This is useful for smoothly transitioning between angles.
The following example shows this function, and its output, when used in a RETURN statement:
math::ln
The math::ln function returns the natural logarithm (base e) of a number.
The following example shows this function, and its output, when used in a RETURN statement:
math::ln_10
The math::ln_10 constant represents the natural logarithm (base e) of 10.
The following example shows this function, and its output, when used in a RETURN statement:
math::ln_2
The math::ln_2 constant represents the natural logarithm (base e) of 2.
The following example shows this function, and its output, when used in a RETURN statement:
math::log
The math::log function returns the logarithm of a number with a specified base.
The following example shows this function, and its output, when used in a RETURN statement:
math::log10
The math::log10 function returns the base-10 logarithm of a number.
The following example shows this function, and its output, when used in a RETURN statement:
math::log10_2
The math::log10_2 constant represents the base-10 logarithm of 2.
The following example shows this function, and its output, when used in a RETURN statement:
math::log10_e
The math::log10_e constant represents the base-10 logarithm of e, the base of the natural logarithm (Euler’s number).
The following example shows this function, and its output, when used in a RETURN statement:
math::log2
The math::log2 function returns the base-2 logarithm of a number.
The following example shows this function, and its output, when used in a RETURN statement:
math::log2_10
The math::log2_10 constant represents the base-2 logarithm of 10.
The following example shows this function, and its output, when used in a RETURN statement:
math::log2_e
The math::log2_e constant represents the base-2 logarithm of e, the base of the natural logarithm (Euler’s number).
The following example shows this function, and its output, when used in a RETURN statement:
math::max
The math::max function returns the greatest number from an array of numbers.
The following example shows this function, and its output, when used in a RETURN statement:
See also:
array::max, which extracts the greatest value from an array of valuestime::max, which extracts the greatest datetime from an array of datetimes
math::mean
The math::mean function returns the mean of a set of numbers.
The following example shows this function, and its output, when used in a RETURN statement:
math::median
The math::median function returns the median of a set of numbers.
The following example shows this function, and its output, when used in a RETURN statement:
math::midhinge
The math::midhinge function returns the midhinge of an array of numbers.
The following example shows this function, and its output, when used in a RETURN statement:
math::min
The math::min function returns the least number from an array of numbers.
The following example shows this function, and its output, when used in a RETURN statement:
See also:
array::min, which extracts the least value from an array of valuestime::min, which extracts the least datetime from an array of datetimes
math::mode
The math::mode function returns the value that occurs most often in a set of numbers. In case of a tie, the highest one is returned.
The following example shows this function, and its output, when used in a RETURN statement:
math::nearestrank
The math::nearestrank function returns the nearest rank of an array of numbers by pullinng the closest extant record from the dataset at the %-th percentile.
The following example shows this function, and its output, when used in a RETURN statement:
A number for the percentile outside of the range 0 to 100 will return the output NaN.
math::neg_inf
The math::neg_inf constant represents negative infinity.
The following example shows this function, and its output, when used in a RETURN statement:
math::percentile
The math::percentile function returns the value below which a percentage of data falls by getting the N percentile, averaging neighboring records if non-exact.
The following example shows this function, and its output, when used in a RETURN statement:
A number for the percentile outside of the range 0 to 100 will return the output NaN.
math::pi
The math::pi constant represents the mathematical constant π.
The following example shows this function, and its output, when used in a RETURN statement:
math::pow
The math::pow function returns a number raised to the power of a second number.
The following example shows this function, and its output, when used in a RETURN statement:
math::product
The math::product function returns the product of a set of numbers.
The following example shows this function, and its output, when used in a RETURN statement:
math::rad2deg
The math::rad2deg function converts an angle from radians to degrees.
The following example shows this function, and its output, when used in a RETURN statement:
math::round
The math::round function rounds a number up or down to the nearest integer.
The following example shows this function, and its output, when used in a RETURN statement:
math::sign
The math::sign function returns the sign of a number, indicating whether the number is positive, negative, or zero.
It returns 1 for positive numbers, -1 for negative numbers, and 0 for zero.
The following example shows this function, and its output, when used in a RETURN statement:
math::sin
The math::sin function returns the sine of a number, which is assumed to be in radians.
The following example shows this function, and its output, when used in a RETURN statement:
math::spread
The math::spread function returns the spread of an array of numbers.
The following example shows this function, and its output, when used in a RETURN statement:
math::sqrt
The math::sqrt function returns the square root of a number.
The following example shows this function, and its output, when used in a RETURN statement:
math::sqrt_2
The math::sqrt_2 constant represents the square root of 2.
The following example shows this function, and its output, when used in a RETURN statement:
math::stddev
The math::stddev function calculates how far a set of numbers are away from the mean.
The following example shows this function, and its output, when used in a RETURN statement:
As of SurrealDB 3.0.0-beta, this function can be used inside a table view.
math::sum
The math::sum function returns the total sum of a set of numbers.
The following example shows this function, and its output, when used in a RETURN statement:
This function on its own expects a numeric value at each point in an array, meaning that on its own it will not be able to be used on an array that contains NONE or NULL values.
However, NONE and NULL can be coalesced into a default value by using the ?? operator (the "null coalescing operator").
Inside an array the array::map() function can be used to ensure that each value is the number 0 if a NONE or NULL is encountered.
Classic array filtering can also be used to simply remove any NONE or NULL values before math::sum() is called.
With this mapping in place, math::sum() will be guaranteed to work.
math::tan
The math::tan function returns the tangent of a number, which is assumed to be in radians.
The following example shows this function, and its output, when used in a RETURN statement:
math::tau
The math::tau constant represents the mathematical constant τ, which is equal to 2π.
The following example shows this function, and its output, when used in a RETURN statement:
math::top
The math::top function returns the top of an array of numbers.
The following example shows this function, and its output, when used in a RETURN statement:
math::trimean
The math::trimean function returns the trimean of an array of numbers.
The following example shows this function, and its output, when used in a RETURN statement:
math::variance
The math::variance function returns the variance of an array of numbers.
The following example shows this function, and its output, when used in a RETURN statement:
As of SurrealDB 3.0.0-beta, this function can be used inside a table view.