Skip to main content
Module

x/simplestatistics/index.js>sum

simple statistics for node & browser javascript
Go to Latest
function sum
import { sum } from "https://deno.land/x/simplestatistics@v7.7.5/index.js";

Our default sum is the Kahan-Babuska algorithm. This method is an improvement over the classical 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 in O(n), linear time, with respect to the length of the array.

Examples

sum([1, 2, 3]); // => 6

Parameters

x

input