From aa4f05512e5c2f58a051150f474dc047c856fa29 Mon Sep 17 00:00:00 2001 From: Blargian Date: Mon, 29 Apr 2024 07:25:38 +0200 Subject: [PATCH] Add stddevPopStable --- .../reference/stddevpop.md | 2 +- .../reference/stddevpopstable.md | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 docs/en/sql-reference/aggregate-functions/reference/stddevpopstable.md diff --git a/docs/en/sql-reference/aggregate-functions/reference/stddevpop.md b/docs/en/sql-reference/aggregate-functions/reference/stddevpop.md index cb9abd79f71..b0514b0ede1 100644 --- a/docs/en/sql-reference/aggregate-functions/reference/stddevpop.md +++ b/docs/en/sql-reference/aggregate-functions/reference/stddevpop.md @@ -12,7 +12,7 @@ Alias: - `STDDEV_POP` :::note -This function uses a numerically unstable algorithm. If you need [numerical stability](https://en.wikipedia.org/wiki/Numerical_stability) in calculations, use the `stddevPopStable` function. It works slower but provides a lower computational error. +This function uses a numerically unstable algorithm. If you need [numerical stability](https://en.wikipedia.org/wiki/Numerical_stability) in calculations, use the [`stddevPopStable`](../reference/stddevpopstable.md) function. It works slower but provides a lower computational error. ::: **Syntax** diff --git a/docs/en/sql-reference/aggregate-functions/reference/stddevpopstable.md b/docs/en/sql-reference/aggregate-functions/reference/stddevpopstable.md new file mode 100644 index 00000000000..7455539ccc1 --- /dev/null +++ b/docs/en/sql-reference/aggregate-functions/reference/stddevpopstable.md @@ -0,0 +1,53 @@ +--- +slug: /en/sql-reference/aggregate-functions/reference/stddevpopstable +sidebar_position: 30 +--- + +# stddevPopStable + +The result is equal to the square root of [varPop](../../../sql-reference/aggregate-functions/reference/varpop.md). Unlike [`stddevPop`](../reference/stddevpop.md), this function uses a numerically stable algorithm. It works slower but provides a lower computational error. + +:::note +This function uses a numerically unstable algorithm. If you need [numerical stability](https://en.wikipedia.org/wiki/Numerical_stability) in calculations, use the `stddevPopStable` function. It works slower but provides a lower computational error. +::: + +**Syntax** + +```sql +stddevPopStable(x) +``` + +**Parameters** + +- `x`: Population of values to find the standard deviation of. [(U)Int*](../../data-types/int-uint.md), [Float*](../../data-types/float.md), [Decimal*](../../data-types/decimal.md). + +**Returned value** + +Standard deviation of `x`. [Float64](../../data-types/float.md). + +**Example** + +Query: + +```sql +DROP TABLE IF EXISTS test_data; +CREATE TABLE test_data +( + population Float64, +) +ENGINE = Log; + +INSERT INTO test_data SELECT randUniform(5.5, 10) FROM numbers(1000000) + +SELECT + stddevPopStable(population) AS stddev +FROM test_data; +``` + +Result: + +```response +┌─────────────stddev─┐ +│ 1.2999977786592576 │ +└────────────────────┘ +```