# fix\(costs\): avoid overflow in daily averages \(\#576\) · lucenx/codexbar-plasma

[View on GitCafe](https://git.cafe/lucenx/codexbar-plasma/commit/8826e05cc68755131e111a7a6adaebbfc366e637)

Repository: [lucenx/codexbar-plasma](https://git.cafe/lucenx/codexbar-plasma)

Visibility: public

Requested revision: 8826e05cc68755131e111a7a6adaebbfc366e637

Requested commit: 8826e05cc68755131e111a7a6adaebbfc366e637

Commit: 8826e05cc68755131e111a7a6adaebbfc366e637

Tree: 875bd14d095417fe208a29014b62d7838f841c14

Author: Simone

Committer: GitHub

## Message

```
fix(costs): avoid overflow in daily averages (#576)

* fix(costs): avoid overflow in daily averages

Use an incremental nonnegative mean so finite daily amounts cannot overflow their intermediate sum. Add a direct regression for cost and token averages, missing days and zero days. Update usage, cost-history and Unreleased documentation; TODO parity work is unaffected. Verified with make check, with local optional KDE module skips and partial Plasma type coverage.

* fix(costs): preserve ordinary average rounding

Keep the original sum/count result whenever the sum is finite, using the incremental mean only on overflow. Reproduced the review case where [803, 136, 8, 19] displayed 241 instead of 242; both input orders now have a direct regression. Update the cost-history guide. The existing changelog entry and TODO scope remain accurate. All 186 focused QtTests and make check pass, with the same optional KDE coverage limits.
```

## Parents

- [ccd67937717f30ac89b3bdf39f6753838ca03b9c](https://git.cafe/lucenx/codexbar-plasma/commit/ccd67937717f30ac89b3bdf39f6753838ca03b9c?format=markdown)

[Source at this commit](https://git.cafe/lucenx/codexbar-plasma/tree/8826e05cc68755131e111a7a6adaebbfc366e637?format=markdown)
