---
title: Math Functions reference
meta:
    description: Functions for mathematical operations.
headingMaxLevels: 2
---

# Mathematical functions

The following functions perform mathematical operations.

## e

Returns the mathematical constant `e`, also known as Euler's number.

### Syntax

```sql
e()
```

### Returns

The value of `e`. Type: [Float64](../data-types/float).

### Example

```sql
SELECT e()
```

Result:

```result
┌─e()────────────────┐
│ 2.718281828459045  │
└────────────────────┘
```

## pi

Returns the mathematical constant `π` (Pi).

### Syntax

```sql
pi()
```

### Returns

The value of `π`. Type: [Float64](../data-types/float).

### Example

```sql
SELECT pi()
```

Result:

```result
┌─pi()───────────────┐
│ 3.141592653589793  │
└────────────────────┘
```

## exp

Calculates the exponential function, raising `e` to the power of the given argument.

### Syntax

```sql
exp(x)
```

### Arguments

- `x`: The exponent. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The result of `e^x`. Type: [Float*](../data-types/float).

### Example

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

Result:

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

## log

Computes the natural logarithm (base `e`) of a number.

### Syntax

```sql
log(x)
```

Alias: `ln(x)`

### Arguments

- `x`: The number for which to calculate the natural logarithm. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The natural logarithm of `x`. Type: [Float*](../data-types/float).

### Example

```sql
SELECT log(10)
```

Result:

```result
┌─log(10)────────────┐
│ 2.302585092994046  │
└────────────────────┘
```

## exp2

Calculates 2 raised to the power of the given argument.

### Syntax

```sql
exp2(x)
```

### Arguments

- `x`: The exponent. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The result of `2^x`. Type: [Float*](../data-types/float).

### Example

```sql
SELECT exp2(3)
```

Result:

```result
┌─exp2(3)─┐
│       8 │
└─────────┘
```

## intExp2

Calculates 2 raised to the power of the given argument, returning the result as an unsigned 64-bit integer.

### Syntax

```sql
intExp2(x)
```

### Arguments

- `x`: The exponent. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The result of `2^x`. Type: [UInt64](../data-types/int-uint).

### Example

```sql
SELECT intExp2(5)
```

Result:

```result
┌─intExp2(5)─┐
│         32 │
└────────────┘
```

## log2

Computes the binary logarithm (base 2) of a number.

### Syntax

```sql
log2(x)
```

### Arguments

- `x`: The number for which to calculate the binary logarithm. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The base 2 logarithm of `x`. Type: [Float*](../data-types/float).

### Example

```sql
SELECT log2(8)
```

Result:

```result
┌─log2(8)─┐
│       3 │
└─────────┘
```

## exp10

Calculates 10 raised to the power of the given argument.

### Syntax

```sql
exp10(x)
```

### Arguments

- `x`: The exponent. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The result of `10^x`. Type: [Float*](../data-types/float).

### Example

```sql
SELECT exp10(2)
```

Result:

```result
┌─exp10(2)─┐
│      100 │
└──────────┘
```

## intExp10

Calculates 10 raised to the power of the given argument, returning the result as an unsigned 64-bit integer.

### Syntax

```sql
intExp10(x)
```

### Arguments

- `x`: The exponent. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The result of `10^x`. Type: [UInt64](../data-types/int-uint).

### Example

```sql
SELECT intExp10(3)
```

Result:

```result
┌─intExp10(3)─┐
│        1000 │
└─────────────┘
```

## log10

Computes the common logarithm (base 10) of a number.

### Syntax

```sql
log10(x)
```

### Arguments

- `x`: The number for which to calculate the common logarithm. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The base 10 logarithm of `x`. Type: [Float*](../data-types/float).

### Example

```sql
SELECT log10(100)
```

Result:

```result
┌─log10(100)─┐
│          2 │
└────────────┘
```

## sqrt

Calculates the square root of a non-negative number.

### Syntax

```sql
sqrt(x)
```

### Arguments

- `x`: The number for which to calculate the square root. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The square root of `x`. Type: [Float*](../data-types/float).

### Example

```sql
SELECT sqrt(25)
```

Result:

```result
┌─sqrt(25)─┐
│        5 │
└──────────┘
```

## cbrt

Calculates the cube root of a number.

### Syntax

```sql
cbrt(x)
```

### Arguments

- `x`: The number for which to calculate the cube root. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The cube root of `x`. Type: [Float*](../data-types/float).

### Example

```sql
SELECT cbrt(27)
```

Result:

```result
┌─cbrt(27)─┐
│        3 │
└──────────┘
```

## erf

