Skip to content

Built-in math functions

Function descriptions

Nebula Graph supports the following built-in math functions:

Function Description
double abs(double x) Returns the absolute value of the argument.
double floor(double x) Returns the largest integer value smaller than or equal to the argument. (Rounds down)
double ceil(double x) Returns the smallest integer greater than or equal to the argument. (Rounds up)
double round(double x) Returns the integer value nearest to the argument. Returns a number farther away from 0 if the argument is in the middle.
double sqrt(double x) Returns the square root of the argument.
double cbrt(double x) Returns the cubic root of the argument.
double hypot(double x, double y) Returns the hypotenuse of a right-angled triangle.
double pow(double x, double y) Returns the result of \(x^y\).
double exp(double x) Returns the result of \(e^x\).
double exp2(double x) Returns the result of \(2^x\).
double log(double x) Returns the base-e logarithm of the argument.
double log2(double x) Returns the base-2 logarithm of the argument.
double log10(double x) Returns the base-10 logarithm of the argument.
double sin(double x) Returns the sine of the argument.
double asin(double x) Returns the inverse sine of the argument.
double cos(double x) Returns the cosine of the argument.
double acos(double x) Returns the inverse cosine of the argument.
double tan(double x) Returns the tangent of the argument.
double atan(double x) Returns the inverse tangent of the argument.
double rand() Returns a random floating point number in the range from 0 (inclusive) to 1 (exclusive); i.e.[0,1).
int rand32(int min, int max) Returns a random 32-bit integer in [min, max).
If you set only one argument, it is parsed as max and min is 0 by default.
If you set no argument, the system returns a random signed 32-bit integer.
int rand64(int min, int max) Returns a random 64-bit integer in [min, max).
If you set only one argument, it is parsed as max and min is 0 by default.
If you set no argument, the system returns a random signed 64-bit integer.
collect() Puts all the collected values into a list.
avg() Returns the average value of the argument.
count() Returns the number of records.
max() Returns the maximum value.
min() Returns the minimum value.
std() Returns the population standard deviation.
sum() Returns the sum value.
bit_and() Bitwise AND.
bit_or() Bitwise OR.
bit_xor() Bitwise XOR.
int size() Returns the number of elements in a list or a map.
int range(int start, int end, int step) Returns a list of integers from [start,end] in the specified steps. step is 1 by default.
int sign(double x) Returns the signum of the given number.
If the number is 0, the system returns 0.
If the number is negative, the system returns -1.
If the number is positive, the system returns 1.
double e() Returns the base of the natural logarithm, e (2.718281828459045).
double pi() Returns the mathematical constant pi (3.141592653589793).
double radians() Converts degrees to radians. radians(180) returns 3.141592653589793.

Note

If the argument is NULL, the output is undefined.

Example

# The following statement supports aggregate functions.
nebula>  GO FROM "player100" OVER follow YIELD dst(edge) AS dst, properties($$).age AS age \
         | GROUP BY $-.dst \
         YIELD \
         $-.dst AS dst, \
         toInteger((sum($-.age)/count($-.age)))+avg(distinct $-.age+1)+1 AS statistics;
+-------------+------------+
| dst         | statistics |
+-------------+------------+
| "player125" | 84.0       |
| "player101" | 74.0       |
+-------------+------------+
Got 2 rows (time spent 4739/5064 us)

Last update: November 1, 2021
Back to top