{
    "content": [
        {
            "type": "text",
            "text": "# dc (info)\n\n## Sections\n\n- **File: dc.info,  Node: Top,  Next: Introduction,  Up: (dir)**\n- **GNU dc**\n- **This manual documents version 1.4.1 of GNU 'dc', an arbitrary precision**\n- **File: dc.info,  Node: Introduction,  Next: Invocation,  Prev: Top,  Up: Top**\n- **1 Introduction**\n- **Normally 'dc' reads from the standard input; if any command arguments**\n- **File: dc.info,  Node: Invocation,  Next: Printing Commands,  Prev: Introduction,  Up: Top**\n- **2 Invocation**\n- **File: dc.info,  Node: Printing Commands,  Next: Arithmetic,  Prev: Invocation,  Up: Top**\n- **3 Printing Commands**\n- **File: dc.info,  Node: Arithmetic,  Next: Stack Control,  Prev: Printing Commands,  Up: Top**\n- **4 Arithmetic**\n- **File: dc.info,  Node: Stack Control,  Next: Registers,  Prev: Arithmetic,  Up: Top**\n- **5 Stack Control**\n- **File: dc.info,  Node: Registers,  Next: Parameters,  Prev: Stack Control,  Up: Top**\n- **6 Registers**\n- **File: dc.info,  Node: Parameters,  Next: Strings,  Prev: Registers,  Up: Top**\n- **7 Parameters**\n- **The input radix controls the interpretation of numbers typed in; all**\n- **File: dc.info,  Node: Strings,  Next: Status Inquiry,  Prev: Parameters,  Up: Top**\n- **8 Strings**\n- **File: dc.info,  Node: Status Inquiry,  Next: Miscellaneous,  Prev: Strings,  Up: Top**\n- **9 Status Inquiry**\n- **File: dc.info,  Node: Miscellaneous,  Next: Reporting bugs,  Prev: Status Inquiry,  Up: Top**\n- **10 Miscellaneous**\n- **File: dc.info,  Node: Reporting bugs,  Prev: Miscellaneous,  Up: Top**\n- **11 Reporting bugs**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "dc",
        "section": "",
        "mode": "info",
        "summary": null,
        "synopsis": null,
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "File: dc.info,  Node: Top,  Next: Introduction,  Up: (dir)",
                "lines": 1,
                "subsections": []
            },
            {
                "name": "GNU dc",
                "lines": 1,
                "subsections": []
            },
            {
                "name": "This manual documents version 1.4.1 of GNU 'dc', an arbitrary precision",
                "lines": 26,
                "subsections": []
            },
            {
                "name": "File: dc.info,  Node: Introduction,  Next: Invocation,  Prev: Top,  Up: Top",
                "lines": 1,
                "subsections": []
            },
            {
                "name": "1 Introduction",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "Normally 'dc' reads from the standard input; if any command arguments",
                "lines": 21,
                "subsections": []
            },
            {
                "name": "File: dc.info,  Node: Invocation,  Next: Printing Commands,  Prev: Introduction,  Up: Top",
                "lines": 1,
                "subsections": []
            },
            {
                "name": "2 Invocation",
                "lines": 25,
                "subsections": []
            },
            {
                "name": "File: dc.info,  Node: Printing Commands,  Next: Arithmetic,  Prev: Invocation,  Up: Top",
                "lines": 1,
                "subsections": []
            },
            {
                "name": "3 Printing Commands",
                "lines": 38,
                "subsections": []
            },
            {
                "name": "File: dc.info,  Node: Arithmetic,  Next: Stack Control,  Prev: Printing Commands,  Up: Top",
                "lines": 1,
                "subsections": []
            },
            {
                "name": "4 Arithmetic",
                "lines": 62,
                "subsections": []
            },
            {
                "name": "File: dc.info,  Node: Stack Control,  Next: Registers,  Prev: Arithmetic,  Up: Top",
                "lines": 1,
                "subsections": []
            },
            {
                "name": "5 Stack Control",
                "lines": 21,
                "subsections": []
            },
            {
                "name": "File: dc.info,  Node: Registers,  Next: Parameters,  Prev: Stack Control,  Up: Top",
                "lines": 1,
                "subsections": []
            },
            {
                "name": "6 Registers",
                "lines": 31,
                "subsections": []
            },
            {
                "name": "File: dc.info,  Node: Parameters,  Next: Strings,  Prev: Registers,  Up: Top",
                "lines": 1,
                "subsections": []
            },
            {
                "name": "7 Parameters",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "The input radix controls the interpretation of numbers typed in; all",
                "lines": 30,
                "subsections": []
            },
            {
                "name": "File: dc.info,  Node: Strings,  Next: Status Inquiry,  Prev: Parameters,  Up: Top",
                "lines": 1,
                "subsections": []
            },
            {
                "name": "8 Strings",
                "lines": 72,
                "subsections": []
            },
            {
                "name": "File: dc.info,  Node: Status Inquiry,  Next: Miscellaneous,  Prev: Strings,  Up: Top",
                "lines": 1,
                "subsections": []
            },
            {
                "name": "9 Status Inquiry",
                "lines": 23,
                "subsections": []
            },
            {
                "name": "File: dc.info,  Node: Miscellaneous,  Next: Reporting bugs,  Prev: Status Inquiry,  Up: Top",
                "lines": 1,
                "subsections": []
            },
            {
                "name": "10 Miscellaneous",
                "lines": 23,
                "subsections": []
            },
            {
                "name": "File: dc.info,  Node: Reporting bugs,  Prev: Miscellaneous,  Up: Top",
                "lines": 1,
                "subsections": []
            },
            {
                "name": "11 Reporting bugs",
                "lines": 2,
                "subsections": []
            }
        ],
        "sections": {
            "File: dc.info,  Node: Top,  Next: Introduction,  Up: (dir)": {
                "content": "",
                "subsections": []
            },
            "GNU dc": {
                "content": "",
                "subsections": []
            },
            "This manual documents version 1.4.1 of GNU 'dc', an arbitrary precision": {
                "content": "calculator.\n\nCopyright (C) 1984, 1994, 1997, 1998, 2000, 2005, 2006, 2008, 2013,\n2016 Free Software Foundation, Inc.\n\nPermission is granted to copy, distribute and/or modify this\ndocument under the terms of the GNU Free Documentation License,\nVersion 1.2 or any later version published by the Free Software\nFoundation; with no Invariant Sections, with no Front-Cover Texts,\nand with no Back-Cover Texts.  A copy of the license can be found\nat <http://www.gnu.org/licenses/fdl.html> .\n\n* Menu:\n\n* Introduction::                Introduction\n* Invocation::                  Invocation\n* Printing Commands::           Printing Commands\n* Arithmetic::                  Arithmetic\n* Stack Control::               Stack Control\n* Registers::                   Registers\n* Parameters::                  Parameters\n* Strings::                     Strings\n* Status Inquiry::              Status Inquiry\n* Miscellaneous::               Other commands\n* Reporting bugs::              Reporting bugs\n",
                "subsections": []
            },
            "File: dc.info,  Node: Introduction,  Next: Invocation,  Prev: Top,  Up: Top": {
                "content": "",
                "subsections": []
            },
            "1 Introduction": {
                "content": "'dc' is a reverse-polish desk calculator which supports unlimited\nprecision arithmetic.  It also allows you to define and call macros.",
                "subsections": []
            },
            "Normally 'dc' reads from the standard input; if any command arguments": {
                "content": "are given to it, they are filenames, and 'dc' reads and executes the\ncontents of the files instead of reading from standard input.  All\nnormal output is to standard output; all error messages are written to\nstandard error.\n\nTo exit, use 'q'.  'C-c' (or whatever other keystroke your system\nuses to generate a 'SIGINT') does not exit; it is used to abort macros\nthat are looping, etc.\n\nA reverse-polish calculator stores numbers on a stack.  Entering a\nnumber pushes it on the stack.  Arithmetic operations pop arguments off\nthe stack and push the results.\n\nTo enter a number in 'dc', type the digits (using upper case letters\n'A' through 'F' as \"digits\" when working with input bases greater than\nten), with an optional decimal point.  Exponential notation is not\nsupported.  To enter a negative number, begin the number with ''.  '-'\ncannot be used for this, as it is a binary operator for subtraction\ninstead.  To enter two numbers in succession, separate them with spaces\nor newlines; these have no meaning as commands.\n",
                "subsections": []
            },
            "File: dc.info,  Node: Invocation,  Next: Printing Commands,  Prev: Introduction,  Up: Top": {
                "content": "",
                "subsections": []
            },
            "2 Invocation": {
                "content": "'dc' may be invoked with the following command-line options:\n\n'-e EXPR'\n'--expression=EXPR'\nEvaluate EXPR as 'dc' commands.\n\n'-f FILE'\n'--file=FILE'\nRead and evaluate 'dc' commands from FILE.\n\n'-h'\n'--help'\nPrint a usage message summarizing the command-line options, then\nexit.\n\n'-V'\n'--version'\nPrint the version information for this program, then exit.\n\nIf any command-line parameters remain after processing the options,\nthese parameters are interpreted as additional FILEs whose contents are\nread and evaluated.  A file name of '-' refers to the standard input\nstream.  If no '-e' option was specified, and no files were specified,\nthen the standard input will be read for commands to evaluate.\n",
                "subsections": []
            },
            "File: dc.info,  Node: Printing Commands,  Next: Arithmetic,  Prev: Invocation,  Up: Top": {
                "content": "",
                "subsections": []
            },
            "3 Printing Commands": {
                "content": "'p'\nPrints the value on the top of the stack, without altering the\nstack.  A newline is printed after the value.\n\n'n'\nPrints the value on the top of the stack, popping it off, and does\nnot print a newline after.  (This command is a GNU extension.)\n\n'P'\nPops off the value on top of the stack.  If it it a string, it is\nsimply printed without a trailing newline.  Otherwise it is a\nnumber, and the integer portion of its absolute value is printed\nout as a \"base (UCHARMAX+1)\" byte stream.  Assuming that\n(UCHARMAX+1) is 256 (as it is on most machines with 8-bit bytes),\nthe sequence 'KSK0k1/ 1Ss[ls*]Sxd0>x [256~Ssd0<x]dsxx\nsx[q]Sq[Lsd0>qaPlxx]dsxx sx0sqLqsxLxLK+k' could also accomplish\nthis function.  (Much of the complexity of the above native-dc code\nis due to the ~ computing the characters backwards, and the desire\nto ensure that all registers wind up back in their original\nstates.)  (Details of the behavior with a number are a GNU\nextension.  Traditional 'dc' happened to \"support\" similar\nfunctionality for a limited range of inputs as an accidental\nside-effect of its internal representation of numbers.)\n\n'f'\nPrints the entire contents of the stack without altering anything.\nThis is a good command to use if you are lost or want to figure out\nwhat the effect of some command has been.\n\nAll numeric output is split to fit within 70 columns, by default.\nWhen a number is broken up in this way, the split is indicated by a \"\\\"\nat the end of the to-be-continued output lines.  The column width at\nwhich output is split can be overridden by setting the DCLINELENGTH\nenvironment variable to the desired width.  A DCLINELENGTH of 0 (zero)\ndisables the line-split feature altogether.  Invalid values of\nDCLINELENGTH are silently ignored.  (The DCLINELENGTH variable is a\nGNU extension.)\n",
                "subsections": []
            },
            "File: dc.info,  Node: Arithmetic,  Next: Stack Control,  Prev: Printing Commands,  Up: Top": {
                "content": "",
                "subsections": []
            },
            "4 Arithmetic": {
                "content": "'+'\nPops two values off the stack, adds them, and pushes the result.\nThe precision of the result is determined only by the values of the\narguments, and is enough to be exact.\n\n'-'\nPops two values, subtracts the first one popped from the second one\npopped, and pushes the result.\n\n'*'\nPops two values, multiplies them, and pushes the result.  The\nnumber of fraction digits in the result is the largest of the\nprecision value, the number of fraction digits in the multiplier,\nor the number of fraction digits in the multiplicand; but in no\nevent exceeding the number of digits required for an exact result.\n\n'/'\nPops two values, divides the second one popped from the first one\npopped, and pushes the result.  The number of fraction digits is\nspecified by the precision value.\n\n'%'\nPops two values, computes the remainder of the division that the\n'/' command would do, and pushes that.  The value computed is the\nsame as that computed by the sequence 'Sd dld/ Ld*-' .\n\n'~'\nPops two values, divides the second one popped from the first one\npopped.  The quotient is pushed first, and the remainder is pushed\nnext.  The number of fraction digits used in the division is\nspecified by the precision value.  (The sequence 'SdSn lnld/ LnLd%'\ncould also accomplish this function, with slightly different error\nchecking.)  (This command is a GNU extension.)\n\n'^'\nPops two values and exponentiates, using the first value popped as\nthe exponent and the second popped as the base.  The fraction part\nof the exponent is ignored.  The precision value specifies the\nnumber of fraction digits in the result.\n\n'|'\nPops three values and computes a modular exponentiation.  The first\nvalue popped is used as the reduction modulus; this value must be a\nnon-zero number, and the result may not be accurate if the modulus\nis not an integer.  The second popped is used as the exponent; this\nvalue must be a non-negative number, and any fractional part of\nthis exponent will be ignored.  The third value popped is the base\nwhich gets exponentiated, which should be an integer.  For small\nintegers this is like the sequence 'Sm^Lm%', but, unlike '^', this\ncommand will work with arbitrarily large exponents.  (This command\nis a GNU extension.)\n\n'v'\nPops one value, computes its square root, and pushes that.  The\nmaximum of the precision value and the precision of the argument is\nused to determine the number of fraction digits in the result.\n\nMost arithmetic operations are affected by the precision value,\nwhich you can set with the 'k' command.  The default precision value is\nzero, which means that all arithmetic except for addition and\nsubtraction produces integer results.\n",
                "subsections": []
            },
            "File: dc.info,  Node: Stack Control,  Next: Registers,  Prev: Arithmetic,  Up: Top": {
                "content": "",
                "subsections": []
            },
            "5 Stack Control": {
                "content": "'c'\nClears the stack, rendering it empty.\n\n'd'\nDuplicates the value on the top of the stack, pushing another copy\nof it.  Thus, '4d*p' computes 4 squared and prints it.\n\n'r'\nReverses the order of (swaps) the top two values on the stack.\n(This can also be accomplished with the sequence 'SaSbLaLb'.)\n(This command is a GNU extension.)\n\n'R'\nPops the top-of-stack as an integer N.  Cyclically rotates the top\nN items on the updated stack.  If N is positive, then the rotation\ndirection will make the topmost element the second-from top; if N\nis negative, then the rotation will make the topmost element the\nN-th element from the top.  If the stack depth is less than N then\nthe entire stack is rotated (in the appropriate direction), without\nany error being reported.  (This command is a GNU extension.)\n",
                "subsections": []
            },
            "File: dc.info,  Node: Registers,  Next: Parameters,  Prev: Stack Control,  Up: Top": {
                "content": "",
                "subsections": []
            },
            "6 Registers": {
                "content": "'dc' provides at least 256 memory registers(1), each named by a single\ncharacter.  You can store a number in a register and retrieve it later.\n\n'sR'\nPop the value off the top of the stack and store it into register\nR.\n\n'lR'\nCopy the value in register R, and push it onto the stack.  The\nvalue '0' is retrieved if the register is uninitialized or its\nstack has become empty.  This does not alter the contents of R.\n\nEach register also contains its own stack.  The current register\nvalue is the top of the register's stack.\n\n'SR'\nPop the value off the top of the (main) stack and push it onto the\nstack of register R.  The previous value of the register becomes\ninaccessible.\n\n'LR'\nPop the value off the top of register R's stack and push it onto\nthe main stack.  The previous value in register R's stack, if any,\nis now accessible via the 'lR' command.\n\n---------- Footnotes ----------\n\n(1) The exact number of registers provided by 'dc' depends on the\nrange of an 'unsigned char' in the C compiler used to create the 'dc'\nexecutable.\n",
                "subsections": []
            },
            "File: dc.info,  Node: Parameters,  Next: Strings,  Prev: Registers,  Up: Top": {
                "content": "",
                "subsections": []
            },
            "7 Parameters": {
                "content": "'dc' has three parameters that control its operation: the precision, the\ninput radix, and the output radix.  The precision specifies the number\nof fraction digits to keep in the result of most arithmetic operations.",
                "subsections": []
            },
            "The input radix controls the interpretation of numbers typed in; all": {
                "content": "numbers typed in use this radix.  The output radix is used for printing\nnumbers.\n\nThe input and output radices are separate parameters; you can make\nthem unequal, which can be useful or confusing.  The input radix must be\nbetween 2 and 16 inclusive.  The output radix must be at least 2.  The\nprecision must be zero or greater.  The precision is always measured in\ndecimal digits, regardless of the current input or output radix.\n\n'i'\nPops the value off the top of the stack and uses it to set the\ninput radix.\n\n'o'\nPops the value off the top of the stack and uses it to set the\noutput radix.\n\n'k'\nPops the value off the top of the stack and uses it to set the\nprecision.\n\n'I'\nPushes the current input radix on the stack.\n\n'O'\nPushes the current output radix on the stack.\n\n'K'\nPushes the current precision on the stack.\n",
                "subsections": []
            },
            "File: dc.info,  Node: Strings,  Next: Status Inquiry,  Prev: Parameters,  Up: Top": {
                "content": "",
                "subsections": []
            },
            "8 Strings": {
                "content": "'dc' has a limited ability to operate on strings as well as on numbers;\nthe only things you can do with strings are print them and execute them\nas macros (which means that the contents of the string are processed as\n'dc' commands).  Both registers and the stack can hold strings, and 'dc'\nalways knows whether any given object is a string or a number.  Some\ncommands such as arithmetic operations demand numbers as arguments and\nprint errors if given strings.  Other commands can accept either a\nnumber or a string; for example, the 'p' command can accept either and\nprints the object according to its type.\n\n'[CHARACTERS]'\nMakes a string containing CHARACTERS and pushes it on the stack.\nFor example, '[foo]P' prints the characters 'foo' (with no\nnewline).  Note that all square brackets ('['s and ']'s) must be\nbalanced; there is no mechanism provided for handling unbalanced\nsquare brackets.\n\n'a'\nThe mnemonic for this is somewhat erroneous: asciify.  The\ntop-of-stack is popped.  If it was a number, then the low-order\nbyte of this number is converted into a 1-character string and\npushed onto the stack.  Otherwise the top-of-stack was a string,\nand the first character of that string is pushed back.  (This\ncommand is a GNU extension.)\n\n'x'\nPops a value off the stack and executes it as a macro.  Normally it\nshould be a string; if it is a number, it is simply pushed back\nonto the stack.  For example, '[1p]x' executes the macro '1p',\nwhich pushes 1 on the stack and prints '1' on a separate line.\n\nMacros are most often stored in registers; '[1p]sa' stores a macro\nto print '1' into register 'a', and 'lax' invokes the macro.\n\n'>R'\nPops two values off the stack and compares them assuming they are\nnumbers, executing the contents of register R as a macro if the\noriginal top-of-stack is greater.  Thus, '1 2>a' will invoke\nregister 'a''s contents and '2 1>a' will not.\n\n'!>R'\nSimilar but invokes the macro if the original top-of-stack is not\ngreater (is less than or equal to) what was the second-to-top.\n\n'<R'\nSimilar but invokes the macro if the original top-of-stack is less.\n\n'!<R'\nSimilar but invokes the macro if the original top-of-stack is not\nless (is greater than or equal to) what was the second-to-top.\n\n'=R'\nSimilar but invokes the macro if the two numbers popped are equal.\n\n'!=R'\nSimilar but invokes the macro if the two numbers popped are not\nequal.\n\n'?'\nReads a line from the terminal and executes it.  This command\nallows a macro to request input from the user.\n\n'q'\nDuring the execution of a macro, this command exits from the macro\nand also from the macro which invoked it.  If called from the top\nlevel, or from a macro which was called directly from the top\nlevel, the 'q' command will cause 'dc' to exit.\n\n'Q'\nPops a value off the stack and uses it as a count of levels of\nmacro execution to be exited.  Thus, '3Q' exits three levels.\n",
                "subsections": []
            },
            "File: dc.info,  Node: Status Inquiry,  Next: Miscellaneous,  Prev: Strings,  Up: Top": {
                "content": "",
                "subsections": []
            },
            "9 Status Inquiry": {
                "content": "'Z'\nPops a value off the stack, calculates the number of decimal digits\nit has (or number of characters, if it is a string) and pushes that\nnumber.\n\nNote that the digit count for a number does not include any\nleading zeros, even if those appear to the right of the radix\npoint.  This may seem a bit strange at first, but it is compatible\nwith historical implementations of 'dc', and can be argued to be\nuseful for computing the magnitude of a value: 'dSaXLaZ-' will\ncompute the power-of-ten multiplier which would be needed to shift\nthe decimal point to be immediately before the leftmost non-zero\ndigit.\n\n'X'\nPops a value off the stack, calculates the number of fraction\ndigits it has, and pushes that number.  For a string, the value\npushed is 0.\n\n'z'\nPushes the current stack depth: the number of objects on the stack\nbefore the execution of the 'z' command.\n",
                "subsections": []
            },
            "File: dc.info,  Node: Miscellaneous,  Next: Reporting bugs,  Prev: Status Inquiry,  Up: Top": {
                "content": "",
                "subsections": []
            },
            "10 Miscellaneous": {
                "content": "'!'\nWill run the rest of the line as a system command.  Note that\nparsing of the !<, !=, and !> commands take precedence, so if you\nwant to run a command starting with <, =, or > you will need to add\na space after the !.\n\n'#'\nWill interpret the rest of the line as a comment.  (This command is\na GNU extension.)\n\n':R'\nWill pop the top two values off of the stack.  The old\nsecond-to-top value will be stored in the array R, indexed by the\nold top-of-stack value.\n\n';R'\nPops the top-of-stack and uses it as an index into the array R.\nThe selected value is then pushed onto the stack.\n\nNote that each stacked instance of a register has its own array\nassociated with it.  Thus '1 0:A 0SA 2 0:A LA 0;Ap' will print 1,\nbecause the 2 was stored in an instance of 0:A that was later popped.\n",
                "subsections": []
            },
            "File: dc.info,  Node: Reporting bugs,  Prev: Miscellaneous,  Up: Top": {
                "content": "",
                "subsections": []
            },
            "11 Reporting bugs": {
                "content": "Email bug reports to <bug-dc@gnu.org>.\n",
                "subsections": []
            }
        }
    }
}