UNPKG

bizcharts

Version:
21 lines (20 loc) 933 B
/** * Our default sum is the [Kahan-Babuska algorithm](https://pdfs.semanticscholar.org/1760/7d467cda1d0277ad272deb2113533131dc09.pdf). * This method is an improvement over the classical * [Kahan summation algorithm](https://en.wikipedia.org/wiki/Kahan_summation_algorithm). * It aims at computing the sum of a list of numbers while correcting for * floating-point errors. Traditionally, sums are calculated as many * successive additions, each one with its own floating-point roundoff. These * losses in precision add up as the number of numbers increases. This alternative * algorithm is more accurate than the simple way of calculating sums by simple * addition. * * This runs on `O(n)`, linear time in respect to the array. * * @param {Array<number>} x input * @return {number} sum of all input numbers * @example * sum([1, 2, 3]); // => 6 */ declare function sumFnc(x: number[]): number; export default sumFnc;