Decimal arithmetic
ADD, SUBTRACT, MULTIPLY, DIVIDE and COMPUTE, and then the digits a plain statement throws away against the ones ROUNDED keeps. ON SIZE ERROR, intermediate precision and a running total in a loop follow. The part closes on why money is decimal and on a wrong total that is traced and fixed.
3.1
ADD and SUBTRACT
TO, FROM, GIVING, several operands at once, and the sign of the result
Open
3.2
MULTIPLY and DIVIDE
BY, GIVING, REMAINDER, DIVIDE INTO, and a division that does not fit
Open
3.3
COMPUTE and arithmetic expressions
**, unary minus, precedence, and one COMPUTE against several separate verbs
Open
3.4
ROUNDED and truncation
the digits a plain statement throws away, ROUNDED, and the half-up rule of COBOL
Open
3.5
ON SIZE ERROR
a receiving field too small, what the statement did to the field, NOT ON SIZE ERROR
Open
3.6
Intermediate precision
the temporary field the compiler uses, why COMPUTE beats a chain of MOVEs, and -W truncation
Open
3.7
Why money is decimal
COMP-3 against a binary float, the cent a float loses, and the same sum in both
Open
3.8
Arithmetic in a loop
a running total under PERFORM VARYING, rounding once at the end, and the total checked by hand
Open
3.9
Edited numeric output
Z, the comma, the decimal point, CR and DB, the currency sign, and a printed amount
Open
3.10
An arithmetic bug, found and fixed
a wrong total, the truncation that caused it, the fix, and the check that proves the fix
Open