mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 22:19:14 +00:00
20 lines
309 B
Go
20 lines
309 B
Go
package stats
|
|
|
|
// https://en.wikipedia.org/wiki/Kahan_summation_algorithm
|
|
|
|
type kahan struct{ hi, lo float64 }
|
|
|
|
func (k *kahan) add(x float64) {
|
|
y := k.lo + x
|
|
t := k.hi + y
|
|
k.lo = y - (t - k.hi)
|
|
k.hi = t
|
|
}
|
|
|
|
func (k *kahan) sub(x float64) {
|
|
y := k.lo - x
|
|
t := k.hi + y
|
|
k.lo = y - (t - k.hi)
|
|
k.hi = t
|
|
}
|