Documentation SurrealQL Functions Math functions

## 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::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::fixed()` Returns a number with the specified number of decimal places
`math::floor()` Rounds a number down to the next largest integer
`math::interquartile()` Returns the interquartile of an array of numbers
`math::max()` Returns the maximum number in a set 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 minimum number in a set 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::percentile()` Returns the value below which a percentage of data falls
`math::product()` Returns the product of a set of numbers
`math::round()` Rounds a number up or down to the nearest integer
`math::spread()` Returns the spread of an array of numbers
`math::sqrt()` Returns the square root of a number
`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::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.

``math::abs(number) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::abs(13.746189);``
``13``

### math::bottom

The `math::bottom` function returns the bottom X set of numbers in a set of numbers

``math::bottom(array{{ "<" }}number>, number) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::bottom([1, 2, 3], 2);``
``[ 2, 1 ]``

### math::ceil

The `math::ceil` function rounds a number up to the next largest integer.

``math::ceil(number) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::ceil(13.146572);``
``14``

### math::fixed

The `math::fixed` function returns a number with the specified number of decimal places.

``math::fixed(number, number) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::fixed(13.146572, 2);``
``13.15``

### math::floor

The `math::floor` function rounds a number down to the next largest integer.

``math::floor(number) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::floor(13.746189);``
``13``

### math::interquartile

The `math::interquartile` function returns the interquartile of an array of numbers.

``math::interquartile(array{{ "<" }}number>) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::interquartile([ 1, 40, 60, 10, 2, 901 ]);``
``48.5``

### math::max

The `math::max` function returns the maximum number in a set of numbers.

``math::max(number) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::max([ 26.164, 13.746189, 23, 16.4, 41.42 ]);``
``41.42``

### math::mean

The `math::mean` function returns the mean of a set of numbers.

``math::mean(array) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::mean([ 26.164, 13.746189, 23, 16.4, 41.42 ]);``
``24.1460378``

### math::median

The `math::median` function returns the median of a set of numbers.

``math::median(array) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::median([ 26.164, 13.746189, 23, 16.4, 41.42 ]);``
``23``

### math::midhinge

The `math::midhinge` function returns the midhinge of an array of numbers.

``math::midhinge(array{{ "<" }}number>) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::midhinge([ 1, 40, 60, 10, 2, 901 ]);``
``25.75``

### math::min

The `math::min` function returns the minimum number in a set of numbers.

``math::min(array) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::min([ 26.164, 13.746189, 23, 16.4, 41.42 ]);``
``13.746189``

### math::mode

The `math::mode` function returns the value that occurs most often in a set of numbers.

``math::mode(array{{ "<" }}number>) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::mode([ 1, 40, 60, 10, 2, 901 ]);``
``901``

### math::nearestrank

The `math::nearestrank` function returns the nearestrank of an array of numbers.

``math::nearestrank(array{{ "<" }}number>, number) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::nearestrank([1, 40, 60, 10, 2, 901], 50);``
``10``

### math::percentile

The `math::percentile` function returns the value below which a percentage of data falls.

``math::percentile(array{{ "<" }}number>, number) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::percentile([1, 40, 60, 10, 2, 901], 50);``
``10``

### math::product

The `math::product` function returns the product of a set of numbers.

``math::product(array) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::product([ 26.164, 13.746189, 23, 16.4, 41.42 ]);``
``5619119.004884841504``

### math::round

The `math::round` function rounds a number up or down to the nearest integer.

``math::round(number) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::round(13.53124);``
``14``

The `math::spread` function returns the spread of an array of numbers.

``math::spread(array{{ "<" }}number>) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::spread([ 1, 40, 60, 10, 2, 901 ]);``
``900``

### math::sqrt

The `math::sqrt` function returns the square root of a number.

``math::sqrt(number) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::sqrt(15);``
``3.872983346207417``

### math::stddev

The `math::stddev` function calculates how far a set of numbers are away from the mean.

``math::stddev(array{{ "<" }}number>) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::stddev([ 1, 40, 60, 10, 2, 901 ]);``
``359.3716738976515383200802748740764743708578424033151316067128042080419093950971134866088206928833419``

### math::sum

The `math::sum` function returns the total sum of a set of numbers.

``math::sum(array) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::sum([ 26.164, 13.746189, 23, 16.4, 41.42 ]);``
``120.730189``

### math::top

The `math::top` function returns the top of an array of numbers.

``math::top(array{{ "<" }}number>, number) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::top([1, 40, 60, 10, 2, 901], 3);``
``[ 40, 901, 60 ]``

### math::trimean

The `math::trimean` function returns the trimean of an array of numbers.

``math::trimean(array{{ "<" }}number>) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::trimean([ 1, 40, 60, 10, 2, 901 ]);``
``32.875``

### math::variance

The `math::variance` function returns the variance of an array of numbers.

``math::variance(array{{ "<" }}number>) -> number``

The following example shows this function, and its output, when used in a `RETURN` statement:

``RETURN math::variance([ 1, 40, 60, 10, 2, 901 ]);``
``129148``