> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sdf.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Math Functions

## `abs`

Returns the absolute value of x.

*Examples:*

```sql examples.sql theme={null}
select abs(-1) as value; -- value '1.0'
```

*Supported Signatures*

```sql theme={null}
function abs(tinyint) returns tinyint
function abs(smallint) returns smallint
function abs(bigint) returns bigint
function abs(double) returns double
function abs(decimal(p, s)) returns decimal(p, s)
function abs(real) returns real
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#abs)

## `acos`

Returns the arc cosine of x.

*Examples:*

```sql examples.sql theme={null}
select acos(0.5) as value; -- value '1.0471975511965976'
```

*Supported Signatures*

```sql theme={null}
function acos(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#acos)

## `asin`

Returns the arc sine of x.

*Examples:*

```sql examples.sql theme={null}
select asin(1) as value; -- value '1.5707963267948966'
```

*Supported Signatures*

```sql theme={null}
function asin(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#asin)

## `atan`

Returns the arc tangent of x.

*Examples:*

```sql examples.sql theme={null}
select atan(0) as value; -- value '0.0'
```

*Supported Signatures*

```sql theme={null}
function atan(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#atan)

## `atan2`

Returns the arc tangent of y / x.

*Examples:*

```sql examples.sql theme={null}
select atan2(1, 0.5) as value; -- value '1.1071487177940904'
```

*Supported Signatures*

```sql theme={null}
function atan2(double, double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#atan2)

## `beta_cdf`

Compute the Beta cdf with given a, b parameters.  P(N \< v; a, b). The a, b parameters must be positive real numbers and value v must be a real value. The value v must lie on the interval \[0, 1].

*Supported Signatures*

```sql theme={null}
function beta_cdf(double, double, double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#beta_cdf)

## `cbrt`

Returns the cube root of x.

*Examples:*

```sql examples.sql theme={null}
SELECT cbrt(328509) as value; -- value '69.0'
```

*Supported Signatures*

```sql theme={null}
function cbrt(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#cbrt)

## `ceil`

This is an alias for ceiling().

*Examples:*

```sql examples.sql theme={null}
SELECT ceil(1.3) AS value; -- value '2.0'
```

*Supported Signatures*

```sql theme={null}
function ceil(bigint) returns bigint
function ceil(decimal(p, s)) returns decimal(rp, 0)
function ceil(double) returns double
function ceil(integer) returns integer
function ceil(real) returns real
function ceil(smallint) returns smallint
function ceil(tinyint) returns tinyint
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#ceil)

## `ceiling`

Returns x rounded up to the nearest integer.

*Supported Signatures*

```sql theme={null}
function ceiling(bigint) returns bigint
function ceiling(decimal(p, s)) returns decimal(rp, 0)
function ceiling(double) returns double
function ceiling(integer) returns integer
function ceiling(real) returns real
function ceiling(smallint) returns smallint
function ceiling(tinyint) returns tinyint
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#ceiling)

## `cos`

Returns the cosine of x.

*Examples:*

```sql examples.sql theme={null}
select cos(1.0) as value; -- value '0.5403023058681398'
```

*Supported Signatures*

```sql theme={null}
function cos(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#cos)

## `cosh`

Returns the hyperbolic cosine of the given value.

*Examples:*

```sql examples.sql theme={null}
SELECT cosh(0) AS value; -- value '1.0'
```

*Supported Signatures*

```sql theme={null}
function cosh(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#cosh)

## `cosine_similarity`

Returns the cosine similarity between the sparse vectors x and y.

*Supported Signatures*

```sql theme={null}
function cosine_similarity(map<varchar, double>, map<varchar, double>) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#cosine_similarity)

## `degrees`

Converts angle x in radians to degrees.

*Examples:*

```sql examples.sql theme={null}
SELECT degrees(3.14159) AS value; -- value '179.9998547447946'
```

*Supported Signatures*

```sql theme={null}
function degrees(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#degrees)

## `e`

Returns the constant Euler’s number.

*Supported Signatures*

```sql theme={null}
function e() returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#e)

## `exp`

Returns Euler’s number raised to the power of x.

*Examples:*

```sql examples.sql theme={null}
select exp(1.0) as value; -- value '2.718281828459045'
```

*Supported Signatures*

```sql theme={null}
function exp(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#exp)

## `floor`

Returns x rounded down to the nearest integer.

*Supported Signatures*

```sql theme={null}
function floor(bigint) returns bigint
function floor(decimal(p, s)) returns decimal(rp, 0)
function floor(double) returns double
function floor(integer) returns integer
function floor(real) returns real
function floor(smallint) returns smallint
function floor(tinyint) returns tinyint
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#floor)

## `from_base`

Returns the value of string interpreted as a base-radix number.

*Supported Signatures*

```sql theme={null}
function from_base(varchar, bigint) returns bigint
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#from_base)

## `infinity`

Returns the constant representing positive infinity.

*Supported Signatures*

```sql theme={null}
function infinity() returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#infinity)

## `inverse_beta_cdf`

Compute the inverse of the Beta cdf with given a, b parameters for the cumulative probability (p). P(N \< n). The a, b parameters must be positive real values. The probability p must lie on the interval \[0, 1].

*Supported Signatures*

```sql theme={null}
function inverse_beta_cdf(double, double, double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#inverse_beta_cdf)

## `inverse_normal_cdf`

Compute the inverse of the Normal cdf with given mean and standard deviation (sd) for the cumulative probability (p). P(N \< n). The mean must be a real value and the standard deviation must be a real and positive value. The probability p must lie on the interval (0, 1).

*Supported Signatures*

```sql theme={null}
function inverse_normal_cdf(double, double, double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#inverse_normal_cdf)

## `is_finite`

Determine if x is finite.

*Supported Signatures*

```sql theme={null}
function is_finite(double) returns boolean
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#is_finite)

## `is_infinite`

Determine if x is infinite.

*Supported Signatures*

```sql theme={null}
function is_infinite(double) returns boolean
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#is_infinite)

## `is_nan`

Determine if `x` is not-a-number.

*Examples:*

```sql examples.sql theme={null}
select is_nan(1.1) as value; -- value 'false'
```

*Supported Signatures*

```sql theme={null}
function is_nan(double) returns boolean
function is_nan(real) returns boolean
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#is_nan)

## `ln`

Returns the natural logarithm of x.

*Examples:*

```sql examples.sql theme={null}
select ln(2.1) as value; -- value '0.7419373447293773'
```

*Supported Signatures*

```sql theme={null}
function ln(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#ln)

## `log`

Returns the base b logarithm of x.

*Examples:*

```sql examples.sql theme={null}
SELECT log(2.19, 1) AS value; -- value '0.0'
```

*Supported Signatures*

```sql theme={null}
function log(double, double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#log)

## `log10`

Returns the base 10 logarithm of x.

*Examples:*

```sql examples.sql theme={null}
select log10(10) as value; -- value '1.0'
```

*Supported Signatures*

```sql theme={null}
function log10(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#log10)

## `log2`

Returns the base 2 logarithm of x.

*Examples:*

```sql examples.sql theme={null}
select log2(2) as value; -- value '1.0'
```

*Supported Signatures*

```sql theme={null}
function log2(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#log2)

## `mod`

Returns the modulus (remainder) of n divided by m.

*Supported Signatures*

```sql theme={null}
function mod(bigint, bigint) returns bigint
function mod(decimal(a_precision, a_scale), decimal(b_precision, b_scale)) returns decimal(r_precision, r_scale)
function mod(double, double) returns double
function mod(integer, integer) returns integer
function mod(real, real) returns real
function mod(smallint, smallint) returns smallint
function mod(tinyint, tinyint) returns tinyint
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#mod)

## `nan`

Returns the constant representing not-a-number.

*Supported Signatures*

```sql theme={null}
function nan() returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#nan)

## `normal_cdf`

Compute the Normal cdf with given mean and standard deviation (sd).  P(N \< v; mean, sd). The mean and value v must be real values and the standard deviation must be a real and positive value.

*Supported Signatures*

```sql theme={null}
function normal_cdf(double, double, double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#normal_cdf)

## `pi`

Returns the constant Pi.

*Examples:*

```sql examples.sql theme={null}
SELECT PI() -- value '3.141592653589793'
```

*Supported Signatures*

```sql theme={null}
function pi() returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#pi)

## `pow`

This is an alias for power().

*Supported Signatures*

```sql theme={null}
function pow(double, double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#pow)

## `power`

Returns x raised to the power of p.

*Examples:*

```sql examples.sql theme={null}
select power(2, 8) as value; -- value '256'
```

*Supported Signatures*

```sql theme={null}
function power(double, double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#power)

## `radians`

Converts angle x in degrees to radians.

*Examples:*

```sql examples.sql theme={null}
SELECT radians(360) AS value; -- value '6.283185307179586'
```

*Supported Signatures*

```sql theme={null}
function radians(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#radians)

## `rand`

This is an alias for random().

*Examples:*

```sql examples.sql theme={null}
SELECT rand() AS value; -- value '0.20138668902074985'
```

*Supported Signatures*

```sql theme={null}
function rand(bigint) returns bigint
function rand(bigint, bigint) returns bigint
function rand() returns double
function rand(integer) returns integer
function rand(integer, integer) returns integer
function rand(smallint) returns smallint
function rand(smallint, smallint) returns smallint
function rand(tinyint) returns tinyint
function rand(tinyint, tinyint) returns tinyint
```

*Note: rand() is volatile, i.e. might return a
different value for the same input.*

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#rand)

## `random`

Returns a pseudo-random value in the range 0.0 \<= x \< 1.0.

*Supported Signatures*

```sql theme={null}
function random(bigint) returns bigint
function random(bigint, bigint) returns bigint
function random() returns double
function random(integer) returns integer
function random(integer, integer) returns integer
function random(smallint) returns smallint
function random(smallint, smallint) returns smallint
function random(tinyint) returns tinyint
function random(tinyint, tinyint) returns tinyint
```

*Note: random() is volatile, i.e. might return a
different value for the same input.*

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#random)

## `round`

Returns x rounded to the nearest integer.

*Examples:*

```sql examples.sql theme={null}
select round(2.1) as value; -- value '2.0'
```

*Supported Signatures*

```sql theme={null}
function round(double) returns double
function round(double, bigint) returns double
function round(real) returns real
function round(real, bigint) returns real
function round(integer) returns integer
function round(integer, integer) returns integer
function round(decimal(p, s)) returns decimal(rp, rs)
function round(decimal(p, s), bigint) returns decimal(rp, s)
function round(bigint) returns bigint
function round(bigint, bigint) returns bigint
function round(smallint) returns smallint
function round(smallint, bigint) returns smallint
function round(tinyint) returns tinyint
function round(tinyint, bigint) returns tinyint
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#round)

## `sign`

Returns the signum function of x, that is.

*Supported Signatures*

```sql theme={null}
function sign(bigint) returns bigint
function sign(decimal(p, s)) returns decimal(1, 0)
function sign(double) returns double
function sign(integer) returns integer
function sign(real) returns real
function sign(smallint) returns smallint
function sign(tinyint) returns tinyint
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#sign)

## `sin`

Returns the sine of x.

*Examples:*

```sql examples.sql theme={null}
select sin(2.1) as value; -- value '-0.8632093666488737'
```

*Supported Signatures*

```sql theme={null}
function sin(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#sin)

## `sinh`

Returns the hyperbolic sine of x.

*Examples:*

```sql examples.sql theme={null}
SELECT sinh(1) AS value; -- value '1.1752011936438014'
```

*Supported Signatures*

```sql theme={null}
function sinh(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#sinh)

## `sqrt`

Returns the square root of x.

*Examples:*

```sql examples.sql theme={null}
select sqrt(16) as value; -- value '4.0'
```

*Supported Signatures*

```sql theme={null}
function sqrt(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#sqrt)

## `tan`

Returns the tangent of x.

*Examples:*

```sql examples.sql theme={null}
select tan(0.5) as value; -- value '0.5463024898437905'
```

*Supported Signatures*

```sql theme={null}
function tan(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#tan)

## `tanh`

Returns the hyperbolic tangent of x.

*Examples:*

```sql examples.sql theme={null}
SELECT tanh(1.0) AS value; -- value '0.7615941559557649'
```

*Supported Signatures*

```sql theme={null}
function tanh(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#tanh)

## `to_base`

Returns the base-radix representation of x.

*Supported Signatures*

```sql theme={null}
function to_base(bigint, bigint) returns varchar
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#to_base)

## `truncate`

Returns x rounded to integer by dropping digits after decimal point.

*Examples:*

```sql examples.sql theme={null}
SELECT truncate(1.23456, 2) as value; -- value '1.23'
```

*Supported Signatures*

```sql theme={null}
function truncate(decimal(p, s), bigint) returns decimal(p, s)
function truncate(decimal(p, s)) returns decimal(rp, 0)
function truncate(double) returns double
function truncate(real) returns real
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#truncate)

## `width_bucket`

Returns the bin number of x in an equi-width histogram with the specified bound1 and bound2 bounds and n number of buckets.

*Supported Signatures*

```sql theme={null}
function width_bucket(double, array<double>) returns bigint
function width_bucket(double, double, double, bigint) returns bigint
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#width_bucket)

## `wilson_interval_lower`

Returns the lower bound of the Wilson score interval of a Bernoulli trial process at a confidence specified by the z-score z.

*Supported Signatures*

```sql theme={null}
function wilson_interval_lower(bigint, bigint, double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#wilson_interval_lower)

## `wilson_interval_upper`

Returns the upper bound of the Wilson score interval of a Bernoulli trial process at a confidence specified by the z-score z.

*Supported Signatures*

```sql theme={null}
function wilson_interval_upper(bigint, bigint, double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/math.html#wilson_interval_upper)
