GREL Math Functions

Joe Wicentowski edited this page Sep 4, 2015 · 5 revisions
Clone this wiki locally

Math functions supported by the OpenRefine Expression Language (GREL)

See also: All GREL functions.

NOTE: For Integer division and precision you can use simple evaluations such as

1 / 2

which is equivalent to floor(1/2) i.e. it returns only whole number results. If either operand is a floating point number, they both get promoted to floating point and a floating point result is returned. You can use 1 / 2.0 or 1.0 / 2 or 1.0 * x / y (if you're working with variables of unknown contents) to achieve the results you desire.

floor(number d)

Returns the floor of a number. For example, floor(3.7) returns 3 and floor(-3.7) returns -4.

ceil(number d)

Returns the ceiling of a number. For example, ceil(3.7) returns 4 and ceil(-3.7) returns -3.

round(number d)

Rounds a number to the nearest integer. For example, round(3.7) returns 4 and round(-3.7) returns -4.

min(number d1, number d2)

Returns the smaller of two numbers.

max(number d1, number d2)

Returns the larger of two numbers.

mod(number d1, number d2)

Returns d1 modulus d2. For examples, mod(74, 9) returns 2.

ln(number d)

Returns the natural log of d.

log(number d)

Returns the base 10 log of d.

exp(number d)

Returns e raised to the power of d.

pow(number d, number e)

Returns d raised to the power of e. For example, pow(2, 3) returns 8 (2 cubed) and pow(3, 2) returns 9 (3 squared).

The Square Root of any numeric value is expressed pow(value, 0.5)

sum(array a)

Returns the sum of numbers in a.