---
title: SQL math functions
description: Use math functions to perform mathematical operations in SQL queries.
url: https://docs.influxdata.com/influxdb3/core/reference/sql/functions/math/
estimated_tokens: 20349
product: InfluxDB 3 Core
version: core
---

# SQL math functions

The InfluxDB 3 Core SQL implementation supports the following math functions for performing mathematic operations:

-   [abs](#abs)
-   [acos](#acos)
-   [acosh](#acosh)
-   [asin](#asin)
-   [asinh](#asinh)
-   [atan](#atan)
-   [atanh](#atanh)
-   [atan2](#atan2)
-   [cbrt](#cbrt)
-   [ceil](#ceil)
-   [cos](#cos)
-   [cosh](#cosh)
-   [cot](#cot)
-   [degrees](#degrees)
-   [exp](#exp)
-   [factorial](#factorial)
-   [floor](#floor)
-   [gcd](#gcd)
-   [isnan](#isnan)
-   [iszero](#iszero)
-   [lcm](#lcm)
-   [ln](#ln)
-   [log](#log)
-   [log10](#log10)
-   [log2](#log2)
-   [nanvl](#nanvl)
-   [pi](#pi)
-   [power](#power)
-   [pow](#pow)
-   [radians](#radians)
-   [random](#random)
-   [round](#round)
-   [signum](#signum)
-   [sin](#sin)
-   [sinh](#sinh)
-   [sqrt](#sqrt)
-   [tan](#tan)
-   [tanh](#tanh)
-   [trunc](#trunc)

## abs

Returns the absolute value of a number.

```sql
abs(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-abs-query-example)

View `abs` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT abs(temp) AS abs FROM home LIMIT 3
```

| abs |
| --- |
| 21 |
| 23 |
| 22.7 |

## acos

Returns the arc cosine or inverse cosine of a number.

```sql
acos(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-acos-query-example)

View `acos` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT acos(temp * .01) AS acos FROM home LIMIT 3
```

| acos |
| --- |
| 1.359221367036801 |
| 1.3387186439321834 |
| 1.3418001704498232 |

## acosh

Returns the area hyperbolic cosine or inverse hyperbolic cosine of a number.

```sql
acosh(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-acosh-query-example)

View `acosh` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT acosh(temp) AS acosh FROM home LIMIT 3
```

| acosh |
| --- |
| 3.737102242198924 |
| 3.8281684713331012 |
| 3.8150265878962055 |

## asin

Returns the arc sine or inverse sine of a number.

```sql
asin(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-asin-query-example)

View `asin` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT asin(temp * .01) AS asin FROM home LIMIT 3
```

| asin |
| --- |
| 0.2115749597580956 |
| 0.23207768286271319 |
| 0.22899615634507337 |

## asinh

Returns the area hyperbolic sine or inverse hyperbolic sine of a number.

```sql
asinh(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-asinh-query-example)

View `asinh` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT asinh(temp) AS asinh FROM home LIMIT 3
```

| asinh |
| --- |
| 3.7382360302615427 |
| 3.8291136516208812 |
| 3.8159969160459988 |

## atan

Returns the arc tangent or inverse tangent of a number.

```sql
atan(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-atan-query-example)

View `atan` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT atan(temp * .01) AS atan FROM home LIMIT 3
```

| atan |
| --- |
| 0.206992194219821 |
| 0.22606838799388393 |
| 0.22321725383717603 |

## atanh

Returns the area hyperbolic tangent or inverse hyperbolic tangent of a number.

```sql
atanh(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-atanh-query-example)

View `atanh` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT atanh(temp * .01) AS atanh FROM home LIMIT 3
```

| atanh |
| --- |
| 0.21317134656485978 |
| 0.2341894667593668 |
| 0.23102419806174476 |

## atan2

Returns the arc tangent or inverse tangent of `expression_y / expression_x`.

```sql
atan2(expression_y, expression_x)
```

### Arguments

-   **expression\_y**: First numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
-   **expression\_x**: Second numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-atan2-query-example)

View `atan2` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT atan2(temp, hum) AS atan2 FROM home LIMIT 3
```

| atan2 |
| --- |
| 0.5292859396993504 |
| 0.5660139100632452 |
| 0.5613335864315844 |

## cbrt

Returns the cube root of a number.

```sql
cbrt(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-cbrt-query-example)

View `cbrt` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT cbrt(temp) AS cbrt FROM home LIMIT 3
```

| cbrt |
| --- |
| 2.7589241763811208 |
| 2.843866979851566 |
| 2.831448188528187 |

## ceil

Returns the nearest integer greater than or equal to a number.

```sql
ceil(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-ceil-query-example)

View `ceil` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT ceil(temp) AS ceil FROM home LIMIT 3
```

| ceil |
| --- |
| 21 |
| 23 |
| 23 |

## cos

Returns the cosine of a number.

```sql
cos(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-cos-query-example)

View `cos` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT cos(temp) AS cos FROM home LIMIT 3
```

| cos |
| --- |
| -0.5477292602242684 |
| -0.5328330203333975 |
| -0.7591100556583898 |

## cosh

Returns the hyperbolic cosine of a number.

```sql
cosh(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-cosh-query-example)

View `cosh` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT cosh(temp) AS cosh FROM home LIMIT 3
```

| cosh |
| --- |
| 659407867.2416073 |
| 4872401723.124452 |
| 3609563974.9715896 |

## cot

Returns the cotangent of a number.

```sql
cot(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.

[](#view-cot-query-example)

View `cot` query example

*The following example uses the [Random numbers sample dataset](/influxdb3/core/reference/sample-data/#random-numbers-sample-data).*

```sql
SELECT cot(a) AS cot FROM numbers LIMIT 3
```

| cot |
| --- |
| 2.9293528483724423 |
| 3.705570308335524 |
| -3.314652247498361 |

## degrees

Converts radians to degrees.

```sql
degrees(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-degrees-query-example)

View `degrees` query example

*The following example uses the [Random numbers sample dataset](/influxdb3/core/reference/sample-data/#random-numbers-sample-data).*

```sql
SELECT degrees(a) AS degrees FROM numbers LIMIT 3
```

| degrees |
| --- |
| 19.428488139031185 |
| -44.403317464348774 |
| -52.771542485064785 |

## exp

Returns the base-e exponential of a number.

```sql
exp(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to use as the exponent. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-exp-query-example)

View `exp` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT exp(temp) AS exp FROM home LIMIT 3
```

| exp |
| --- |
| 1318815734.4832146 |
| 9744803446.248903 |
| 7219127949.943179 |

## factorial

Returns 1 if value is less than 2.

```sql
factorial(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Must be an integer (`BIGINT`). Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-factorial-query-example)

View `factorial` query example

*The following example uses the [Random numbers sample dataset](/influxdb3/core/reference/sample-data/#random-numbers-sample-data).*

```sql
SELECT factorial((b + 2)::BIGINT) AS factorial FROM numbers LIMIT 3
```

| factorial |
| --- |
| 1 |
| 2 |
| 1 |

## floor

Returns the nearest integer less than or equal to a number.

```sql
floor(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-floor-query-example)

View `floor` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT floor(temp) AS floor FROM home LIMIT 3
```

| floor |
| --- |
| 21 |
| 23 |
| 22 |

## gcd

Returns the greatest common divisor of `expression_x` and `expression_y`. Returns `0` if both inputs are zero.

```sql
gcd(expression_x, expression_y)
```

### Arguments

-   **expression\_x**: First numeric expression to operate on. Must be an integer (`BIGINT`). Can be a constant, column, or function, and any combination of arithmetic operators.
-   **expression\_y**: Second numeric expression to operate on. Must be an integer (`BIGINT`). Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-gcd-query-example)

View `gcd` query example

*The following example uses the [Random numbers sample dataset](/influxdb3/core/reference/sample-data/#random-numbers-sample-data).*

```sql
SELECT gcd((a * 5)::BIGINT, (b * 5)::BIGINT) AS gcd FROM numbers LIMIT 3
```

| gcd |
| --- |
| 1 |
| 3 |
| 2 |

## isnan

Returns `true` if a given number is ±NaN, otherwise returns `false`.

```sql
isnan(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Must be a float (`DOUBLE`). Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-isnan-query-example)

View `isnan` query example

*The following example uses the [Table value constructor](/influxdb3/core/reference/sql/table-value-constructor/) to simulate sample data.*

```sql
SELECT isnan(a)
FROM
  (VALUES (4.56),
          ('NaN'::DOUBLE),
          (16.2)
  ) AS data(a)
```

| isnan |
| --- |
| false |
| true |
| false |

## iszero

Returns `true` if the given number is ±0.0, otherwise returns `false`.

```sql
iszero(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-iszero-query-example)

View `iszero` query example

*The following example uses the [Table value constructor](/influxdb3/core/reference/sql/table-value-constructor/) to simulate sample data.*

```sql
SELECT iszero(a)
FROM
  (VALUES (0),
          (1),
          (2)
  ) AS data(a)
```

| iszero |
| --- |
| true |
| false |
| false |

## lcm

Returns the least common multiple of `expression_x` and `expression_y`. Returns `0` if either input is zero.

```sql
lcm(expression_x, expression_y)
```

### Arguments

-   **expression\_x**: First numeric expression to operate on. Must be an integer (`BIGINT`). Can be a constant, column, or function, and any combination of arithmetic operators.
-   **expression\_y**: Second numeric expression to operate on. Must be an integer (`BIGINT`). Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-lcm-query-example)

View `lcm` query example

*The following example uses the [Random numbers sample dataset](/influxdb3/core/reference/sample-data/#random-numbers-sample-data).*

```sql
SELECT lcm((a * 10)::BIGINT, (b * 10)::BIGINT) AS lcm FROM numbers LIMIT 3
```

| lcm |
| --- |
| 3 |
| 7 |
| 36 |

## ln

Returns the natural logarithm of a number.

```sql
ln(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-ln-query-example)

View `ln` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT ln(temp) AS ln FROM home LIMIT 3
```

| ln |
| --- |
| 3.044522437723423 |
| 3.1354942159291497 |
| 3.122364924487357 |

## log

Returns the base-x logarithm of a number.

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

#### Arguments

-   **base**: Base numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators. Default is `10`.
-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-log-query-example)

View `log` query example

*The following example uses the sample data set provided in the {{ influxdb3/home-sample-link }}.*

```sql
SELECT
  temp,
  log(2, temp) AS temp_log2,
  log(4, temp) AS temp_log4,
  log(temp) AS temp_log10
FROM home
LIMIT 3
```

| temp | temp_log2 | temp_log4 | temp_log10 |
| --- | --- | --- | --- |
| 21 | 4.392317422778761 | 2.1961587113893803 | 1.322219294733919 |
| 23 | 4.523561956057013 | 2.2617809780285065 | 1.3617278360175928 |
| 22.7 | 4.504620392403553 | 2.2523101962017766 | 1.3560258571931225 |

## log10

Returns the base-10 logarithm of a number.

```sql
log10(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-log10-query-example)

View `log10` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT log10(temp) AS log10 FROM home LIMIT 3
```

| log10 |
| --- |
| 1.3222192947339193 |
| 1.3617278360175928 |
| 1.3560258571931227 |

## log2

Returns the base-2 logarithm of a number.

```sql
log2(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-log2-query-example)

View `log2` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT log2(temp) AS log2 FROM home LIMIT 3
```

| log2 |
| --- |
| 4.392317422778761 |
| 4.523561956057013 |
| 4.504620392403552 |

## nanvl

Returns the first argument if it’s not `±NaN`. Otherwise returns the second argument.

```sql
nanvl(expression_x, expression_y)
```

### Arguments

-   **expression\_x**: Numeric expression to return if it’s not `NaN`. Can be a constant, column, or function, and any combination of arithmetic operators.
-   **expression\_y**: Numeric expression to return if the first expression is `NaN`. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-nanvl-query-example)

View `nanvl` query example

*The following example uses the [Table value constructor](/influxdb3/core/reference/sql/table-value-constructor/) to simulate sample data.*

```sql
SELECT nanvl(a, 0.0) AS nanvl
FROM
  (VALUES (4.56),
          ('NaN'::DOUBLE),
          (16.2)
  ) AS data(a)
```

| nanvl |
| --- |
| 4.56 |
| 0 |
| 16.2 |

## pi

Returns an approximate value of π.

```sql
pi()
```

[](#view-pi-query-example)

View `pi` query example

```sql
SELECT pi() AS pi
```

| pi |
| --- |
| 3.141592653589793 |

## power

Returns a base expression raised to the power of an exponent.

```sql
power(base, exponent)
```

##### Aliases

-   `pow`

### Arguments

-   **base**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
-   **exponent**: Exponent numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-power-query-example)

View `power` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT power(temp, hum * .1) AS power FROM home LIMIT 3
```

| power |
| --- |
| 55817.099910217476 |
| 85007.01501569824 |
| 78569.38332452129 |

## `pow`

*Alias of [power](#power).*

## radians

Converts degrees to radians.

```sql
radians(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-radians-query-example)

View `radians` query example

*The following example uses the [Random numbers sample dataset](/influxdb3/core/reference/sample-data/#random-numbers-sample-data).*

```sql
SELECT radians(b) AS radians FROM numbers LIMIT 3
```

| radians |
| --- |
| -0.0028561101762876 |
| 0.0023917008411179744 |
| -0.008428949313343818 |

## random

Returns a random float value between 0 and 1. The random seed is unique to each row.

```sql
random()
```

[](#view-random-query-example)

View `random` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT temp * random() AS random FROM home LIMIT 3
```

Due to the nature of the function, your results will not match the results below.

| random |
| --- |
| 0.5030770374815072 |
| 12.938847036567514 |
| 2.8204596545385385 |

## round

Rounds a number to the nearest integer.

```sql
round(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-round-query-example)

View `round` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT round(temp) AS round FROM home LIMIT 3
```

| round |
| --- |
| 21 |
| 23 |
| 23 |

## signum

Returns the sign of a number. Negative numbers return `-1`. Zero and positive numbers return `1`.

```sql
signum(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-signum-query-example)

View `signum` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT signum(temp - 23) AS signum FROM home LIMIT 3
```

| signum |
| --- |
| -1 |
| 1 |
| -1 |

## sin

Returns the sine of a number.

```sql
sin(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-sin-query-example)

View `sin` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT sin(temp) AS sin FROM home LIMIT 3
```

| sin |
| --- |
| 0.8366556385360561 |
| -0.8462204041751706 |
| -0.6509623056662469 |

## sinh

Returns the hyperbolic sine of a number.

```sql
sinh(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-sinh--query-example)

View `sinh` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT sinh(temp) AS sinh FROM home LIMIT 3
```

| sinh |
| --- |
| 659407867.2416073 |
| 4872401723.124452 |
| 3609563974.9715896 |

## sqrt

Returns the square root of a number.

```sql
sqrt(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-sqrt-query-example)

View `sqrt` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT sqrt(temp) AS sqrt FROM home LIMIT 3
```

| sqrt |
| --- |
| 4.58257569495584 |
| 4.795831523312719 |
| 4.764451699828638 |

## tan

Returns the tangent of a number.

```sql
tan(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-tan-query-example)

View `tan` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT tan(temp) AS tan FROM home LIMIT 3
```

| tan |
| --- |
| -1.5274985276366035 |
| 1.5881530833912738 |
| 0.8575335036257101 |

## tanh

Returns the hyperbolic tangent of a number.

```sql
tanh(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-tanh-query-example)

View `tanh` query example

*The following example uses the [Random numbers sample dataset](/influxdb3/core/reference/sample-data/#random-numbers-sample-data).*

```sql
SELECT tanh(a) AS tanh FROM numbers LIMIT 3
```

| tanh |
| --- |
| 0.32666571332086836 |
| -0.6498182711525403 |
| -0.7263877015335474 |

## trunc

Truncates a number toward zero (at the decimal point).

```sql
trunc(numeric_expression)
```

### Arguments

-   **numeric\_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.

[](#view-trunc-query-example)

View `trunc` query example

*The following example uses the {{ influxdb3/home-sample-link }}.*

```sql
SELECT trunc(temp) AS trunc FROM home LIMIT 3
```

| trunc |
| --- |
| 21 |
| 23 |
| 22 |