Computes the error function of a given value. This function is often used in probability and statistics.

### Syntax

```sql
erf(x)
```

### Arguments

- `x`: The input value. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The error function of `x`. Type: [Float*](../data-types/float).

### Example

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

Result:

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

## erfc

Computes the complementary error function, which is `1 - erf(x)`. This function provides higher precision for large `x` values compared to directly calculating `1 - erf(x)`.

### Syntax

```sql
erfc(x)
```

### Arguments

- `x`: The input value. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The complementary error function of `x`. Type: [Float*](../data-types/float).

### Example

```sql
SELECT erfc(0)
```

Result:

```result
┌─erfc(0)─┐
│       1 │
└─────────┘
```

## lgamma

Calculates the natural logarithm of the absolute value of the gamma function.

### Syntax

```sql
lgamma(x)
```

### Arguments

- `x`: The input value. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The natural logarithm of the gamma function of `x`. Type: [Float*](../data-types/float).

### Example

```sql
SELECT lgamma(5)
```

Result:

```result
┌─lgamma(5)──────────┐
│ 3.1780538303479453 │
└────────────────────┘
```

## tgamma

Calculates the gamma function of a given value.

### Syntax

```sql
gamma(x)
```

### Arguments

- `x`: The input value. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The gamma function of `x`. Type: [Float*](../data-types/float).

### Example

```sql
SELECT gamma(5)
```

Result:

```result
┌─gamma(5)─┐
│       24 │
└──────────┘
```

## sin

Computes the sine of an angle given in radians.

### Syntax

```sql
sin(x)
```

### Arguments

- `x`: The angle in radians. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The sine of `x`. Type: [Float*](../data-types/float).

### Example

```sql
SELECT sin(pi() / 2)
```

Result:

```result
┌─sin(divide(pi(), 2))─┐
│                    1 │
└──────────────────────┘
```

## cos

Computes the cosine of an angle given in radians.

### Syntax

```sql
cos(x)
```

### Arguments

- `x`: The angle in radians. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The cosine of `x`. Type: [Float*](../data-types/float).

### Example

```sql
SELECT cos(pi())
```

Result:

```result
┌─cos(pi())─┐
│        -1 │
└───────────┘
```

## tan

Computes the tangent of an angle given in radians.

### Syntax

```sql
tan(x)
```

### Arguments

- `x`: The angle in radians. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The tangent of `x`. Type: [Float*](../data-types/float).

### Example

```sql
SELECT tan(pi() / 4)
```

Result:

```result
┌─tan(divide(pi(), 4))─┐
│                    1 │
└──────────────────────┘
```

## asin

Computes the arc sine (inverse sine) of a value, returning the angle in radians.

### Syntax

```sql
asin(x)
```

### Arguments

- `x`: The value for which to calculate the arc sine (must be between -1 and 1). Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The arc sine of `x` in radians. Type: [Float*](../data-types/float).

### Example

```sql
SELECT asin(1)
```

Result:

```result
┌─asin(1)────────────┐
│ 1.5707963267948966 │
└────────────────────┘
```

## acos

Computes the arc cosine (inverse cosine) of a value, returning the angle in radians.

### Syntax

```sql
acos(x)
```

### Arguments

- `x`: The value for which to calculate the arc cosine (must be between -1 and 1). Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The arc cosine of `x` in radians. Type: [Float*](../data-types/float).

### Example

```sql
SELECT acos(0)
```

Result:

```result
┌─acos(0)────────────┐
│ 1.5707963267948966 │
└────────────────────┘
```

## atan

Computes the arc tangent (inverse tangent) of a value, returning the angle in radians.

### Syntax

```sql
atan(x)
```

### Arguments

- `x`: The value for which to calculate the arc tangent. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The arc tangent of `x` in radians. Type: [Float*](../data-types/float).

### Example

```sql
SELECT atan(1)
```

Result:

```result
┌─atan(1)────────────┐
│ 0.7853981633974483 │
└────────────────────┘
```

## pow

Calculates the result of raising a base number to a specified exponent.

### Syntax

```sql
pow(x, y)
```

Alias: `power(x, y)`

### Arguments

