blog-2025-11-06_float_sums
> Suppose you have an array of floating-point numbers, and wish to sum them. You might naively think you can simply add them
> This however can easily result in an arbitrarily large accumulated error.
[Taming Floating-Point Sums](https://orlp.net/blog/taming-float-sums/)
tried this in kotlin, where even the built in `sum` function uses the naive approach:
```kotlin
// prints 16777216,00
println("%.2f".format(FloatArray(100_000_000) { 1.0f }.sum()))
```
floating point addition isn't associative, commutative nor distributive.
edited by: stefs at Thursday, November 6, 2025, 11:11:25 AM Coordinated Universal Time
view