> ## 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`](/zh/reference/functions/aggregate-functions/sum) 函数更慢。
补偿机制仅对 [Float](/zh/reference/data-types/float) 类型有效。

**语法**

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

**参数**

* `x` — 输入值。[`Integer`](/zh/reference/data-types/int-uint) 或 [`Float`](/zh/reference/data-types/float) 或 [`Decimal`](/zh/reference/data-types/decimal)

**返回值**

返回数值之和。[`(U)Int*`](/zh/reference/data-types/int-uint) 或 [`Float*`](/zh/reference/data-types/float) 或 [`Decimal`](/zh/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 │
└────────────────────┴───────────────┘
```