- `x`: The base number. Type: [(U)Int8/16/32/64](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).
- `y`: The exponent. Type: [(U)Int8/16/32/64](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The value of `x` raised to the power of `y`. Type: [Float64](../data-types/float).

### Example

```sql
SELECT pow(2, 4)
```

Result:

```result
┌─pow(2, 4)─┐
│        16 │
└───────────┘
```

## cosh

Computes the hyperbolic cosine of an angle.

### Syntax

```sql
cosh(x)
```

### Arguments

- `x`: The angle, in radians. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The hyperbolic cosine of `x`. Type: [Float64](../data-types/float).

### Example

```sql
SELECT cosh(0)
```

Result:

```result
┌─cosh(0)──┐
│        1 │
└──────────┘
```

## acosh

Computes the inverse hyperbolic cosine of a value.

### Syntax

```sql
acosh(x)
```

### Arguments

- `x`: The value for which to calculate the inverse hyperbolic cosine (must be `>= 1`). Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The inverse hyperbolic cosine of `x` in radians. Type: [Float64](../data-types/float).

### Example

```sql
SELECT acosh(1)
```

Result:

```result
┌─acosh(1)─┐
│        0 │
└──────────┘
```

## sinh

Computes the hyperbolic sine of an angle.

### Syntax

```sql
sinh(x)
```

### Arguments

- `x`: The angle, in radians. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The hyperbolic sine of `x`. Type: [Float64](../data-types/float).

### Example

```sql
SELECT sinh(0)
```

Result:

```result
┌─sinh(0)──┐
│        0 │
└──────────┘
```

## asinh

Computes the inverse hyperbolic sine of a value.

### Syntax

```sql
asinh(x)
```

### Arguments

- `x`: The value for which to calculate the inverse hyperbolic sine. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The inverse hyperbolic sine of `x` in radians. Type: [Float64](../data-types/float).

### Example

```sql
SELECT asinh(0)
```

Result:

```result
┌─asinh(0)─┐
│        0 │
└──────────┘
```

## tanh

Computes the hyperbolic tangent of an angle.

### Syntax

```sql
tanh(x)
```

### Arguments

- `x`: The angle, in radians. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The hyperbolic tangent of `x`. Type: [Float*](../data-types/float).

### Example

```sql
SELECT tanh(0)
```

Result:

```result
┌─tanh(0)─┐
│       0 │
└─────────┘
```

## atanh

Computes the inverse hyperbolic tangent of a value.

### Syntax

```sql
atanh(x)
```

### Arguments

- `x`: The value for which to calculate the inverse hyperbolic tangent (must be between -1 and 1, exclusive). Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The inverse hyperbolic tangent of `x` in radians. Type: [Float64](../data-types/float).

### Example

```sql
SELECT atanh(0)
```

Result:

```result
┌─atanh(0)─┐
│        0 │
└──────────┘
```

## atan2

Calculates the angle in radians between the positive x-axis and a point `(x, y)` in the Euclidean plane. This function correctly handles all four quadrants.

### Syntax

```sql
atan2(y, x)
```

### Arguments

- `y`: The y-coordinate of the point. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).
- `x`: The x-coordinate of the point. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The angle `θ` in radians, where `-π < θ <= π`. Type: [Float64](../data-types/float).

### Example

```sql
SELECT atan2(1, 1)
```

Result:

```result
┌────────atan2(1, 1)─┐
│ 0.7853981633974483 │
└────────────────────┘
```

## hypot

Calculates the length of the hypotenuse of a right-angled triangle given the lengths of its two shorter sides. This function is designed to avoid overflow or underflow issues with very large or small inputs.

### Syntax

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

### Arguments

- `x`: The length of the first side (cathetus). Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).
- `y`: The length of the second side (cathetus). Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The length of the hypotenuse. Type: [Float64](../data-types/float).

### Example

```sql
SELECT hypot(3, 4)
```

Result:

```result
┌─hypot(3, 4)─┐
│           5 │
└─────────────┘
```

## log1p

Computes the natural logarithm of `1 + x`. This function offers improved precision for `x` values close to zero compared to `log(1 + x)`.

### Syntax

```sql
log1p(x)
```

### Arguments

- `x`: The input value (must be `> -1`). Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The natural logarithm of `1 + x`. Type: [Float64](../data-types/float).

### Example

```sql
SELECT log1p(0)
```

Result:

```result
┌─log1p(0)─┐
│        0 │
└──────────┘
```

## sign

Determines the sign of a numeric value.

### Syntax

```sql
sign(x)
```

### Arguments

- `x`: Any numeric value. Type: All numeric types.

### Returns

- `-1` if `x < 0`
- `0` if `x = 0`
- `1` if `x > 0`

Type: [Int8](../data-types/int-uint).

### Example

```sql
SELECT sign(-5)
```

Result:

```result
┌─sign(-5)─┐
│       -1 │
└──────────┘
```

## sigmoid

Applies the sigmoid activation function, which maps any real-valued number to a value between 0 and 1. This is commonly used in machine learning.

### Syntax

