15.4. Mathematical functions

15.4.1. ABS
15.4.2. ROUND
15.4.3. SQRT
15.4.4. SIGN

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

See also Section 11.1.1, “Mathematical operators”.

Figure 15.4. Graph


15.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


15.4.2. 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


15.4.3. 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


15.4.4. 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