PROPHET/OS
NAME
sum: adds every number that comes through in, exactly, and writes the total
SYNOPSIS
sum [-d] sum selbsttest
DESCRIPTION
Adds every number that comes through in, exactly, and writes the total.
It adds in the decimal machine of this tree (lib/pml/decimal, the same one calc stands on), so 0,1 + 0,2 is 0,3. bc has a scale and rounds to it, and everything that adds in binary floating point answers 0,30000000000000004. A sum that had to be rounded says so on err, and a word that is no number is skipped and said as well: a sum over text may not read like a sum over numbers.
Every number of a line counts, not only the first: 3 4 is seven. With -d the count of the numbers stands behind the total.
It exists because the build asks this eight times, every time as paste -sd+ | bc, so with two foreign tools for one addition, and neither of them is on this machine (R10-SELF-06). It carries no arithmetic of its own: whoever writes a number parser beside the decimal machine has written a second one that will differ from it.
sum selbsttest drives eight cases, without a keyboard: the exact 0.1 + 0.2, the + as a separator, a word that is no number, and the counts beside the sum. A filter has to be checkable this way, because a filter without input waits for input (R11-BEREICH-02).
EXAMPLE
$ echo 12 30 0.5 | sum 42.5