A program that does nothing more than add up a stream of numbers. The program works with 64 bit foating point numbers) and the program is intended for use in shell scripting.
To add a stream of numbers is such a simple operation and something I have wanted to do in various bash scripts recently but there does not seem to be a simple straight for unix filter for this purpose. So I have tried using various techniques, including those suggested here.
Written in the Rust programming language this program ought to be quick and since it uses the Kahan summation algorithm it also ought to significantly reduce the numerical error compared with a niave implementation.
Install the latest version of Rust and build using 'cargo':
$ cargo install
Examples using bash:
Add all the numbers from 1 to 10:
$ seq 1 10 | dumbsum
55Add up a list of numbers held in a file called abc.txt:
$ cat abc.txt | dumbsumAdd a list of numbers entered as a Here document:
$ dumbsum <<EOF
> 11
> 22
> 33
> 44
> 55
> EOF
165Using a Here string:
$ dumbsum <<< '1
> 2
> 3
> 4
> 5'
15Add numbers separated by newlines:
$ printf "1\n2" | dumbsum
3$ printf "101\n202" | dumbsum
303Add a sequence of space separated numbers:
$ echo 15 24 33 42 51 | sed 's/ /\n/g' | dumbsum
165Add up all the numbers returned by the disk usage (du) command:
$ du | cut -f 1 | dumbsum
103022