> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Kahanの補償和アルゴリズムを使用して数値の合計を計算します

# sumKahan

<div id="sumKahan">
  ## sumKahan
</div>

導入バージョン: v1.1.0

[Kahanの補償和アルゴリズム](https://en.wikipedia.org/wiki/Kahan_summation_algorithm) を使用して、数値の合計を計算します。
[`sum`](/ja/reference/functions/aggregate-functions/sum) 関数よりも低速です。
補償が機能するのは [Float](/ja/reference/data-types/float) 型のみです。

**構文**

```sql theme={null}
sumKahan(x)
```

**引数**

* `x` — 入力値。[`Integer`](/ja/reference/data-types/int-uint) または [`Float`](/ja/reference/data-types/float) または [`Decimal`](/ja/reference/data-types/decimal)

**戻り値**

数値の合計を返します。[`(U)Int*`](/ja/reference/data-types/int-uint) または [`Float*`](/ja/reference/data-types/float) または [`Decimal`](/ja/reference/data-types/decimal)

**例**

**Kahan加算による精度向上の例**

```sql title=Query theme={null}
SELECT sum(0.1), sumKahan(0.1) FROM numbers(10);
```

```response title=Response theme={null}
┌───────────sum(0.1)─┬─sumKahan(0.1)─┐
│ 0.9999999999999999 │             1 │
└────────────────────┴───────────────┘
```