```sql
sigmoid(x)
```

### Arguments

- `x`: The input value. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The sigmoid of `x`. Type: [Float64](../data-types/float).

### Example

```sql
SELECT round(sigmoid(0), 5)
```

Result:

```result
┌─round(sigmoid(0), 5)─┐
│                  0.5 │
└──────────────────────┘
```

## degrees

Converts an angle from radians to degrees.

### Syntax

```sql
degrees(x)
```

### Arguments

- `x`: The angle in radians. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The angle in degrees. Type: [Float64](../data-types/float).

### Example

```sql
SELECT degrees(pi())
```

Result:

```result
┌─degrees(pi())─┐
│           180 │
└───────────────┘
```

## radians

Converts an angle from degrees to radians.

### Syntax

```sql
radians(x)
```

### Arguments

- `x`: The angle in degrees. Type: [(U)Int*](../data-types/int-uint), [Float*](../data-types/float) or [Decimal*](../data-types/decimal).

### Returns

The angle in radians. Type: [Float64](../data-types/float).

### Example

```sql
SELECT radians(90)
```

Result:

```result
┌─radians(90)────────┐
│ 1.5707963267948966 │
└────────────────────┘
```

## factorial

Computes the factorial of a non-negative integer. The factorial of `n` is the product of all positive integers less than or equal to `n`.

### Syntax

```sql
factorial(n)
```

### Arguments

- `n`: A non-negative integer. Type: Any integer type.

### Returns

The factorial of `n`. Type: [UInt64](../data-types/int-uint).

### Example

```sql
SELECT factorial(5)
```

Result:

```result
┌─factorial(5)─┐
│          120 │
└──────────────┘
```

## width_bucket

Assigns a numeric value to a specific bucket within a defined range, dividing the range into equal-width intervals.

### Syntax

```sql
widthBucket(operand, low, high, count)
```

Alias: `WIDTH_BUCKET`

### Arguments

- `operand`: The value to be placed into a bucket. Type: Any numeric type.
- `low`: The lower bound of the range. Type: Any numeric type.
- `high`: The upper bound of the range. Type: Any numeric type.
- `count`: The number of equal-width buckets. Type: [UInt*](../data-types/int-uint) (must be non-zero).

### Returns

The bucket number (1 to `count`), `0` if `operand < low`, or `count + 1` if `operand >= high`. Type: [UInt64](../data-types/int-uint).

### Example

```sql
SELECT widthBucket(5.5, 0, 10, 2)
```

Result:

```result
┌─widthBucket(5.5, 0, 10, 2)─┐
│                          2 │
└────────────────────────────┘
```

## proportionsZTest

Performs a two-proportion Z-test to compare the proportions of successes from two independent populations. It returns statistical metrics including the Z-statistic, p-value, and confidence interval.

### Syntax

```sql
proportionsZTest(successes_x, successes_y, trials_x, trials_y, conf_level, pool_type)
```

### Arguments

- `successes_x`: Number of successes in population `x`. Type: [UInt64](../data-types/int-uint).
- `successes_y`: Number of successes in population `y`. Type: [UInt64](../data-types/int-uint).
- `trials_x`: Total number of trials in population `x`. Type: [UInt64](../data-types/int-uint).
- `trials_y`: Total number of trials in population `y`. Type: [UInt64](../data-types/int-uint).
- `conf_level`: The desired confidence level for the test (e.g., 0.95 for 95%). Type: [Float64](../data-types/float).
- `pool_type`: Specifies whether to use a 'pooled' or 'unpooled' estimate for the standard error. Type: [String](../data-types/string).

{% callout type="info" %}
For argument `pool_type`: In the pooled version, the two proportions are averaged, and only one proportion is used to estimate the standard error. In the unpooled version, the two proportions are used separately.
{% /callout %}

### Returns

A tuple containing:
- `z_stat`: The calculated Z-statistic. Type: [Float64](../data-types/float).
- `p_val`: The p-value of the test. Type: [Float64](../data-types/float).
- `ci_low`: The lower bound of the confidence interval. Type: [Float64](../data-types/float).
- `ci_high`: The upper bound of the confidence interval. Type: [Float64](../data-types/float).

### Example

```sql
SELECT proportionsZTest(10, 11, 100, 101, 0.95, 'unpooled')
```

Result:

```result
┌─proportionsZTest(10, 11, 100, 101, 0.95, 'unpooled')───────────────────────────────┐
│ (-0.20656724435948853,0.8363478437079654,-0.09345975390115283,0.07563797172293502) │
└────────────────────────────────────────────────────────────────────────────────────┘
```
