{
    "content": [
        {
            "type": "text",
            "text": "# dc (man)\n\n## NAME\n\ndc - an arbitrary precision calculator\n\n## SYNOPSIS\n\ndc [-V] [--version] [-h] [--help]\n[-e scriptexpression] [--expression=scriptexpression]\n[-f scriptfile] [--file=scriptfile]\n[file ...]\n\n## DESCRIPTION\n\ndc  is  a  reverse-polish  desk calculator which supports unlimited precision arithmetic.  It\nalso allows you to define and call macros.  Normally dc reads from the standard input; if any\ncommand arguments are given to it, they are filenames, and dc reads and executes the contents\nof the files before reading from standard input.  All normal output is  to  standard  output;\nall error output is to standard error.\n\n## TLDR\n\n> An arbitrary precision calculator. Uses reverse polish notation (RPN).\n\n- Start an interactive session:\n  `dc`\n- Execute a script:\n  `dc {{path/to/script.dc}}`\n- Calculate an expression with the specified scale:\n  `dc {{-e|--expression}} '{{10}} k {{5 3 /}} p'`\n- Calculate 4 times 5 (4 5 *), subtract 17 (17 -), and [p]rint the output:\n  `dc {{-e|--expression}} '4 5 * 17 - p'`\n- Specify the number of decimal places to 7 (7 k), calculate 5 divided by -3 (5 _3 /) and [p]rint:\n  `dc {{-e|--expression}} '7 k 5 _3 / p'`\n- Calculate the golden ratio, phi: set number of decimal places to 100 (100 k), square root of 5 (5 v) plus 1 (1 +), divided by 2 (2 /), and [p]rint result:\n  `dc {{-e|--expression}} '100 k 5 v 1 + 2 / p'`\n\n*Source: tldr-pages*\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **OPTIONS** (5 subsections)\n- **Printing Commands**\n- **Arithmetic**\n- **Stack Control**\n- **Registers**\n- **Parameters**\n- **Strings**\n- **Status Inquiry**\n- **Miscellaneous**\n- **FILES**\n- **BUGS**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "dc",
        "section": "",
        "mode": "man",
        "summary": "dc - an arbitrary precision calculator",
        "synopsis": "dc [-V] [--version] [-h] [--help]\n[-e scriptexpression] [--expression=scriptexpression]\n[-f scriptfile] [--file=scriptfile]\n[file ...]",
        "tldr_summary": "An arbitrary precision calculator. Uses reverse polish notation (RPN).",
        "tldr_examples": [
            {
                "description": "Start an interactive session",
                "command": "dc"
            },
            {
                "description": "Execute a script",
                "command": "dc {{path/to/script.dc}}"
            },
            {
                "description": "Calculate an expression with the specified scale",
                "command": "dc {{-e|--expression}} '{{10}} k {{5 3 /}} p'"
            },
            {
                "description": "Calculate 4 times 5 (4 5 *), subtract 17 (17 -), and [p]rint the output",
                "command": "dc {{-e|--expression}} '4 5 * 17 - p'"
            },
            {
                "description": "Specify the number of decimal places to 7 (7 k), calculate 5 divided by -3 (5 _3 /) and [p]rint",
                "command": "dc {{-e|--expression}} '7 k 5 _3 / p'"
            },
            {
                "description": "Calculate the golden ratio, phi: set number of decimal places to 100 (100 k), square root of 5 (5 v) plus 1 (1 +), divided by 2 (2 /), and [p]rint result",
                "command": "dc {{-e|--expression}} '100 k 5 v 1 + 2 / p'"
            }
        ],
        "tldr_source": "official",
        "flags": [
            {
                "flag": "-V",
                "long": null,
                "arg": null,
                "description": ""
            },
            {
                "flag": "",
                "long": "--version",
                "arg": null,
                "description": "Print out the version of dc that is being run and a copyright notice, then exit."
            },
            {
                "flag": "-h",
                "long": null,
                "arg": null,
                "description": "--help Print a usage message briefly summarizing these command-line options and the bug-re‐ porting address, then exit."
            },
            {
                "flag": "-e",
                "long": null,
                "arg": null,
                "description": "--expression=script Add the commands in script to the set of commands to be run while processing the in‐ put."
            },
            {
                "flag": "-f",
                "long": null,
                "arg": null,
                "description": "--file=script-file Add the commands contained in the file script-file to the set of commands to be run while processing the input. If any command-line parameters remain after processing the above, these parameters are inter‐ preted as the names of input files to be processed. A file name of - refers to the standard input stream. The standard input will processed if no script files or expressions are speci‐ fied."
            }
        ],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 16,
                "subsections": []
            },
            {
                "name": "OPTIONS",
                "lines": 2,
                "subsections": [
                    {
                        "name": "-V",
                        "lines": 1,
                        "flag": "-V"
                    },
                    {
                        "name": "--version",
                        "lines": 2,
                        "long": "--version"
                    },
                    {
                        "name": "-h",
                        "lines": 3,
                        "flag": "-h"
                    },
                    {
                        "name": "-e _",
                        "lines": 4,
                        "flag": "-e"
                    },
                    {
                        "name": "-f _",
                        "lines": 9,
                        "flag": "-f"
                    }
                ]
            },
            {
                "name": "Printing Commands",
                "lines": 19,
                "subsections": []
            },
            {
                "name": "Arithmetic",
                "lines": 43,
                "subsections": []
            },
            {
                "name": "Stack Control",
                "lines": 15,
                "subsections": []
            },
            {
                "name": "Registers",
                "lines": 17,
                "subsections": []
            },
            {
                "name": "Parameters",
                "lines": 22,
                "subsections": []
            },
            {
                "name": "Strings",
                "lines": 51,
                "subsections": []
            },
            {
                "name": "Status Inquiry",
                "lines": 11,
                "subsections": []
            },
            {
                "name": "Miscellaneous",
                "lines": 16,
                "subsections": []
            },
            {
                "name": "FILES",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 3,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "dc - an arbitrary precision calculator\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "dc [-V] [--version] [-h] [--help]\n[-e scriptexpression] [--expression=scriptexpression]\n[-f scriptfile] [--file=scriptfile]\n[file ...]\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "dc  is  a  reverse-polish  desk calculator which supports unlimited precision arithmetic.  It\nalso allows you to define and call macros.  Normally dc reads from the standard input; if any\ncommand arguments are given to it, they are filenames, and dc reads and executes the contents\nof the files before reading from standard input.  All normal output is  to  standard  output;\nall error output is to standard error.\n\nA  reverse-polish  calculator  stores numbers on a stack.  Entering a number pushes it on the\nstack.  Arithmetic operations pop arguments off the stack and push the results.\n\nTo enter a number in dc, type the digits (using upper case letters A through  F  as  \"digits\"\nwhen working with input bases greater than ten), with an optional decimal point.  Exponential\nnotation  is  not supported.  To enter a negative number, begin the number with ``''.  ``-''\ncannot be used for this, as it is a binary operator for subtraction instead.   To  enter  two\nnumbers  in succession, separate them with spaces or newlines.  These have no meaning as com‐\nmands.\n",
                "subsections": []
            },
            "OPTIONS": {
                "content": "dc may be invoked with the following command-line options:\n",
                "subsections": [
                    {
                        "name": "-V",
                        "content": "",
                        "flag": "-V"
                    },
                    {
                        "name": "--version",
                        "content": "Print out the version of dc that is being run and a copyright notice, then exit.\n",
                        "long": "--version"
                    },
                    {
                        "name": "-h",
                        "content": "--help Print a usage message briefly summarizing these command-line options and  the  bug-re‐\nporting address, then exit.\n",
                        "flag": "-h"
                    },
                    {
                        "name": "-e _",
                        "content": "--expression=script\nAdd  the  commands in script to the set of commands to be run while processing the in‐\nput.\n",
                        "flag": "-e"
                    },
                    {
                        "name": "-f _",
                        "content": "--file=script-file\nAdd the commands contained in the file script-file to the set of commands  to  be  run\nwhile processing the input.\n\nIf any command-line parameters remain after processing the above, these parameters are inter‐\npreted  as the names of input files to be processed.  A file name of - refers to the standard\ninput stream.  The standard input will processed if no script files or expressions are speci‐\nfied.\n",
                        "flag": "-f"
                    }
                ]
            },
            "Printing Commands": {
                "content": "p      Prints the value on the top of the stack, without altering the stack.   A  newline  is\nprinted after the value.\n\nn      Prints the value on the top of the stack, popping it off, and does not print a newline\nafter.\n\nP      Pops off the value on top of the stack.  If it it a string, it is simply printed with‐\nout  a trailing newline.  Otherwise it is a number, and the integer portion of its ab‐\nsolute value is printed out as a \"base  (UCHARMAX+1)\"  byte  stream.   Assuming  that\n(UCHARMAX+1)  is  256  (as  it  is  on  most machines with 8-bit bytes), the sequence\nKSK0k1/1Ss [ls*]Sxd0>x [256~Ssd0<x]dsxxsx[q]Sq[Lsd0>qaPlxx] dsxxsx0sqLqsxLxLK+k could\nalso accomplish this function.  (Much of the complexity of the above native-dc code is\ndue to the ~ computing the characters backwards, and the desire  to  ensure  that  all\nregisters wind up back in their original states.)\n\nf      Prints  the  entire  contents  of the stack without altering anything.  This is a good\ncommand to use if you are lost or want to figure out what the effect of  some  command\nhas been.\n",
                "subsections": []
            },
            "Arithmetic": {
                "content": "+      Pops two values off the stack, adds them, and pushes the result.  The precision of the\nresult is determined only by the values of the arguments, and is enough to be exact.\n\n-      Pops two values, subtracts the first one popped from the second one popped, and pushes\nthe result.\n\n*      Pops  two values, multiplies them, and pushes the result.  The number of fraction dig‐\nits in the result depends on the current precision value and the  number  of  fraction\ndigits in the two arguments.\n\n/      Pops  two  values, divides the second one popped from the first one popped, and pushes\nthe result.  The number of fraction digits is specified by the precision value.\n\n%      Pops two values, computes the remainder of the division that the / command  would  do,\nand  pushes  that.  The value computed is the same as that computed by the sequence Sd\ndld/ Ld*- .\n\n~      Pops two values, divides the second one popped from the first one  popped.   The  quo‐\ntient  is pushed first, and the remainder is pushed next.  The number of fraction dig‐\nits used in the division is specified by the  precision  value.   (The  sequence  SdSn\nlnld/  LnLd% could also accomplish this function, with slightly different error check‐\ning.)\n\n^      Pops two values and exponentiates, using the first value popped as  the  exponent  and\nthe  second  popped  as  the base.  The fraction part of the exponent is ignored.  The\nprecision value specifies the number of fraction digits in the result.\n\n|      Pops three values and computes a modular exponentiation.  The first  value  popped  is\nused  as the reduction modulus; this value must be a non-zero number, and should be an\ninteger.  The second popped is used as the exponent; this value must be a non-negative\nnumber, and any fractional part of this exponent will be  ignored.   The  third  value\npopped  is  the  base which gets exponentiated, which should be an integer.  For small\nintegers this is like the sequence Sm^Lm%, but, unlike ^, this command will work  with\narbitrarily large exponents.\n\nv      Pops  one value, computes its square root, and pushes that.  The maximum of the preci‐\nsion value and the precision of the argument is used to determine the number of  frac‐\ntion digits in the result.\n\nMost  arithmetic  operations  are affected by the ``precision value'', which you can set with\nthe k command.  The default precision value is zero, which means that all  arithmetic  except\nfor addition and subtraction produces integer results.\n",
                "subsections": []
            },
            "Stack Control": {
                "content": "c      Clears the stack, rendering it empty.\n\nd      Duplicates  the  value  on  the  top  of the stack, pushing another copy of it.  Thus,\n``4d*p'' computes 4 squared and prints it.\n\nr      Reverses the order of (swaps) the top two values on the stack.  (This can also be  ac‐\ncomplished with the sequence SaSbLaLb.)\n\nR      Pops  the top-of-stack as an integer n.  Cyclically rotates the top n items on the up‐\ndated stack.  If n is positive, then the rotation direction will make the topmost ele‐\nment the second-from top; if n is negative, then the rotation will  make  the  topmost\nelement  the  n-th  element from the top.  If the stack depth is less than n, then the\nentire stack is rotated (in the appropriate direction), without any  error  being  re‐\nported.\n",
                "subsections": []
            },
            "Registers": {
                "content": "dc provides at least 256 memory registers, each named by a single character.  You can store a\nnumber or a string in a register and retrieve it later.\n\nsr     Pop the value off the top of the stack and store it into register r.\n\nlr     Copy  the value in register r and push it onto the stack.  The value 0 is retrieved if\nthe register is uninitialized.  This does not alter the contents of r.\n\nEach register also contains its own stack.  The current register value is the top of the reg‐\nister's stack.\n\nSr     Pop the value off the top of the (main) stack and push it onto the stack  of  register\nr.  The previous value of the register becomes inaccessible.\n\nLr     Pop  the value off the top of register r's stack and push it onto the main stack.  The\nprevious value in register r's stack, if any, is now accessible via the lr command.\n",
                "subsections": []
            },
            "Parameters": {
                "content": "dc has three parameters that control its operation: the precision, the input radix,  and  the\noutput radix.  The precision specifies the number of fraction digits to keep in the result of\nmost arithmetic operations.  The input radix controls the interpretation of numbers typed in;\nall numbers typed in use this radix.  The output radix is used for printing numbers.\n\nThe input and output radices are separate parameters; you can make them unequal, which can be\nuseful  or  confusing.  The input radix must be between 2 and 16 inclusive.  The output radix\nmust be at least 2.  The precision must be zero or greater.  The precision is always measured\nin decimal digits, regardless of the current input or output radix.\n\ni      Pops the value off the top of the stack and uses it to set the input radix.\n\no      Pops the value off the top of the stack and uses it to set the output radix.\n\nk      Pops the value off the top of the stack and uses it to set the precision.\n\nI      Pushes the current input radix on the stack.\n\nO      Pushes the current output radix on the stack.\n\nK      Pushes the current precision on the stack.\n",
                "subsections": []
            },
            "Strings": {
                "content": "dc has a limited ability to operate on strings as well as on numbers; the only things you can\ndo with strings are print them and execute them as macros (which means that the  contents  of\nthe  string are processed as dc commands).  All registers and the stack can hold strings, and\ndc always knows whether any given object is a string or a  number.   Some  commands  such  as\narithmetic  operations  demand numbers as arguments and print errors if given strings.  Other\ncommands can accept either a number or a string; for example, the p command can accept either\nand prints the object according to its type.\n\n[characters]\nMakes a string containing characters (contained between balanced [ and ]  characters),\nand  pushes  it  on the stack.  For example, [foo]P prints the characters foo (with no\nnewline).\n\na      The top-of-stack is popped.  If it was a number, then the low-order byte of this  num‐\nber  is converted into a string and pushed onto the stack.  Otherwise the top-of-stack\nwas a string, and the first character of that string is pushed back.\n\nx      Pops a value off the stack and executes it as  a  macro.   Normally  it  should  be  a\nstring;  if  it  is  a  number, it is simply pushed back onto the stack.  For example,\n[1p]x executes the macro 1p which pushes 1 on the stack and prints  1  on  a  separate\nline.\n\nMacros  are most often stored in registers; [1p]sa stores a macro to print 1 into register a,\nand lax invokes this macro.\n\n>r     Pops two values off the stack and compares them assuming they are  numbers,  executing\nthe  contents of register r as a macro if the original top-of-stack is greater.  Thus,\n1 2>a will invoke register a's contents and 2 1>a will not.\n\n!>r    Similar but invokes the macro if the original top-of-stack is not greater  than  (less\nthan or equal to) what was the second-to-top.\n\n<r     Similar but invokes the macro if the original top-of-stack is less.\n\n!<r    Similar  but  invokes the macro if the original top-of-stack is not less than (greater\nthan or equal to) what was the second-to-top.\n\n=r     Similar but invokes the macro if the two numbers popped are equal.\n\n!=r    Similar but invokes the macro if the two numbers popped are not equal.\n\n?      Reads a line from the terminal and executes it.  This command allows a  macro  to  re‐\nquest input from the user.\n\nq      exits  from  a macro and also from the macro which invoked it.  If called from the top\nlevel, or from a macro which was called directly from the top  level,  the  q  command\nwill cause dc to exit.\n\nQ      Pops  a  value off the stack and uses it as a count of levels of macro execution to be\nexited.  Thus, 3Q exits three levels.  The Q command will never cause dc to exit.\n",
                "subsections": []
            },
            "Status Inquiry": {
                "content": "Z      Pops a value off the stack, calculates the number of decimal digits it has (or  number\nof  characters, if it is a string) and pushes that number.  The digit count for a num‐\nber does not include any leading zeros, even if those appear to the right of the radix\npoint.\n\nX      Pops a value off the stack, calculates the number  of  fraction  digits  it  has,  and\npushes that number.  For a string, the value pushed is 0.\n\nz      Pushes  the  current stack depth: the number of objects on the stack before the execu‐\ntion of the z command.\n",
                "subsections": []
            },
            "Miscellaneous": {
                "content": "!      Will run the rest of the line as a system command.  Note that parsing of the  !<,  !=,\nand  !>  commands take precedence, so if you want to run a command starting with <, =,\nor > you will need to add a space after the !.\n\n#      Will interpret the rest of the line as a comment.\n\n:r     Will pop the top two values off of the stack.  The old  second-to-top  value  will  be\nstored in the array r, indexed by the old top-of-stack value.\n\n;r     Pops the top-of-stack and uses it as an index into the array r.  The selected value is\nthen pushed onto the stack.\n\nNote  that  each stacked instance of a register has its own array associated with it.  Thus 1\n0:a 0Sa 2 0:a La 0;ap will print 1, because the 2 was stored in an instance of 0:a  that  was\nlater popped.\n",
                "subsections": []
            },
            "FILES": {
                "content": "~/.dcrc        The commands in this file will be executed when dc is first run.\n",
                "subsections": []
            },
            "BUGS": {
                "content": "Email bug reports to bug-dc@gnu.org.\n\nGNU Project                                  2008-05-22                                        dc(1)",
                "subsections": []
            }
        }
    }
}