2020-04-03 13:23:32 +00:00
---
2022-04-09 13:29:05 +00:00
sidebar_position: 44
sidebar_label: Mathematical
2020-04-03 13:23:32 +00:00
---
2022-06-02 10:55:18 +00:00
# Mathematical Functions
2017-12-28 15:13:23 +00:00
2017-04-26 19:16:38 +00:00
All the functions return a Float64 number. The accuracy of the result is close to the maximum precision possible, but the result might not coincide with the machine representable number nearest to the corresponding real number.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## e()
2017-12-28 15:13:23 +00:00
2018-09-04 11:18:59 +00:00
Returns a Float64 number that is close to the number e.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## pi()
2017-12-28 15:13:23 +00:00
2018-09-04 11:18:59 +00:00
Returns a Float64 number that is close to the number π.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## exp(x)
2017-12-28 15:13:23 +00:00
2017-04-26 19:16:38 +00:00
Accepts a numeric argument and returns a Float64 number close to the exponent of the argument.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## log(x), ln(x)
2017-12-28 15:13:23 +00:00
2017-04-26 19:16:38 +00:00
Accepts a numeric argument and returns a Float64 number close to the natural logarithm of the argument.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## exp2(x)
2017-12-28 15:13:23 +00:00
2018-09-04 11:18:59 +00:00
Accepts a numeric argument and returns a Float64 number close to 2 to the power of x.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## log2(x)
2017-12-28 15:13:23 +00:00
2017-04-26 19:16:38 +00:00
Accepts a numeric argument and returns a Float64 number close to the binary logarithm of the argument.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## exp10(x)
2017-12-28 15:13:23 +00:00
2018-09-04 11:18:59 +00:00
Accepts a numeric argument and returns a Float64 number close to 10 to the power of x.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## log10(x)
2017-12-28 15:13:23 +00:00
2017-04-26 19:16:38 +00:00
Accepts a numeric argument and returns a Float64 number close to the decimal logarithm of the argument.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## sqrt(x)
2017-12-28 15:13:23 +00:00
2017-04-26 19:16:38 +00:00
Accepts a numeric argument and returns a Float64 number close to the square root of the argument.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## cbrt(x)
2017-12-28 15:13:23 +00:00
2017-04-26 19:16:38 +00:00
Accepts a numeric argument and returns a Float64 number close to the cubic root of the argument.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## erf(x)
2017-04-03 19:49:50 +00:00
2020-05-08 08:04:09 +00:00
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’ .
2017-04-03 19:49:50 +00:00
2017-04-26 19:16:38 +00:00
Example (three sigma rule):
2017-04-03 19:49:50 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2021-03-13 18:18:45 +00:00
SELECT erf(3 / sqrt(2));
2017-12-28 15:13:23 +00:00
```
2017-04-03 19:49:50 +00:00
2020-03-20 10:10:48 +00:00
``` text
2017-12-28 15:13:23 +00:00
┌─erf(divide(3, sqrt(2)))─┐
│ 0.9973002039367398 │
└─────────────────────────┘
```
2017-06-13 04:15:47 +00:00
2022-06-02 10:55:18 +00:00
## erfc(x)
2017-06-13 04:15:47 +00:00
2020-03-20 10:10:48 +00:00
Accepts a numeric argument and returns a Float64 number close to 1 - erf(x), but without loss of precision for large ‘ x’ values.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## lgamma(x)
2017-12-28 15:13:23 +00:00
2017-04-26 19:16:38 +00:00
The logarithm of the gamma function.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## tgamma(x)
2017-12-28 15:13:23 +00:00
2017-04-26 19:16:38 +00:00
Gamma function.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## sin(x)
2017-12-28 15:13:23 +00:00
2017-04-26 19:16:38 +00:00
The sine.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## cos(x)
2017-12-28 15:13:23 +00:00
2017-04-26 19:16:38 +00:00
The cosine.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## tan(x)
2017-12-28 15:13:23 +00:00
2017-04-26 19:16:38 +00:00
The tangent.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## asin(x)
2017-12-28 15:13:23 +00:00
The arc sine.
2022-06-02 10:55:18 +00:00
## acos(x)
2017-04-03 19:49:50 +00:00
2017-04-26 19:16:38 +00:00
The arc cosine.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## atan(x)
2017-12-28 15:13:23 +00:00
2017-04-26 19:16:38 +00:00
The arc tangent.
2017-04-03 19:49:50 +00:00
2022-06-02 10:55:18 +00:00
## pow(x, y), power(x, y)
2017-12-28 15:13:23 +00:00
2018-09-04 11:18:59 +00:00
Takes two numeric arguments x and y. Returns a Float64 number close to x to the power of y.
2018-10-16 10:47:17 +00:00
2022-06-02 10:55:18 +00:00
## intExp2
2019-01-30 10:39:46 +00:00
Accepts a numeric argument and returns a UInt64 number close to 2 to the power of x.
2022-06-02 10:55:18 +00:00
## intExp10
2019-01-30 10:39:46 +00:00
Accepts a numeric argument and returns a UInt64 number close to 10 to the power of x.
2022-06-02 10:55:18 +00:00
## cosh(x)
2020-12-01 19:25:57 +00:00
[Hyperbolic cosine ](https://in.mathworks.com/help/matlab/ref/cosh.html ).
**Syntax**
``` sql
cosh(x)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2020-12-01 19:25:57 +00:00
2020-12-03 20:59:17 +00:00
- `x` — The angle, in radians. Values from the interval: `-∞ < x < +∞` . [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
2020-12-01 19:25:57 +00:00
**Returned value**
2020-12-03 20:59:17 +00:00
- Values from the interval: `1 <= cosh(x) < +∞` .
2020-12-01 19:25:57 +00:00
Type: [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
**Example**
Query:
``` sql
SELECT cosh(0);
```
Result:
``` text
┌─cosh(0)──┐
│ 1 │
└──────────┘
```
2022-06-02 10:55:18 +00:00
## acosh(x)
2020-12-01 19:25:57 +00:00
[Inverse hyperbolic cosine ](https://www.mathworks.com/help/matlab/ref/acosh.html ).
**Syntax**
``` sql
acosh(x)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2020-12-01 19:25:57 +00:00
2020-12-06 09:55:09 +00:00
- `x` — Hyperbolic cosine of angle. Values from the interval: `1 <= x < +∞` . [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
2020-12-01 19:25:57 +00:00
**Returned value**
2020-12-06 09:55:09 +00:00
- The angle, in radians. Values from the interval: `0 <= acosh(x) < +∞` .
2020-12-01 19:25:57 +00:00
Type: [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
**Example**
Query:
``` sql
SELECT acosh(1);
```
Result:
``` text
┌─acosh(1)─┐
│ 0 │
└──────────┘
```
**See Also**
- [cosh(x) ](../../sql-reference/functions/math-functions.md#coshx )
2022-06-02 10:55:18 +00:00
## sinh(x)
2020-12-01 19:25:57 +00:00
[Hyperbolic sine ](https://www.mathworks.com/help/matlab/ref/sinh.html ).
**Syntax**
``` sql
sinh(x)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2020-12-01 19:25:57 +00:00
2020-12-03 20:59:17 +00:00
- `x` — The angle, in radians. Values from the interval: `-∞ < x < +∞` . [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
2020-12-01 19:25:57 +00:00
**Returned value**
2020-12-03 20:59:17 +00:00
- Values from the interval: `-∞ < sinh(x) < +∞` .
2020-12-01 19:25:57 +00:00
Type: [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
**Example**
Query:
``` sql
SELECT sinh(0);
```
Result:
``` text
┌─sinh(0)──┐
│ 0 │
└──────────┘
```
2022-06-02 10:55:18 +00:00
## asinh(x)
2020-12-01 19:25:57 +00:00
[Inverse hyperbolic sine ](https://www.mathworks.com/help/matlab/ref/asinh.html ).
**Syntax**
``` sql
asinh(x)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2020-12-01 19:25:57 +00:00
2020-12-06 09:55:09 +00:00
- `x` — Hyperbolic sine of angle. Values from the interval: `-∞ < x < +∞` . [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
2020-12-01 19:25:57 +00:00
**Returned value**
2020-12-06 09:55:09 +00:00
- The angle, in radians. Values from the interval: `-∞ < asinh(x) < +∞` .
2020-12-01 19:25:57 +00:00
Type: [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
**Example**
Query:
``` sql
SELECT asinh(0);
```
Result:
``` text
┌─asinh(0)─┐
│ 0 │
└──────────┘
```
**See Also**
- [sinh(x) ](../../sql-reference/functions/math-functions.md#sinhx )
2022-06-02 10:55:18 +00:00
## atanh(x)
2020-12-01 19:25:57 +00:00
[Inverse hyperbolic tangent ](https://www.mathworks.com/help/matlab/ref/atanh.html ).
**Syntax**
``` sql
atanh(x)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2020-12-01 19:25:57 +00:00
2020-12-06 09:55:09 +00:00
- `x` — Hyperbolic tangent of angle. Values from the interval: `– 1 < x < 1` . [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
2020-12-01 19:25:57 +00:00
**Returned value**
2020-12-06 09:55:09 +00:00
- The angle, in radians. Values from the interval: `-∞ < atanh(x) < +∞` .
2020-12-01 19:25:57 +00:00
Type: [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
**Example**
Query:
``` sql
SELECT atanh(0);
```
Result:
``` text
┌─atanh(0)─┐
│ 0 │
└──────────┘
```
2022-06-02 10:55:18 +00:00
## atan2(y, x)
2020-12-01 19:25:57 +00:00
2020-12-03 20:59:17 +00:00
The [function ](https://en.wikipedia.org/wiki/Atan2 ) calculates the angle in the Euclidean plane, given in radians, between the positive x axis and the ray to the point `(x, y) ≠ (0, 0)` .
2020-12-01 19:25:57 +00:00
**Syntax**
``` sql
atan2(y, x)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2020-12-01 19:25:57 +00:00
2020-12-03 20:59:17 +00:00
- `y` — y-coordinate of the point through which the ray passes. [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
- `x` — x-coordinate of the point through which the ray passes. [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
2020-12-01 19:25:57 +00:00
**Returned value**
2020-12-03 20:59:17 +00:00
- The angle `θ` such that `−π < θ ≤ π` , in radians.
2020-12-01 19:25:57 +00:00
Type: [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
**Example**
Query:
``` sql
SELECT atan2(1, 1);
```
Result:
``` text
┌────────atan2(1, 1)─┐
│ 0.7853981633974483 │
└────────────────────┘
```
2022-06-02 10:55:18 +00:00
## hypot(x, y)
2020-12-01 19:25:57 +00:00
2020-12-03 20:59:17 +00:00
Calculates the length of the hypotenuse of a right-angle triangle. The [function ](https://en.wikipedia.org/wiki/Hypot ) avoids problems that occur when squaring very large or very small numbers.
2020-12-01 19:25:57 +00:00
**Syntax**
``` sql
hypot(x, y)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2020-12-01 19:25:57 +00:00
- `x` — The first cathetus of a right-angle triangle. [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
- `y` — The second cathetus of a right-angle triangle. [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
**Returned value**
- The length of the hypotenuse of a right-angle triangle.
Type: [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
**Example**
Query:
``` sql
SELECT hypot(1, 1);
```
Result:
``` text
┌────────hypot(1, 1)─┐
│ 1.4142135623730951 │
└────────────────────┘
```
2022-06-02 10:55:18 +00:00
## log1p(x)
2020-12-01 19:25:57 +00:00
2020-12-03 20:59:17 +00:00
Calculates `log(1+x)` . The [function ](https://en.wikipedia.org/wiki/Natural_logarithm#lnp1 ) `log1p(x)` is more accurate than `log(1+x)` for small values of x.
2020-12-01 19:25:57 +00:00
**Syntax**
``` sql
log1p(x)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2020-12-01 19:25:57 +00:00
2020-12-03 20:59:17 +00:00
- `x` — Values from the interval: `-1 < x < +∞` . [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
2020-12-01 19:25:57 +00:00
**Returned value**
2020-12-03 20:59:17 +00:00
- Values from the interval: `-∞ < log1p(x) < +∞` .
2020-12-01 19:25:57 +00:00
Type: [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
**Example**
Query:
``` sql
SELECT log1p(0);
```
Result:
``` text
┌─log1p(0)─┐
│ 0 │
└──────────┘
```
**See Also**
- [log(x) ](../../sql-reference/functions/math-functions.md#logx-lnx )
2022-06-02 10:55:18 +00:00
## sign(x)
2021-01-24 09:15:47 +00:00
2021-03-12 02:12:28 +00:00
Returns the sign of a real number.
2021-01-24 09:15:47 +00:00
**Syntax**
``` sql
sign(x)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2021-01-24 09:15:47 +00:00
- `x` — Values from `-∞` to `+∞` . Support all numeric types in ClickHouse.
**Returned value**
- -1 for `x < 0`
- 0 for `x = 0`
- 1 for `x > 0`
2021-03-06 11:13:14 +00:00
**Examples**
2021-01-24 09:15:47 +00:00
2021-03-06 11:13:14 +00:00
Sign for the zero value:
2021-01-24 09:15:47 +00:00
``` sql
SELECT sign(0);
```
Result:
``` text
┌─sign(0)─┐
│ 0 │
└─────────┘
```
2021-03-06 11:13:14 +00:00
Sign for the positive value:
2021-01-24 09:15:47 +00:00
``` sql
SELECT sign(1);
```
Result:
``` text
┌─sign(1)─┐
│ 1 │
└─────────┘
```
2021-03-06 11:13:14 +00:00
Sign for the negative value:
2021-01-24 09:15:47 +00:00
``` sql
SELECT sign(-1);
```
Result:
``` text
┌─sign(-1)─┐
│ -1 │
└──────────┘
```
2022-06-02 10:55:18 +00:00
## degrees(x)
2022-01-19 23:31:04 +00:00
Converts the input value in radians to degrees.
**Syntax**
``` sql
degrees(x)
```
**Arguments**
- `x` — Input in radians. [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
**Returned value**
- Value in degrees.
Type: [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
**Example**
Query:
``` sql
SELECT degrees(3.141592653589793);
```
Result:
``` text
┌─degrees(3.141592653589793)─┐
│ 180 │
└────────────────────────────┘
```
2022-06-02 10:55:18 +00:00
## radians(x)
2022-01-19 23:31:04 +00:00
Converts the input value in degrees to radians.
**Syntax**
``` sql
radians(x)
```
**Arguments**
- `x` — Input in degrees. [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
**Returned value**
- Value in radians.
Type: [Float64 ](../../sql-reference/data-types/float.md#float32-float64 ).
**Example**
Query:
``` sql
SELECT radians(180);
```
Result:
``` text
┌──────radians(180)─┐
│ 3.141592653589793 │
└───────────────────┘
```