Mathematical functions

## erf[​](#erf "Direct link to erf")

Introduced in: v1.1.0

If `x` is non-negative, then `erf(x/(σ√2))` is the probability that a random variable having a normal distribution with standard deviation `σ` takes the value that is separated from the expected value by more than `x`.

**Syntax**

```
erf(x)
```

**Arguments**

- `x` — The value for which to compute the error function value. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal*`](/docs/sql-reference/data-types/decimal)

**Returned value**

Returns the error function value [`Float*`](/docs/sql-reference/data-types/float)

**Examples**

**Three sigma rule**

```
SELECT erf(3 / sqrt(2))
```

```
┌─erf(divide(3, sqrt(2)))─┐
│      0.9973002039367398 │
└─────────────────────────┘
```

## erfc[​](#erfc "Direct link to erfc")

Introduced in: v1.1.0

Returns a number close to `1-erf(x)` without loss of precision for large `x` values.

**Syntax**

```
erfc(x)
```

**Arguments**

- `x` — The value for which to find the error function value. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal*`](/docs/sql-reference/data-types/decimal)

**Returned value**

Returns the complementary error function value [`Float*`](/docs/sql-reference/data-types/float)

**Examples**

**Usage example**

```
SELECT erfc(0);
```

```
1
```

## exp[​](#exp "Direct link to exp")

Introduced in: v1.1.0

Returns e raised to the power of `x`, where `x` is the given argument to the function.

**Syntax**

```
exp(x)
```

**Arguments**

- `x` — The exponent. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal*`](/docs/sql-reference/data-types/decimal)

**Returned value**

Returns `e^x` [`Float*`](/docs/sql-reference/data-types/float)

**Examples**

**Basic usage**

```
SELECT round(exp(-1), 4)
```

```
┌─round(exp(-1), 4)─┐
│            0.3679 │
└───────────────────┘
```

## exp10[​](#exp10 "Direct link to exp10")

Introduced in: v1.1.0

Returns 10 to the power of the given argument.

**Syntax**

```
exp10(x)
```

**Arguments**

- `x` — The exponent. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal*`](/docs/sql-reference/data-types/decimal)

**Returned value**

Returns 10^x [`Float*`](/docs/sql-reference/data-types/float)

**Examples**

**Usage example**

```
SELECT exp10(2);
```

```
100
```

## exp2[​](#exp2 "Direct link to exp2")

Introduced in: v1.1.0

Returns 2 to the power of the given argument.

**Syntax**

```
exp2(x)
```

**Arguments**

- `x` — The exponent. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal*`](/docs/sql-reference/data-types/decimal)

**Returned value**

Returns 2^x [`Float*`](/docs/sql-reference/data-types/float)

**Examples**

**Usage example**

```
SELECT exp2(3);
```

```
8
```

## factorial[​](#factorial "Direct link to factorial")

Introduced in: v22.11.0

Computes the factorial of an integer value.
The factorial of 0 is 1. Likewise, the `factorial()` function returns `1` for any negative value.
The maximum positive value for the input argument is `20`, a value of `21` or greater will cause an exception.

**Syntax**

```
factorial(n)
```

**Arguments**

- `n` — Integer value for which to calculate the factorial. Maximum value is 20. [`(U)Int8/16/32/64`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns the factorial of the input as UInt64. Returns 1 for input 0 or any negative value. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
factorial(10)
```

```
3628800
```

## hypot[​](#hypot "Direct link to hypot")

Introduced in: v20.12.0

Returns the length of the hypotenuse of a right-angle triangle.
Hypot avoids problems that occur when squaring very large or very small numbers.

**Syntax**

```
hypot(x, y)
```

**Arguments**

- `x` — The first cathetus of a right-angle triangle. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal*`](/docs/sql-reference/data-types/decimal)
- `y` — The second cathetus of a right-angle triangle. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal*`](/docs/sql-reference/data-types/decimal)

**Returned value**

Returns the length of the hypotenuse of a right-angle triangle. [`Float64`](/docs/sql-reference/data-types/float)

**Examples**

**Basic usage**

```
SELECT hypot(1, 1)
```

```
1.4142135623730951
```

## intExp10[​](#intExp10 "Direct link to intExp10")

Introduced in: v1.1.0

Like [exp10](#exp10) but returns a `UInt64` number.

**Syntax**

```
intExp10(x)
```

**Arguments**

- `x` — The exponent. [`Int*`](/docs/sql-reference/data-types/int-uint) or [`UInt*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float)

**Returned value**

Returns 10^x. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT intExp10(2);
```

```
100
```

## intExp2[​](#intExp2 "Direct link to intExp2")

Introduced in: v1.1.0

Like [exp2](#exp2) but returns a `UInt64` number.

**Syntax**

```
intExp2(x)
```

**Arguments**

- `x` — The exponent. [`Int*`](/docs/sql-reference/data-types/int-uint) or [`UInt*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float)

**Returned value**

Returns 2^x. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT intExp2(3);
```

```
8
```

## lgamma[​](#lgamma "Direct link to lgamma")

Introduced in: v1.1.0

Returns the logarithm of the gamma function.

**Syntax**

```
lgamma(x)
```

**Arguments**

- `x` — The number for which to compute the logarithm of the gamma function. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal*`](/docs/sql-reference/data-types/decimal)

**Returned value**

Returns the logarithm of the gamma function of `x`. [`Float*`](/docs/sql-reference/data-types/float)

**Examples**

**Usage example**

```
SELECT lgamma(5);
```

```
3.1780538303479458
```

## log[​](#log "Direct link to log")

Introduced in: v1.1.0

Returns the natural logarithm of the argument.

**Syntax**

```
log(x)
```

**Aliases**: `ln`

**Arguments**

- `x` — The number for which to compute the natural logarithm of. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal*`](/docs/sql-reference/data-types/decimal)

**Returned value**

Returns the natural logarithm of `x`. [`Float*`](/docs/sql-reference/data-types/float)

**Examples**

**Usage example**

```
SELECT log(10);
```

```
2.302585092994046
```

## log10[​](#log10 "Direct link to log10")

Introduced in: v1.1.0

Returns the decimal logarithm of the argument.

**Syntax**

```
log10(x)
```

**Arguments**

- `x` — Number for which to compute the decimal logarithm of. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal*`](/docs/sql-reference/data-types/decimal)

**Returned value**

Returns the decimal logarithm of `x`. [`Float*`](/docs/sql-reference/data-types/float)

**Examples**

**Usage example**

```
SELECT log10(100);
```

```
2
```

## log1p[​](#log1p "Direct link to log1p")

Introduced in: v20.12.0

Calculates log(1+x).
The calculation log1p(x) is more accurate than log(1+x) for small values of `x`.

**Syntax**

```
log1p(x)
```

**Arguments**

- `x` — Values from the interval: `-1 < x < +∞`. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal*`](/docs/sql-reference/data-types/decimal)

**Returned value**

Returns values from the interval: -∞ < log1p(x) < +∞ [`Float64`](/docs/sql-reference/data-types/float)

**Examples**

**Usage example**

```
SELECT log1p(0)
```

```
0
```

## log2[​](#log2 "Direct link to log2")

Introduced in: v1.1.0