Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

DC(1)

NAME

dc − desk calculator

USAGE

dc [ file ]

DESCRIPTION

Dc is an arbitrary precision arithmetic package.  Ordinarily, it operates on decimal integers, but you may specify an input base, output base, and a number of fractional digits to be maintained.  Bc (1) is the preprocessor to this package, providing infix notation, a C-like syntax that implements functions, and reasonable control structures for programs.  Dc is, fundamentally, a stacking calculator.  If an argument is given, input is taken from that file until its end, and then from the standard input. 

OPERATORS

number The value of the number pushed on the stack.  A number is an unbroken string of the digits 0−9.  It may be preceded by an underscore (_) to signify a negative number.  A number may also contain decimal points. 

+ − / ∗ % ^ Add (+), subtract (−), multiply (*), divide (/), remainder (%), or exponentiate (^) the top two values on the stack.  Pop the two entries off the stack; push the result on the stack in their place.  Ignore any fractional part of an exponent. 

sx Pop the top of the stack and store it in a register named x, where x may be any character.  If the s is capitalized, treat x as a stack and the value is pushed on it. 

lx Push the value in register x on the stack.  The register x remains unaltered.  All registers start with zero value.  If the l is capitalized, register x is treated as a stack and its top value is popped onto the main stack. 

d Duplicate the top value on the stack. 

p Print the top value on the stack.  Do not change the top value. 

P Interpret the top of the stack as an ASCII string, remove the string, and then print it. 

f Print all values on the stack. 

q Exit the program.  If executing a string, pop the recursion level by two. 

Q Pop the top value on the stack, and 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 the top two elements of the stack and compare them.  Evaluate register x if the elements obey the stated relation. 

v Replace the top element on the stack by its square root.  Take any existing fractional part of the argument into account, but otherwise ignore the scale factor. 

!  Interpret the rest of the line as a UNIX system command. 

c Pop all values on the stack. 

i Pop the top value on the stack and use it as the number radix for further input.  Push the input base on top of the stack. 

o Pop the top value on the stack and use it as the number radix for further output. 

O Push the output base on top of the stack. 

k Pop the top of the stack and use that value as a non-negative scale factor.  Print the appropriate number of places output, and maintain them 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 (1) for array operations. 

EXAMPLE

To print the first 10 values of n!, specify the following:

[la1+dsa∗pla10>y]sy
0sa1
lyx

DIAGNOSTICS

“x is unimplemented" The value of x is an octal number. 

“Stack empty" There are not enough elements on the stack to do what was asked. 

“Out of space" The free list is exhausted (too many digits). 

“Out of headers" Too many numbers are being retained. 

“Out of pushdown" Too many items are on the stack. 

“Nesting Depth" There are too many levels of nested execution. 

RELATED INFORMATION

bc (1). 

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026