Built-in math functions¶
This topic describes the built-in math functions supported by NebulaGraph.
abs()¶
abs() returns the absolute value of the argument.
Syntax: abs(<expression>)
expression
: An expression of which the result type is double.
- Result type: Double
Example:
nebula> RETURN abs(-10);
+------------+
| abs(-(10)) |
+------------+
| 10 |
+------------+
nebula> RETURN abs(5-6);
+------------+
| abs((5-6)) |
+------------+
| 1 |
+------------+
floor()¶
floor() returns the largest integer value smaller than or equal to the argument.(Rounds down)
Syntax: floor(<expression>)
expression
: An expression of which the result type is double.
- Result type: Double
Example:
nebula> RETURN floor(9.9);
+------------+
| floor(9.9) |
+------------+
| 9.0 |
+------------+
ceil()¶
ceil() returns the smallest integer greater than or equal to the argument.(Rounds up)
Syntax: ceil(<expression>)
expression
: An expression of which the result type is double.
- Result type: Double
Example:
nebula> RETURN ceil(9.1);
+-----------+
| ceil(9.1) |
+-----------+
| 10.0 |
+-----------+
round()¶
round() returns the rounded value of the specified number. Pay attention to the floating-point precision when using this function.
Syntax: round(<expression>, <digit>)
expression
: An expression of which the result type is double.
digit
: Decimal digits. Ifdigit
is less than 0, round at the left of the decimal point.
- Result type: Double
Example:
nebula> RETURN round(314.15926, 2);
+--------------------+
| round(314.15926,2) |
+--------------------+
| 314.16 |
+--------------------+
nebula> RETURN round(314.15926, -1);
+-----------------------+
| round(314.15926,-(1)) |
+-----------------------+
| 310.0 |
+-----------------------+
sqrt()¶
sqrt() returns the square root of the argument.
Syntax: sqrt(<expression>)
expression
: An expression of which the result type is double.
- Result type: Double
Example:
nebula> RETURN sqrt(9);
+---------+
| sqrt(9) |
+---------+
| 3.0 |
+---------+
cbrt()¶
cbrt() returns the cubic root of the argument.
Syntax: cbrt(<expression>)
expression
: An expression of which the result type is double.
- Result type: Double
Example:
nebula> RETURN cbrt(8);
+---------+
| cbrt(8) |
+---------+
| 2.0 |
+---------+
hypot()¶
hypot() returns the hypotenuse of a right-angled triangle.
Syntax: hypot(<expression_x>,<expression_y>)
expression_x
,expression_y
: An expression of which the result type is double. They represent the side lengths x and y of a right triangle.
- Result type: Double
Example:
nebula> RETURN hypot(3,2*2);
+----------------+
| hypot(3,(2*2)) |
+----------------+
| 5.0 |
+----------------+
pow()¶
pow() returns the result of xy.
Syntax: pow(<expression_x>,<expression_y>,)
expression_x
: An expression of which the result type is double. It represents the basex
.
expression_y
: An expression of which the result type is double. It represents the exponentialy
.
- Result type: Double
Example:
nebula> RETURN pow(3,3);
+----------+
| pow(3,3) |
+----------+
| 27 |
+----------+
exp()¶
exp() returns the result of ex.
Syntax: exp(<expression>)
expression
: An expression of which the result type is double. It represents the exponentialx
.
- Result type: Double
Example:
nebula> RETURN exp(2);
+------------------+
| exp(2) |
+------------------+
| 7.38905609893065 |
+------------------+
exp2()¶
exp2() returns the result of 2x.
Syntax: exp2(<expression>)
expression
: An expression of which the result type is double. It represents the exponentialx
.
- Result type: Double
Example:
nebula> RETURN exp2(3);
+---------+
| exp2(3) |
+---------+
| 8.0 |
+---------+
log()¶
log() returns the base-e logarithm of the argument. (\(log_{e}{N}\))
Syntax: log(<expression>)
expression
: An expression of which the result type is double. It represents the antilogarithmN
.
- Result type: Double
Example:
nebula> RETURN log(8);
+--------------------+
| log(8) |
+--------------------+
| 2.0794415416798357 |
+--------------------+
log2()¶
log2() returns the base-2 logarithm of the argument. (\(log_{2}{N}\))
Syntax: log2(<expression>)
expression
: An expression of which the result type is double. It represents the antilogarithmN
.
- Result type: Double
Example:
nebula> RETURN log2(8);
+---------+
| log2(8) |
+---------+
| 3.0 |
+---------+
log10()¶
log10() returns the base-10 logarithm of the argument. (\(log_{10}{N}\))
Syntax: log10(<expression>)
expression
: An expression of which the result type is double. It represents the antilogarithmN
.
- Result type: Double
Example:
nebula> RETURN log10(100);
+------------+
| log10(100) |
+------------+
| 2.0 |
+------------+
sin()¶
sin() returns the sine of the argument. Users can convert angles to radians using the function radians()
.
Syntax: sin(<expression>)
expression
: An expression of which the result type is double.
- Result type: Double
Example:
nebula> RETURN sin(3);
+--------------------+
| sin(3) |
+--------------------+
| 0.1411200080598672 |
+--------------------+
asin()¶
asin() returns the inverse sine of the argument. Users can convert angles to radians using the function radians()
.
Syntax: asin(<expression>)
expression
: An expression of which the result type is double.
- Result type: Double
Example:
nebula> RETURN asin(0.5);
+--------------------+
| asin(0.5) |
+--------------------+
| 0.5235987755982989 |
+--------------------+
cos()¶
cos() returns the cosine of the argument. Users can convert angles to radians using the function radians()
.
Syntax: cos(<expression>)
expression
: An expression of which the result type is double.
- Result type: Double
Example:
nebula> RETURN cos(0.5);
+--------------------+
| cos(0.5) |
+--------------------+
| 0.8775825618903728 |
+--------------------+
acos()¶
acos() returns the inverse cosine of the argument. Users can convert angles to radians using the function radians()
.
Syntax: acos(<expression>)
expression
: An expression of which the result type is double.
- Result type: Double
Example:
nebula> RETURN acos(0.5);
+--------------------+
| acos(0.5) |
+--------------------+
| 1.0471975511965979 |
+--------------------+
tan()¶
tan() returns the tangent of the argument. Users can convert angles to radians using the function radians()
.
Syntax: tan(<expression>)
expression
: An expression of which the result type is double.
- Result type: Double
Example:
nebula> RETURN tan(0.5);
+--------------------+
| tan(0.5) |
+--------------------+
| 0.5463024898437905 |
+--------------------+
atan()¶
atan() returns the inverse tangent of the argument. Users can convert angles to radians using the function radians()
.
Syntax: atan(<expression>)
expression
: An expression of which the result type is double.
- Result type: Double
Example:
nebula> RETURN atan(0.5);
+--------------------+
| atan(0.5) |
+--------------------+
| 0.4636476090008061 |
+--------------------+
rand()¶
rand() returns a random floating point number in the range from 0 (inclusive) to 1 (exclusive); i.e.[0,1).
Syntax: rand()
- Result type: Double
Example:
nebula> RETURN rand();
+--------------------+
| rand() |
+--------------------+
| 0.6545837172298736 |
+--------------------+
rand32()¶
rand32() returns a random 32-bit integer in [min, max)
.
Syntax: rand32(<expression_min>,<expression_max>)
expression_min
: An expression of which the result type is int. It represents the minimummin
.
expression_max
: An expression of which the result type is int. It represents the maximummax
.
- Result type: Int
- If you set only one argument, it is parsed as
max
andmin
is0
by default. If you set no argument, the system returns a random signed 32-bit integer.
Example:
nebula> RETURN rand32(1,100);
+---------------+
| rand32(1,100) |
+---------------+
| 63 |
+---------------+
rand64()¶
rand64() returns a random 64-bit integer in [min, max)
.
Syntax: rand64(<expression_min>,<expression_max>)
expression_min
: An expression of which the result type is int. It represents the minimummin
.
expression_max
: An expression of which the result type is int. It represents the maximummax
.
- Result type: Int
- If you set only one argument, it is parsed as
max
andmin
is0
by default. If you set no argument, the system returns a random signed 64-bit integer.
Example:
nebula> RETURN rand64(1,100);
+---------------+
| rand64(1,100) |
+---------------+
| 34 |
+---------------+
bit_and()¶
bit_and() returns the result of bitwise AND.
Syntax: bit_and(<expression_1>,<expression_2>)
expression_1
,expression_2
: An expression of which the result type is int.
- Result type: Int
Example:
nebula> RETURN bit_and(5,6);
+--------------+
| bit_and(5,6) |
+--------------+
| 4 |
+--------------+
bit_or()¶
bit_or() returns the result of bitwise OR.
Syntax: bit_or(<expression_1>,<expression_2>)
expression_1
,expression_2
: An expression of which the result type is int.
- Result type: Int
Example:
nebula> RETURN bit_or(5,6);
+-------------+
| bit_or(5,6) |
+-------------+
| 7 |
+-------------+
bit_xor()¶
bit_xor() returns the result of bitwise XOR.
Syntax: bit_xor(<expression_1>,<expression_2>)
expression_1
,expression_2
: An expression of which the result type is int.
- Result type: Int
Example:
nebula> RETURN bit_xor(5,6);
+--------------+
| bit_xor(5,6) |
+--------------+
| 3 |
+--------------+
size()¶
size() returns the number of elements in a list or a map, or the length of a string.
Syntax: size({<expression>|<string>})
expression
: An expression for a list or map.string
: A specified string.
- Result type: Int
Example:
nebula> RETURN size([1,2,3,4]);
+-----------------+
| size([1,2,3,4]) |
+-----------------+
| 4 |
+-----------------+
nebula> RETURN size("basketballplayer") as size;
+------+
| size |
+------+
| 16 |
+------+
range()¶
range() returns a list of integers from [start,end]
in the specified steps.
Syntax: range(<expression_start>,<expression_end>[,<expression_step>])
expression_start
: An expression of which the result type is int. It represents the starting valuestart
.
expression_end
: An expression of which the result type is int. It represents the end valueend
.
expression_step
: An expression of which the result type is int. It represents the step sizestep
,step
is 1 by default.
- Result type: List
Example:
nebula> RETURN range(1,3*3,2);
+------------------+
| range(1,(3*3),2) |
+------------------+
| [1, 3, 5, 7, 9] |
+------------------+
sign()¶
sign() 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
.
Syntax: sign(<expression>)
expression
: An expression of which the result type is double.
- Result type: Int
Example:
nebula> RETURN sign(10);
+----------+
| sign(10) |
+----------+
| 1 |
+----------+
e()¶
e() returns the base of the natural logarithm, e (2.718281828459045).
Syntax: e()
- Result type: Double
Example:
nebula> RETURN e();
+-------------------+
| e() |
+-------------------+
| 2.718281828459045 |
+-------------------+
pi()¶
pi() returns the mathematical constant pi (3.141592653589793).
Syntax: pi()
- Result type: Double
Example:
nebula> RETURN pi();
+-------------------+
| pi() |
+-------------------+
| 3.141592653589793 |
+-------------------+
radians()¶
radians() converts angles to radians.
Syntax: radians(<angle>)
- Result type: Double
Example:
nebula> RETURN radians(180);
+-------------------+
| radians(180) |
+-------------------+
| 3.141592653589793 |
+-------------------+