up | Inhaltsverzeichniss | Kommentar

Manual page for DC(1)

dc - desk calculator

SYNOPSIS

dc [ filename ]

DESCRIPTION

dc is an arbitrary precision arithmetic package. Ordinarily it operates on decimal integers, but an input base, output base, and a number of fractional digits to be maintained may be specified. The overall structure of dc is a stacking (reverse Polish) calculator. If an argument is given, input is taken from that file until its end, and then from the standard input.

Note: bc.1 is a preprocessor for dc that provides infix (normal arithmetic) notation, a C-like syntax for functions, and reasonable control structures for programs.

The following input constructs are recognized:

Commands

number
Push a number onto the stack. A number is an unbroken string of the digits 0-9. It may be preceded by an underscore `_' to input a negative number, and may contain decimal points.
+ - / * % ^
The top two values on the stack are: added (+), subtracted (-), multiplied (*), divided (/), remaindered (%), or exponentiated (^). The two entries are popped off the stack and the result is pushed in their place. Any fractional part of an exponent is ignored.
sx
Pop the top of the stack and store into a register named x, where x is any character.
Sx
Treat x as a stack and push the value onto it.
lx
Push the value in register x onto the stack. The register x is not altered. All registers start with zero value.
Lx
Treat register x as a stack, and pop its top value onto the main stack.
d
Duplicate the top value on the stack.
p
Print the top value on the stack. The top value remains unchanged.
P
Interpret the top of the stack as an ASCII string, remove and print it.
f
Print all values on the stack and in registers.
q
Exit the program. If executing a string, pop the recursion level by two.
Q
Pop the top value on the stack, and pop the string execution level by that value.
x
Treat the top element of the stack as a character string and execute it as a string of dc commands.
X
Replace the number on the top of the stack with its scale factor.
[...]
Put the bracketed ASCII string onto the top of the stack.
<x >x =x
Pop and compare top two elements of the stack. Execute register x if they obey the stated relation.
v
Replace the top element on the stack by its square root. Any existing fractional part of the argument is taken into account, but otherwise the scale factor is ignored.
!
Interpret the rest of the line as a command.
c
Clear all values on the stack.
i
Pop the top value on the stack and use that value as the input radix.
I
Push the input base on the top of the stack.
o
Pop the top value on the stack and use as the output radix.
O
Push the output base on the top of the stack.
k
The top of the stack is popped, and that value is used as a non-negative scale factor: the appropriate number of places are printed on output, and maintained during multiplication, division, and exponentiation. The interaction of scale factor, input base, and output base will be reasonable if all are changed together.
z
Push the stack level onto the stack.
Z
Replace the number on the top of the stack with its length.
?
Take a line of input from the input source (usually the terminal) and execute it.
; :
Used by bc for array operations.

EXAMPLE

Print the first ten values of n!

[la1+dsa*pla10>y]sy

0sa1
lyx

SEE ALSO

bc.1

DIAGNOSTICS

x is unimplemented
Where x is an octal number.
stack empty
For not enough elements on the stack to do what was asked.
Out of space
When the free list is exhausted (too many digits).
Out of headers
For too many numbers being kept around.
Out of pushdown
For too many items on the stack.
Nesting Depth
For too many levels of nested execution.

BUGS

Base conversions on fractions are truncated to the number of fractional digits of the input value. The values are not rounded.


index | Inhaltsverzeichniss | Kommentar

Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97