16.4. Mathematical functions

16.4.1. ABS
16.4.2. ACOS
16.4.3. ASIN
16.4.4. ATAN
16.4.5. COS
16.4.6. COT
16.4.7. DEGREES
16.4.8. E
16.4.9. EXP
16.4.10. FLOOR
16.4.11. LOG
16.4.12. LOG10
16.4.13. PI
16.4.14. RADIANS
16.4.15. RAND
16.4.16. ROUND
16.4.17. SIGN
16.4.18. SIN
16.4.19. SQRT
16.4.20. TAN

These functions all operate on numerical expressions only, and will return an error if used on any other values.

See also Section 12.1.1, “Mathematical operators”.

Figure 16.4. Graph


16.4.1. ABS

ABS returns the absolute value of a number.

Syntax: ABS( expression )

Arguments:

  • expression: A numeric expression.

Query. 

MATCH a, e
WHERE a.name = 'Alice' AND e.name = 'Eskil'
RETURN a.age, e.age, abs(a.age - e.age)

The absolute value of the age difference is returned.

Result

a.agee.ageabs(a.age - e.age)
1 row

38

41

3.0


16.4.2. ACOS

ACOS returns the arccosine of the expression, in radians.

Syntax: ACOS( expression )

Arguments:

  • expression: A numeric expression.

Query. 

START a=node(3)
RETURN acos(0.5)

The arccosine of 0.5.

Result

acos(0.5)
1 row

1.0471975511965979


16.4.3. ASIN

ASIN returns the arcsine of the expression, in radians.

Syntax: ASIN( expression )

Arguments:

  • expression: A numeric expression.

Query. 

START a=node(3)
RETURN asin(0.5)

The arcsine of 0.5.

Result

asin(0.5)
1 row

0.5235987755982989


16.4.4. ATAN

ATAN returns the arctangent of the expression, in radians.

Syntax: ATAN( expression )

Arguments:

  • expression: A numeric expression.

Query. 

START a=node(3)
RETURN atan(0.5)

The arctangent of 0.5.

Result

atan(0.5)
1 row

0.4636476090008061


16.4.5. COS

COS returns the cosine of the expression.

Syntax: COS( expression )

Arguments:

  • expression: A numeric expression.

Query. 

START a=node(3)
RETURN cos(0.5)

The cosine of 0.5 is returned.

Result

cos(0.5)
1 row

0.8775825618903728


16.4.6. COT

COT returns the cotangent of the expression.

Syntax: COT( expression )

Arguments:

  • expression: A numeric expression.

Query. 

START a=node(3)
RETURN cot(0.5)

The cotangent of 0.5 is returned.

Result

cot(0.5)
1 row

1.830487721712452


16.4.7. DEGREES

DEGREES converts radians to degrees.

Syntax: DEGREES( expression )

Arguments:

  • expression: A numeric expression.

Query. 

START a=node(3)
RETURN degrees(3.14159)

The number of degrees in something close to pi.

Result

degrees(3.14159)
1 row

179.99984796050427


16.4.8. E

E returns the constant, e.

Syntax: E( expression )

Arguments:

Query. 

START a=node(3)
RETURN e()

The constant e is returned (the base of natural log).

Result

e()
1 row

2.718281828459045


16.4.9. EXP

EXP returns the value e raised to the power of the expression.

Syntax: EXP( expression )

Arguments:

  • expression: A numeric expression.

Query. 

START a=node(3)
RETURN exp(2)

The exp of 2 is returned: e^2.

Result

exp(2)
1 row

7.38905609893065


16.4.10. FLOOR

FLOOR returns the greatest integer less than or equal to the expression.

Syntax: FLOOR( expression )

Arguments:

  • expression: A numeric expression.

Query. 

START a=node(3)
RETURN floor(0.9)

The floor of 0.9 is returned.

Result

floor(0.9)
1 row

0.0


16.4.11. LOG

LOG returns the natural logarithm of the expression.

Syntax: LOG( expression )

Arguments:

  • expression: A numeric expression.

Query. 

START a=node(3)
RETURN log(27)

The log of 27 is returned.

Result

log(27)
1 row

3.295836866004329


16.4.12. LOG10

LOG10 returns the base 10 logarithm of the expression.

Syntax: LOG10( expression )

Arguments:

  • expression: A numeric expression.

Query. 

START a=node(3)
RETURN log10(27)

The log10 of 27 is returned.

Result

log10(27)
1 row

1.4313637641589874


16.4.13. PI

PI returns the mathmatical constant pi.

Syntax: PI()

Arguments:

Query. 

START a=node(3)
RETURN pi()

The constant pi is returned.

Result

pi()
1 row

3.141592653589793


16.4.14. RADIANS

RADIANS converts degrees to radians.

Syntax: RADIANS( expression )

Arguments:

  • expression: A numeric expression.

Query. 

START a=node(3)
RETURN radians(180)

The number of radians in 180 is returned (pi).

Result

radians(180)
1 row

3.141592653589793


16.4.15. RAND

RAND returns a random double between 0 and 1.0.

Syntax: RAND( expression )

Arguments:

  • expression: A numeric expression.

Query. 

START a=node(3)
RETURN rand() AS x1

Two random numbers are returned.

Result

x1
1 row

0.8969509843435297


16.4.16. ROUND

ROUND returns the numerical expression, rounded to the nearest integer.

Syntax: ROUND( expression )

Arguments:

  • expression: A numerical expression.

Query. 

MATCH a
RETURN round(3.141592)
LIMIT 1

Result

round(3.141592)
1 row

3


16.4.17. SIGN

SIGN returns the signum of a number — zero if the expression is zero, -1 for any negative number, and 1 for any positive number.

Syntax: SIGN( expression )

Arguments:

  • expression: A numerical expression

Query. 

MATCH n
RETURN sign(-17), sign(0.1)
LIMIT 1

Result

sign(-17)sign(0.1)
1 row

-1.0

1.0


16.4.18. SIN

SIN returns the sine of the expression.

Syntax: SIN( expression )

Arguments:

  • expression: A numeric expression.

Query. 

START a=node(3)
RETURN sin(0.5)

The sine of 0.5 is returned.

Result

sin(0.5)
1 row

0.479425538604203


16.4.19. SQRT

SQRT returns the square root of a number.

Syntax: SQRT( expression )

Arguments:

  • expression: A numerical expression

Query. 

MATCH n
RETURN sqrt(256)
LIMIT 1

Result

sqrt(256)
1 row

16.0


16.4.20. TAN

TAN returns the tangent of the expression.

Syntax: TAN( expression )

Arguments:

  • expression: A numeric expression.

Query. 

START a=node(3)
RETURN tan(0.5)

The tangent of 0.5 is returned.

Result

tan(0.5)
1 row

0.5463024898437905