DC(1plan9)
โจ NAME โจ
dc โ desk calculator. yes bestie, it's a whole calculator that lives in your terminal and it's lowkey iconic ๐งฎ๐
๐ฆ SYNOPSIS ๐ฆ
dc [ file ]
๐ธ DESCRIPTION ๐ธ
okay so dc is an arbitrary precision desk calculator, which means it does NOT get flustered when your numbers are absolutely unhinged in size. normally it works with decimal integers, but you can tell it what base to read in, what base to print out, and how many fractional digits to keep around. periodt.
the whole vibe of dc is a stacking (reverse Polish) calculator ๐ฅ โ so you push numbers, then you tell it what to do with them. no parentheses drama, no precedence discourse.
if you hand it an argument, it reads input from that file until the file runs out, then it just keeps going and reads from standard input. the following constructions are recognized:
number โ the value of the number gets pushed on the stack. a number is an unbroken string of the digits 0-9A-F or 0-9a-f. ๐จ important: a hexadecimal number that starts with a lower case letter has to be preceded by a zero, otherwise dc thinks it's the command for that letter. you can also slap an underscore _ in front to input a negative number. numbers may contain decimal points.
+ - / * % ^ โ add, subtract, multiply, divide, remainder, or exponentiate the top two values on the stack. both entries get popped off, and the result gets pushed on in their place. any fractional part of an exponent is just ignored, no cap.
sx Sx โ pop the top of the stack and store it into a register named x, where x can be any character. under operation S, register x is treated as a stack and the value gets pushed on it. ๐
lx Lx โ push the value in register x onto the stack. register x is not altered. all registers start with a zero value. under operation L, register x is treated as a stack and its top value gets popped onto the main stack. ๐ซถ
d โ duplicate the top value on the stack. it's giving "copy paste but make it math".
p โ print the top value on the stack, and the top value stays exactly where it is, unchanged. P interprets the top of the stack as a text string, removes it, and prints it. ๐จ๏ธโจ
f โ print the values on the stack. the whole stack. all of it.
q Q โ exit the program. if you're executing a string, the recursion level is popped by two. under operation Q, the top value on the stack is popped and the string execution level is popped by that value. bye bestie ๐๐
x โ treat the top element of the stack as a character string and execute it as a string of dc commands. yes it runs code it found on the stack, slay.
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 is executed 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 shell command. ๐ (careful, bestie, that's real shell)
c โ clear the stack. clean slate energy โจ
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. change them as a squad, not solo ๐
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 for array operations. (iykyk)
the scale factor set by k decides how many digits get kept to the right of the decimal point. if s is the current scale factor, sa is the scale of the first operand, sb is the scale of the second, and b is the (integer) second operand, then results are truncated to the following scales. ๐ฏ
+,- 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! โ look at this absolute bop:
[la1+dsa*pla10>y]sy
0sa1
lyx
๐ SOURCE ๐
/src/cmd/dc.c
๐ SEE ALSO ๐
bc(1), hoc(1) โ the whole calculator friend group fr fr
๐จ DIAGNOSTICS ๐จ
xwhere x is an octal number: an internal error. ๐ญ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. so like, bestie, that's just how it is. ๐
- Past its time. ๐ชฆ
okay that's the whole page ๐ซถ this was the dc page from the Plan 9 manual, section 1 (you know, the DC(1plan9) situation) โ go forth and stack some numbers, queen. ๐โจ๐๐ฆ
๐ฆ where this page comes from
- debian bookworm: 9base 1:6-13 ยท Lucent
- debian trixie: 9base 1:6-14 ยท Lucent
- ubuntu jammy: 9base 1:6-11 ยท Lucent
- ubuntu noble: 9base 1:6-14 ยท Lucent
- ubuntu questing: 9base 1:6-15
- ubuntu resolute: 9base 1:6-15build1 ยท Lucent
- ubuntu stonking: 9base 1:6-15build1 ยท Lucent
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms