Числовые функции¶
AQL offers some numeric functions for calculations. The following functions are supported:
ABS()¶
ABS(value) → unsignedValue
Return the absolute part of value.
- value (number): any number, positive or negative
- returns unsignedValue (number): the number without + or - sign
1 2 3 |
|
ACOS()¶
ACOS(value) → num
Return the arccosine of value.
- value (number): the input value
- returns num (number|null): the arccosine of value, or null if value is outside the valid range -1 and 1 (inclusive)
1 2 3 4 |
|
ASIN()¶
ASIN(value) → num
Return the arcsine of value.
- value (number): the input value
- returns num (number|null): the arcsine of value, or null if value is outside the valid range -1 and 1 (inclusive)
1 2 3 4 |
|
ATAN()¶
ATAN(value) → num
Return the arctangent of value.
- value (number): the input value
- returns num (number): the arctangent of value
1 2 3 |
|
ATAN2()¶
ATAN2(y, x) → num
Return the arctangent of the quotient of y and x.
1 2 3 4 |
|
AVERAGE()¶
AVERAGE(numArray) → mean
Return the average (arithmetic mean) of the values in array.
- numArray (array): an array of numbers, null values are ignored
- returns mean (number|null): the average value of numArray. If the array is empty or contains null values only, null will be returned.
1 2 3 |
|
AVG()¶
This is an alias for AVERAGE().
CEIL()¶
CEIL(value) → roundedValue
Return the integer closest but not less than value.
To round downward, see FLOOR().
To round to the nearest integer value, see ROUND().
- value (number): any number
- returns roundedValue (number): the value rounded to the ceiling
1 2 3 4 |
|
COS()¶
COS(value) → num
Return the cosine of value.
- value (number): the input value
- returns num (number): the cosine of value
1 2 3 4 |
|
COSINE_SIMILARITY()¶
Introduced in: v3.9.0
COSINE_SIMILARITY(x, y) → num
Return the cosine similarity between x and y.
To calculate the distance, see L1_DISTANCE() and L2_DISTANCE().
- x (array): first input array
- y (array): second input array
- returns num (number|array): the cosine similarity value. If one of the inputs is a nested (2D) array, then an array is returned. The length of each 2D array row should be equal to the length of second input array in that case.
In case of invalid input values the function returns null and produces a warning.
1 2 3 |
|
DECAY_GAUSS()¶
Introduced in: v3.9.0
DECAY_GAUSS(value, origin, scale, offset, decay) → score
Calculate the score for one or multiple values with a Gaussian function that decays depending on the distance of a numeric value from a user-given origin.
- value (number|array): the input value or an array with input values
- origin (number): the point of origin used for calculating the distance
- scale (number): defines the distance from
origin
+offset
at which the computed score will equal thedecay
parameter - offset (number): the decay function will be evaluated for distance values greater than the defined offset
- decay (number): the decay parameter defines how input values are scored at the distance given by the
scale
parameter - returns score (number|array): a single score or an array of scores depending on the type of the input
value
1 2 3 |
|
DECAY_EXP()¶
Introduced in: v3.9.0
DECAY_EXP(value, origin, scale, offset, decay) → num, array
Calculate the score for one or multiple values with an exponential function that decays depending on the distance of a numeric value from a user-given origin.
- value (number|array): the input value or an array with input values
- origin (number): the point of origin used for calculating the distance
- scale (number): defines the distance from
origin
+offset
at which the computed score will equal thedecay
parameter - offset (number): the decay function will be evaluated for distance values greater than the defined offset
- decay (number): the decay parameter defines how input values are scored at the distance given by the
scale
parameter - returns score (number|array): a single score or an array of scores depending on the type of the input
value
1 2 3 |
|
DECAY_LINEAR()¶
Introduced in: v3.9.0
DECAY_LINEAR(value, origin, scale, offset, decay) → score
Calculate the score for one or multiple values with a linear function that decays depending on the distance of a numeric value from a user-given origin.
- value (number|array): the input value or an array with input values
- origin (number): the point of origin used for calculating the distance
- scale (number): defines the distance from
origin
+offset
at which the computed score will equal thedecay
parameter - offset (number): the decay function will be evaluated for distance values greater than the defined offset
- decay (number): the decay parameter defines how input values are scored at the distance given by the
scale
parameter - returns score (number|array): a single score or an array of scores depending on the type of the input
value
1 2 3 |
|
DEGREES()¶
DEGREES(rad) → num
Return the angle converted from radians to degrees.
- rad (number): the input value
- returns num (number): the angle in degrees
1 2 3 |
|
EXP()¶
EXP(value) → num
Return Euler's constant (2.71828...) raised to the power of value.
- value (number): the input value
- returns num (number): Euler's constant raised to the power of value
1 2 3 |
|
EXP2()¶
EXP2(value) → num
Return 2 raised to the power of value.
- value (number): the input value
- returns num (number): 2 raised to the power of value
1 2 3 |
|
FLOOR()¶
FLOOR(value) → roundedValue
Return the integer closest but not greater than value.
To round upward, see CEIL().
To round to the nearest integer value, see ROUND().
- value (number): any number
- returns roundedValue (number): the value rounded downward
1 2 3 4 |
|
LOG()¶
LOG(value) → num
Return the natural logarithm of value. The base is Euler's constant (2.71828...).
- value (number): the input value
- returns num (number|null): the natural logarithm of value, or null if value is equal or less than 0
1 2 3 |
|
LOG2()¶
LOG2(value) → num
Return the base 2 logarithm of value.
- value (number): the input value
- returns num (number|null): the base 2 logarithm of value, or null if value is equal or less than 0
1 2 3 |
|
LOG10()¶
LOG10(value) → num
Return the base 10 logarithm of value.
- value (number): the input value
- returns num (number): the base 10 logarithm of value, or null if value is equal or less than 0
1 2 3 |
|
L1_DISTANCE()¶
Introduced in: v3.9.0
L1_DISTANCE(x, y) → num
Return the Manhattan distance between x and y.
To calculate the similarity, see COSINE_SIMILARITY().
- x (array): first input array
- y (array): second input array
- returns num (number|array): the L1 distance value. If one of the inputs is a nested (2D) array, then an array is returned. The length of each inner array should be equal to the length of second input array in that case.
In case of invalid input values the function returns null and produces a warning.
1 2 3 |
|
L2_DISTANCE()¶
Introduced in: v3.9.0
L2_DISTANCE(x,y) → num
Return the Euclidean distance between x and y.
To calculate the similarity, see COSINE_SIMILARITY().
- x (array): first input array
- y (array): second input array
- returns num (number|array): the L2 distance value. If one of the inputs is a nested (2D) array, then an array is returned. The length of each inner array should be equal to the length of second input array in that case.
In case of invalid input values the function returns null and produces a warning.
1 2 3 |
|
MAX()¶
MAX(anyArray) → max
Return the greatest element of anyArray. The array is not limited to numbers. Also see type and value order.
- anyArray (array): an array of numbers, null values are ignored
- returns max (any|null): the element with the greatest value. If the array is empty or contains null values only, the function will return null.
1 2 |
|
MEDIAN()¶
MEDIAN(numArray) → median
Return the median value of the values in array.
The array is sorted and the element in the middle is returned. If the array has an even length of elements, the two center-most elements are interpolated by calculating the average value (arithmetic mean).
- numArray (array): an array of numbers, null values are ignored
- returns median (number|null): the median of numArray. If the array is empty or contains null values only, the function will return null.
1 2 3 4 |
|
MIN()¶
MIN(anyArray) → min
Return the smallest element of anyArray. The array is not limited to numbers. Also see type and value order.
- anyArray (array): an array of numbers, null values are ignored
- returns min (any|null): the element with the smallest value. If the array is empty or contains null values only, the function will return null.
1 2 |
|
PERCENTILE()¶
PERCENTILE(numArray, n, method) → percentile
Return the nth percentile of the values in numArray.
- numArray (array): an array of numbers, null values are ignored
- n (number): must be between 0 (excluded) and 100 (included)
- method (string, optional): "rank" (default) or "interpolation"
- returns percentile (number|null): the nth percentile, or null if the array is empty or only null values are contained in it or the percentile cannot be calculated
1 2 3 |
|
PI()¶
PI() → pi
Return pi.
- returns pi (number): the first few significant digits of pi (3.141592653589793)
1 |
|
POW()¶
POW(base, exp) → num
Return the base to the exponent exp.
- base (number): the base value
- exp (number): the exponent value
- returns num (number): the exponentiated value
1 2 3 |
|
PRODUCT()¶
Introduced in: v3.7.2
PRODUCT(numArray) → product
Return the product of the values in array.
- numArray (array): an array of numbers, null values are ignored
- returns product (number): the product of all values in numArray. If the array is empty or only null values are contained in the array, 1 will be returned.
1 2 3 |
|
RADIANS()¶
RADIANS(deg) → num
Return the angle converted from degrees to radians.
- deg (number): the input value
- returns num (number): the angle in radians
1 2 3 |
|
RAND()¶
RAND() → randomNumber
Return a pseudo-random number between 0 and 1.
- returns randomNumber (number): a number greater than 0 and less than 1
1 2 |
|
Complex example:
1 2 3 4 5 6 7 8 9 |
|
Result:
1 2 3 4 5 6 |
|
RANGE()¶
RANGE(start, stop, step) → numArray
Return an array of numbers in the specified range, optionally with increments other than 1. The start and stop arguments are truncated to integers unless a step argument is provided.
Also see the range operator for ranges with integer bounds and a step size of 1.
- start (number): the value to start the range at (inclusive)
- stop (number): the value to end the range with (inclusive)
- step (number, optional): how much to increment in every step, the default is 1.0
- returns numArray (array): all numbers in the range as array
1 2 3 4 5 6 7 |
|
ROUND()¶
ROUND(value) → roundedValue
Return the integer closest to value.
- value (number): any number
- returns roundedValue (number): the value rounded to the closest integer
1 2 3 4 |
|
Rounding towards zero, also known as trunc() in C/C++, can be achieved with a combination of the ternary operator, CEIL() and FLOOR():
1 |
|
SIN()¶
SIN(value) → num
Return the sine of value.
- value (number): the input value
- returns num (number): the sine of value
1 2 3 4 |
|
SQRT()¶
SQRT(value) → squareRoot
Return the square root of value.
- value (number): a number
- returns squareRoot (number): the square root of value
1 2 |
|
Other roots can be calculated with POW() like POW(value, 1/n)
:
1 2 3 4 5 6 7 8 |
|
STDDEV_POPULATION()¶
STDDEV_POPULATION(numArray) → num
Return the population standard deviation of the values in array.
- numArray (array): an array of numbers, null values are ignored
- returns num (number|null): the population standard deviation of numArray. If the array is empty or only null values are contained in the array, null will be returned.
1 |
|
STDDEV_SAMPLE()¶
STDDEV_SAMPLE(numArray) → num
Return the sample standard deviation of the values in array.
- numArray (array): an array of numbers, null values are ignored
- returns num (number|null): the sample standard deviation of numArray. If the array is empty or only null values are contained in the array, null will be returned.
1 |
|
STDDEV()¶
This is an alias for STDDEV_POPULATION().
SUM()¶
SUM(numArray) → sum
Return the sum of the values in array.
- numArray (array): an array of numbers, null values are ignored
- returns sum (number): the total of all values in numArray. If the array is empty or only null values are contained in the array, 0 will be returned.
1 2 3 |
|
TAN()¶
TAN(value) → num
Return the tangent of value.
- value (number): the input value
- returns num (number): the tangent of value
1 2 3 |
|
VARIANCE_POPULATION()¶
VARIANCE_POPULATION(numArray) → num
Return the population variance of the values in array.
- numArray (array): an array of numbers, null values are ignored
- returns num (number|null): the population variance of numArray. If the array is empty or only null values are contained in the array, null will be returned.
1 |
|
VARIANCE_SAMPLE()¶
VARIANCE_SAMPLE(array) → num
Return the sample variance of the values in array.
- numArray (array): an array of numbers, null values are ignored
- returns num (number|null): the sample variance of numArray. If the array is empty or only null values are contained in the array, null will be returned.
1 |
|
VARIANCE()¶
This is an alias for VARIANCE_POPULATION().