Skip to content

wozgonon/dumbsum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

dumbsum

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.

To build

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
55

Add up a list of numbers held in a file called abc.txt:

$ cat abc.txt | dumbsum

Add a list of numbers entered as a Here document:

$ dumbsum <<EOF
> 11
> 22
> 33
> 44
> 55
> EOF
165

Using a Here string:

$ dumbsum <<< '1
> 2
> 3
> 4
> 5'
15

Add numbers separated by newlines:

$ printf "1\n2" | dumbsum
3
$ printf "101\n202" | dumbsum
303

Add a sequence of space separated numbers:

$ echo 15 24 33 42 51 | sed 's/ /\n/g' | dumbsum
165

Add up all the numbers returned by the disk usage (du) command:

$ du  | cut -f 1 | dumbsum
103022

About

A program that does nothing more than add up a stream of numbers

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages