(values: Iterable<number>)
| 68 | * |
| 69 | * The deviation `x − mean` of two finite numbers of opposite signs can |
| 70 | * overflow (`1e308 − (−1e308)`), and the update then gave an infinite mean |
| 71 | * and a NEGATIVE `M2`: the variance of `[1e308, −1e308]` was `−∞`. `M2` |
| 72 | * itself can overflow while the variance fits (the population variance of |
| 73 | * `[1e154, −1e154]` is `1e308`). From the first update that would overflow |
| 74 | * on, the update runs on the data divided by `scale`, |
| 75 | * the largest magnitude seen (the mean and `M2` are converted to those |
| 76 | * units, and again when a larger magnitude comes). `scale` is returned |
| 77 | * with `M2` (0 when the data never left the first branch), and the caller |
| 78 | * divides `M2` by the count before it multiplies by `scale²`, which gives |
| 79 | * `+∞` only when the variance itself is past the largest number. Data whose deviations do not overflow never leaves the first |
| 80 | * branch, so its result is the same as before, bit for bit. |
| 81 | */ |
| 82 | function welford(values: Iterable<number>): { |
| 83 | n: number; |
| 84 | m2: number; |
no outgoing calls
no test coverage detected