DC(1)DC(1)

## NAME

dc – desk calculator

## SYNOPSIS

`dc`*file*

## DESCRIPTION

*Dc**dc*

The value of the number is pushed on the stack.
A number is an unbroken string of the digits
`0-9A-F``0-9a-f`.`_`

`+ - / * % ^`

Add
`+`,`-`,`*`,`/`,`%`,`^`

`s`

*x*

**unhandled troff command .ns**

`S`

*x*

Pop the top of the stack and store into
a register named
*x*,*x*`S`*x*

`l`

*x*

**unhandled troff command .ns**

`L`

*x*

Push the value in register
*x**x*`L`*x*

`d`

Duplicate the top value on the stack.

`p`

Print the top value on the stack.
The top value remains unchanged.
`P`

`f`

Print the values on the stack.

`q`

**unhandled troff command .ns**

`Q`

Exit the program.
If executing a string, the recursion level is
popped by two.
Under operation
`Q`

`x`

Treat the top element of the stack as a character string
and execute it as a string of
*dc*

`X`

Replace the number on the top of the stack with its scale factor.

`[ ... ]`

Put the bracketed text string on the top of the stack.

`<`

*x*

`>`

*x*

`=`

*x*

Pop and compare the
top two elements of the stack.
Register
*x*

`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 shell command.

`c`

Clear the stack.

`i`

The top value on the stack is popped and used as the number base for further input.

`I`

Push the input base on the top of the stack.

`o`

The top value on the stack is popped and used as the number base for further output. In bases larger than 10, each ‘digit’ prints as a group of decimal digits.

`O`

Push the output base on the top of the stack.

`k`

Pop the top of the stack, and use that value 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.

`?`

A line of input is taken from the input source (usually the terminal) and executed.

`; :`

Used by
*bc*

The scale factor set by
`k`*s**sa**sb**b*

`+`,`-` max(*sa,sb*)
`*` min(*sa*+*sb *, max(*s,sa,sb*))
`/ s`

`%`so that dividend = divisor*quotient + remainder; remainder has sign of dividend

`^`min(

*sa*×|

*b*|, max(

*s,sa*))

`v`max(

*s,sa*)

## EXAMPLES

Print the first ten values of
*n*!

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

Print π.

1sq180sr60st2si[3li*1+d1+*3*suli27*12-lq*5lr*+lt 5*/d48+Psy10lqlid2*1-***10lulqli5*2-*lr+lylt*-** srsqlult*stli1+silmx]smlmx

## SOURCE

`/sys/src/cmd/dc.c`

## SEE ALSO

## DIAGNOSTICS

*x*`is unimplemented` ,*x*

‘Out of headers’
for too many numbers being kept around.

‘Nesting depth’
for too many levels of nested execution.

## BUGS

When the input base exceeds 16,
there is no notation for digits greater than
`F`.

Past its time.