MPE/iX Shell and Utilities Reference Manual, Vol 1

dc(1) MPE/iX Shell and Utilities dc(1)
45+2* (18)
452+* (28)
452*- (-6)
If you are experimenting with dc to see how this works, you can type p to print out the top
value on the stack and f to print out the full stack.
The Scaling Factor
One of dc’s great virtues is its ability to deal with numbers of arbitrary size and precision
dc is not constrained by the hardware’s restrictions on number size or precision.
Many arithmetic calculations use a scaling factor, an integer greater than or equal to zero, and
strictly less than 100. The scaling factor affects how many decimal places dc uses when mak-
ing calculations.
The default scaling factor begins at zero (no decimal places). This can be confusing; for
example, if you try
12/p
to divide 1 by 2 and print the result, dc prints 0. The real answer is 0.5 but a scaling factor
of 0 tells dc not to keep track of fractions when doing arithmetic.
You can set a different default scaling factor with the k operation. This pops the top value
from the stack and sets that value to the new default scaling factor. For example,
4k
sets the default scaling factor to 4. Now if you try
12/p
the result is .5000.
As our discussion of arithmetic operations points out, the number of decimal places in the
operands also affects the number of decimal places in the answer. Thus the scaling factor is
not the only influence on the precision of the calculations.
The K operation pushes the current default scaling factor onto the stack.
Basic Operators
The following list is the operators recognized by dc and the effects that they have.
+ pops the top two values from the stack, adds them, then pushes the result onto the
stack. The number of decimal places in the result is the maximum number of decimal
places in the two operands; the scaling factor has no effect.
Commands and Utilities 1-157