﻿---
title: Math functions
description: PromQL mathematical, trigonometric, and rounding functions in Elasticsearch.
url: https://www.elastic.co/elastic/docs-builder/docs/3562/reference/query-languages/promql/functions/math
products:
  - Elasticsearch
applies_to:
  - Elastic Cloud Serverless: Generally available
  - Elastic Stack: Preview in 9.4
---

# Math functions
These functions perform mathematical, trigonometric, and rounding operations on instant vectors.

## `abs`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Returns the input vector with all sample values converted to their absolute value.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
abs(rate(http_requests_total[5m]))
```

**Differences from Prometheus**
For the minimum `integer` or `long` value, whose absolute value cannot be represented, Elasticsearch returns `null` and emits a warning. Prometheus, which operates on floating-point values, returns the absolute value instead.

## `acos`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Calculates the arccosine of all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
acos(some_metric)
```

**Differences from Prometheus**
For inputs outside the range [-1, 1], Elasticsearch returns `null` and emits a warning, rather than the `NaN` that Prometheus returns.

## `acosh`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Calculates the inverse hyperbolic cosine of all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
acosh(some_metric)
```

**Differences from Prometheus**
For inputs below 1, Elasticsearch returns `null` and emits a warning, rather than the `NaN` that Prometheus returns.

## `asin`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Calculates the arcsine of all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
asin(some_metric)
```

**Differences from Prometheus**
For inputs outside the range [-1, 1], Elasticsearch returns `null` and emits a warning, rather than the `NaN` that Prometheus returns.

## `asinh`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Calculates the inverse hyperbolic sine of all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
asinh(some_metric)
```


## `atan`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Calculates the arctangent of all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
atan(some_metric)
```


## `atanh`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Calculates the inverse hyperbolic tangent of all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
atanh(some_metric)
```

**Differences from Prometheus**
For an input whose absolute value is 1 or greater, Elasticsearch returns `null` and emits a warning, rather than the `±Inf` or `NaN` that Prometheus returns.

## `ceil`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Rounds the sample values of all elements up to the nearest integer.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
ceil(rate(http_requests_total[5m]))
```


## `clamp`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Clamps the sample values of all elements to be within [min, max].
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
  <definition term="min (scalar)">
    Minimum value.
  </definition>
  <definition term="max (scalar)">
    Maximum value.
  </definition>
</definitions>

**Example**
```
clamp(http_requests_total, 0, 100)
```

**Differences from Prometheus**
Does not implement Prometheus's special case of returning an empty vector when `min` is greater than `max`; it always returns clamped values.

## `clamp_max`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Clamps the sample values of all elements to have an upper limit of max.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
  <definition term="max (scalar)">
    Maximum value.
  </definition>
</definitions>

**Example**
```
clamp_max(http_requests_total, 100)
```


## `clamp_min`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Clamps the sample values of all elements to have a lower limit of min.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
  <definition term="min (scalar)">
    Minimum value.
  </definition>
</definitions>

**Example**
```
clamp_min(http_requests_total, 0)
```


## `cos`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Calculates the cosine of all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
cos(some_metric)
```


## `cosh`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Calculates the hyperbolic cosine of all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
cosh(some_metric)
```

**Differences from Prometheus**
On numeric overflow for large-magnitude inputs, Elasticsearch returns `null` and emits a warning, rather than the `±Inf` that Prometheus returns.

## `deg`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Converts input values from radians to degrees for all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
deg(some_metric)
```

**Differences from Prometheus**
For `NaN` or infinite inputs, Elasticsearch returns `null` and emits a warning, instead of returning the value unchanged.

## `exp`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Calculates the exponential function for all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
exp(rate(http_requests_total[5m]))
```


## `floor`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Rounds the sample values of all elements down to the nearest integer.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
floor(rate(http_requests_total[5m]))
```


## `ln`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Calculates the natural logarithm for all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
ln(memory_usage_bytes)
```

**Differences from Prometheus**
For an input of zero or a negative number, Elasticsearch returns `null` and emits a warning, rather than the `-Inf` (for zero) or `NaN` (for negatives) that Prometheus returns.

## `log10`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Calculates the decimal logarithm for all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
log10(http_requests_total)
```

**Differences from Prometheus**
For an input of zero or a negative number, Elasticsearch returns `null` and emits a warning, rather than the `-Inf` (for zero) or `NaN` (for negatives) that Prometheus returns.

## `log2`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Calculates the binary logarithm for all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
log2(memory_usage_bytes)
```

**Differences from Prometheus**
For an input of zero or a negative number, Elasticsearch returns `null` and emits a warning, rather than the `-Inf` (for zero) or `NaN` (for negatives) that Prometheus returns.

## `pi`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Returns the value of pi.
**Return type**
`scalar`
**Example**
```
pi()
```


## `rad`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Converts input values from degrees to radians for all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
rad(some_metric)
```


## `round`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Rounds the sample values to the nearest integer, or to the nearest multiple of the optional argument.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
  <definition term="to_nearest (scalar, optional)">
    Round to nearest multiple of this value.
  </definition>
</definitions>

**Example**
```
round(rate(http_requests_total[5m]))
```

**Differences from Prometheus**
With a `to_nearest` argument, ties round up, matching Prometheus. Called with a single argument, a `NaN` input returns `0` instead of `NaN`.

## `sgn`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Returns the sign of the sample values: -1 for negative, 0 for zero, and 1 for positive values.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
sgn(delta(queue_depth[5m]))
```


## `sin`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Calculates the sine of all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
sin(some_metric)
```


## `sinh`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Calculates the hyperbolic sine of all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
sinh(some_metric)
```

**Differences from Prometheus**
On numeric overflow for large-magnitude inputs, Elasticsearch returns `null` and emits a warning, rather than the `±Inf` that Prometheus returns.

## `sqrt`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Calculates the square root of all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
sqrt(http_requests_total)
```

**Differences from Prometheus**
For a negative input, Elasticsearch returns `null` and emits a warning, rather than the `NaN` that Prometheus returns.

## `tan`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Calculates the tangent of all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
tan(some_metric)
```


## `tanh`

<applies-to>Elastic Stack: Preview in 9.4</applies-to>
Calculates the hyperbolic tangent of all elements in the input vector.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
tanh(some_metric)
```