|
|
1.1 ! root 1: .TH DC 1 "18 January 1983" ! 2: .SH NAME ! 3: dc \- desk calculator ! 4: .SH SYNOPSIS ! 5: .B dc ! 6: [ file ] ! 7: .SH DESCRIPTION ! 8: .I Dc ! 9: is an arbitrary precision arithmetic package. ! 10: The overall structure of ! 11: .I dc ! 12: is ! 13: a stacking (reverse Polish) calculator. ! 14: If an argument is given, ! 15: input is taken from that file until its end, ! 16: then from the standard input. ! 17: .PP ! 18: Ordinarily ! 19: .I dc ! 20: operates ! 21: on decimal integers, ! 22: but one may specify an input base, output base, ! 23: and a maximum number of fractional digits to be maintained. ! 24: The number of significant decimal digits ! 25: maintained for each value pushed on the stack ! 26: is determined by the number of digits ! 27: specified in its input. This applies even if the ! 28: input base is not decimal. For example, ! 29: given hex input base, the input value .B ! 30: (decimal value .6875) is pushed on the stack ! 31: as .6 decimal. Given hex output, this ! 32: prints as .9 since .6 decimal converts ! 33: to .9 hex. If the input value is specified ! 34: as .B000, the stack value will have the full 4 decimal ! 35: digits, and the hex output will ! 36: be accurately converted to .B0 hex. ! 37: .PP ! 38: The following constructions are recognized: ! 39: .HP 6 ! 40: number ! 41: .br ! 42: The value of the number is pushed on the stack. ! 43: A number is an unbroken string of the digits 0-9. ! 44: It may be preceded by an underscore _ to input a ! 45: negative number. ! 46: Numbers may contain decimal points. ! 47: .HP 6 ! 48: + \- / * % ^ ! 49: .br ! 50: The ! 51: top two values on the stack are added ! 52: (+), ! 53: subtracted ! 54: (\-), ! 55: multiplied (*), ! 56: divided (/), ! 57: remaindered (%), ! 58: or exponentiated (^). ! 59: The two entries are popped off the stack; ! 60: the result is pushed on the stack in their place. ! 61: Any fractional part of an exponent is ignored. ! 62: .TP ! 63: .BI s x ! 64: The ! 65: top of the stack is popped and stored into ! 66: a register named ! 67: .I x, ! 68: where ! 69: .I x ! 70: may be any character. ! 71: If ! 72: the ! 73: .B s ! 74: is capitalized, ! 75: .I x ! 76: is treated as a stack and the value is pushed on it. ! 77: .TP ! 78: .BI l x ! 79: The ! 80: value in register ! 81: .I x ! 82: is pushed on the stack. ! 83: The register ! 84: .I x ! 85: is not altered. ! 86: All registers start with zero value. ! 87: If the ! 88: .B l ! 89: is capitalized, ! 90: register ! 91: .I x ! 92: is treated as a stack and its top value is popped onto the main stack. ! 93: .TP ! 94: .B d ! 95: The ! 96: top value on the stack is duplicated. ! 97: .TP ! 98: .B p ! 99: The top value on the stack is printed. ! 100: The top value remains unchanged. ! 101: .B P ! 102: interprets the top of the stack as an ascii string, ! 103: removes it, and prints it. ! 104: .TP ! 105: .B f ! 106: All values on the stack and in registers are printed. ! 107: .TP ! 108: .B q ! 109: exits the program. ! 110: If executing a string, the recursion level is ! 111: popped by two. ! 112: If ! 113: .B q ! 114: is capitalized, ! 115: the top value on the stack is popped and the string execution level is popped ! 116: by that value. ! 117: .TP ! 118: .B x ! 119: treats the top element of the stack as a character string ! 120: and executes it as a string of dc commands. ! 121: .TP ! 122: .B X ! 123: replaces the number on the top of the stack with its scale factor. ! 124: .TP ! 125: .B "[ ... ]" ! 126: puts the bracketed ascii string onto the top of the stack. ! 127: .HP 6 ! 128: .I "<x >x =x" ! 129: .br ! 130: The ! 131: top two elements of the stack are popped and compared. ! 132: Register ! 133: .I x ! 134: is executed if they obey the stated ! 135: relation. ! 136: .TP ! 137: .B v ! 138: replaces the top element on the stack by its square root. ! 139: Any existing fractional part of the argument is taken ! 140: into account, but otherwise the scale factor is ignored. ! 141: .TP ! 142: .B ! ! 143: interprets the rest of the line as a UNIX command. ! 144: .TP ! 145: .B c ! 146: All values on the stack are popped. ! 147: .TP ! 148: .B i ! 149: The top value on the stack is popped and used as the ! 150: number radix for further input. ! 151: .B I ! 152: pushes the input base on the top of the stack. ! 153: .TP ! 154: .B o ! 155: The top value on the stack is popped and used as the ! 156: number radix for further output. ! 157: .TP ! 158: .SM ! 159: .B O ! 160: pushes the output base on the top of the stack. ! 161: .TP ! 162: .B k ! 163: the top of the stack is popped, and that value is used as ! 164: a non-negative scale factor: ! 165: the appropriate number of places ! 166: are printed on output, ! 167: and maintained during multiplication, division, and exponentiation. ! 168: The interaction of scale factor, ! 169: input base, and output base will be reasonable if all are changed ! 170: together. ! 171: .TP ! 172: .B z ! 173: The stack level is pushed onto the stack. ! 174: .TP ! 175: .SM ! 176: .B Z ! 177: replaces the number on the top of the stack with its length. ! 178: .TP ! 179: .B ? ! 180: A line of input is taken from the input source (usually the terminal) ! 181: and executed. ! 182: .TP ! 183: .B "; :" ! 184: are used by ! 185: .I bc ! 186: for array operations. ! 187: .PP ! 188: An example which prints the first ten values of n! is ! 189: .nf ! 190: .PP ! 191: .in +3 ! 192: [la1+dsa*pla10>y]sy ! 193: .br ! 194: 0sa1 ! 195: .br ! 196: lyx ! 197: .fi ! 198: .SH "SEE ALSO" ! 199: bc(1), ! 200: which is a preprocessor for ! 201: .I dc ! 202: providing infix notation and a C-like syntax ! 203: which implements functions and reasonable control ! 204: structures for programs. ! 205: .SH DIAGNOSTICS ! 206: `x is unimplemented' where x is an octal number. ! 207: .br ! 208: `stack empty' for not enough elements on the stack to do what was asked. ! 209: .br ! 210: `Out of space' when the free list is exhausted (too many digits). ! 211: .br ! 212: `Out of headers' for too many numbers being kept around. ! 213: .br ! 214: `Out of pushdown' for too many items on the stack. ! 215: .br ! 216: `Nesting Depth' for too many levels of nested execution.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.