# Math

> Source: https://docs.recombee.com/reql/functions/math

> For the complete documentation index, see [llms.txt](/llms.txt).

# Math

| Name                      | Description                                                           | Example                 |
| ------------------------- | --------------------------------------------------------------------- | ----------------------- |
| [max](#reql-func-max)     | Returns the maximum of _n_ arguments                                  | max(147,42,81.9) == 147 |
| [min](#reql-func-min)     | Returns the minimum of _n_ arguments                                  | min(147,42,81.9) == 42  |
| [avg](#reql-func-avg)     | Returns the average of _n_ numbers                                    | avg(2, 4) == 3          |
| [round](#reql-func-round) | Returns closest integer                                               | round(4.5) == 5         |
| [floor](#reql-func-floor) | Returns largest preceding integer                                     | floor(4.3) == 4         |
| [ceil](#reql-func-ceil)   | Returns smallest following integer                                    | ceil(4.3) == 5          |
| [abs](#reql-func-abs)     | Returns non-negative value of the argument without regard to its sign | abs(-4.3) == 4.3        |
| [sqrt](#reql-func-sqrt)   | Returns the square root of the argument                               | sqrt(4) == 2            |
| [pow](#reql-func-pow)     | Returns 𝑓𝑖𝑟𝑠𝑡\_𝑎𝑟𝑔𝑢𝑚𝑒𝑛𝑡𝑠𝑒𝑐𝑜𝑛𝑑\_𝑎𝑟𝑔𝑢𝑚𝑒𝑛𝑡    | pow(10,3) == 1000       |
| [log](#reql-func-log)     | Returns the logarithm of the argument                                 | log(1000) == 3          |

## Max

Returns the maximum of n arguments.

Alternatively, if you provide a single set/array, it returns the maximum of its values.

The arguments must be comparable using `>`.

### Definition

```
max(val1, val2, [val3, val4 ...])

max(set/array value)
```

| Argument | Type |
| -------- | ---- |
| val1     | any  |
| val2     | any  |
| ...      |      |

### Example

```
max(147,42,81.9) == 147
max("abc", "bac") == "bac"
max({5}, {}) == {5}

max({147,42,81.9}) == 147
```

## Min

Returns the minimum of _n_ arguments.

Alternatively, if you provide a single set/array, it returns the minimum of its values.

The arguments must be comparable using `<`.

### Definition

```
min(val1, val2, [val3, val4 ...])

min(set/array value)
```

| Argument | Type |
| -------- | ---- |
| val1     | any  |
| val2     | any  |
| ...      |      |

### Example

```
min(147,42,81.9) == 42
min("abc", "bac") == "abc"
min({5}, {}) == {}

min({147,42,81.9}) == 42
```

## Avg

Returns the average of _n_ numbers.

Alternatively, if you provide a single set/array of values, it returns the average of its values.

### Definition

```
avg(val1, val2, [val3, val4 ...])

avg(set/array value)
```

| Argument | Type |
| -------- | ---- |
| val1     | any  |
| val2     | any  |
| ...      |      |

### Example

```
avg(2, 1, 5) == 4
avg({2, 1, 5}) == 4
```

## Round

### Definition

```
round(x)
```

| Argument         | Type   | Meaning              |
| ---------------- | ------ | -------------------- |
| x                | number |                      |
| **Return value** | number | Integer closest to x |

### Example

All the following expressions result in `true`:

```
round(4.3) == 4

round(4.5) == 5
```

## Floor

### Definition

```
floor(x)
```

| Argument         | Type   | Meaning                     |
| ---------------- | ------ | --------------------------- |
| x                | number |                             |
| **Return value** | number | Largest integer preceding x |

### Example

All the following expressions result in `true`:

```
floor(4.3) == 4

floor(4.5) == 4
```

## Ceil

### Definition

```
ceil(x)
```

| Argument         | Type   | Meaning                      |
| ---------------- | ------ | ---------------------------- |
| x                | number |                              |
| **Return value** | number | Smallest integer following x |

### Example

All the following expressions result in `true`:

```
ceil(4.3) == 5

ceil(4.5) == 5
```

## Absolute Value

### Definition

```
abs(x)
```

| Argument         | Type   | Meaning                                            |
| ---------------- | ------ | -------------------------------------------------- |
| x                | number |                                                    |
| **Return value** | number | Non-negative value of x without regard to its sign |

### Example

All the following expressions result in `true`:

```
abs(-4.3) == 4.3

abs(4.3) == 4.3
```

## Square Root

### Definition

```
sqrt(x)
```

| Argument         | Type                | Meaning                      |
| ---------------- | ------------------- | ---------------------------- |
| x                | Non-negative number |                              |
| **Return value** | number              | Number 𝑎, such that 𝑎2\=𝑥 |

### Example

All the following expressions result in `true`:

```
sqrt(4) == 2

// Square root is defined only for non-negative numbers
sqrt(-16) == null
```

## Power Function

### Definition

```
pow(base, exponent)
```

| Argument         | Type   | Meaning                                                      |
| ---------------- | ------ | ------------------------------------------------------------ |
| base             | number |                                                              |
| exponent         | number |                                                              |
| **Return value** | number | Base raised to the power exponent (𝑏𝑎𝑠𝑒𝑒𝑥𝑝𝑜𝑛𝑒𝑛𝑡) |

### Example

All the following expressions result in `true`:

```
pow(10,3) == 1000

pow(5,-2) == 0.04

pow(-2,5) == -32
```

## Logarithm

### Definition

```
log(x [, base])
```

| Argument         | Type                | Meaning                              |
| ---------------- | ------------------- | ------------------------------------ |
| x                | Non-negative number |                                      |
| base             | Non-negative number | _Optional._ Default base is decadic. |
| **Return value** | number              | Number 𝑦, such that 𝑏𝑎𝑠𝑒𝑦\=𝑥  |

### Example

All the following expressions result in `true`:

```
log(1000) == 3

log(16,2) == 4

// Logarithm is defined only for non-negative numbers
log(-2) == null
```