home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-bin / info / dc.info < prev    next >
Encoding:
GNU Info File  |  1996-10-12  |  11.3 KB  |  347 lines

  1. This is Info file dc.info, produced by Makeinfo-1.64 from the input
  2. file dc.texinfo.
  3.  
  4.    This file documents DC, an arbitrary precision calculator.
  5.  
  6.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  7. Cambridge, MA 02139 USA
  8.  
  9.    Copyright (C) 1984 Free Software Foundation, Inc.
  10.  
  11.    Permission is granted to make and distribute verbatim copies of this
  12. manual provided the copyright notice and this permission notice are
  13. preserved on all copies.
  14.  
  15.    Permission is granted to copy and distribute modified versions of
  16. this manual under the conditions for verbatim copying, provided that
  17. the entire resulting derived work is distributed under the terms of a
  18. permission notice identical to this one.
  19.  
  20.    Permission is granted to copy and distribute translations of this
  21. manual into another language, under the above conditions for modified
  22. versions, except that this permission notice may be stated in a
  23. translation approved by the Foundation.
  24.  
  25. 
  26. File: dc.info,  Node: Top,  Next: Introduction,  Prev: (dir),  Up: (dir)
  27.  
  28. * Menu:
  29.  
  30. * Introduction::                Introduction
  31. * Printing Commands::           Printing Commands
  32. * Arithmetic::                  Arithmetic
  33. * Stack Control::               Stack Control
  34. * Registers::                   Registers
  35. * Parameters::                  Parameters
  36. * Strings::                     Strings
  37. * Status Inquiry::              Status Inquiry
  38. * Miscellaneous::               Other commands
  39. * Notes::                       Notes
  40.  
  41. 
  42. File: dc.info,  Node: Introduction,  Next: Printing Commands,  Prev: Top,  Up: Top
  43.  
  44. Introduction
  45. ************
  46.  
  47.    DC is a reverse-polish desk calculator which supports unlimited
  48. precision arithmetic.  It also allows you to define and call macros.
  49. Normally DC reads from the standard input; if any command arguments are
  50. given to it, they are filenames, and DC reads and executes the contents
  51. of the files before reading from standard input.  All normal output is
  52. to standard output; all error messages are written to standard error.
  53.  
  54.    To exit, use `q'.  `C-c' does not exit; it is used to abort macros
  55. that are looping, etc.  (Currently this is not true; `C-c' does exit.)
  56.  
  57.    A reverse-polish calculator stores numbers on a stack.  Entering a
  58. number pushes it on the stack.  Arithmetic operations pop arguments off
  59. the stack and push the results.
  60.  
  61.    To enter a number in DC, type the digits, with an optional decimal
  62. point.  Exponential notation is not supported.  To enter a negative
  63. number, begin the number with `_'.  `-' cannot be used for this, as it
  64. is a binary operator for subtraction instead.  To enter two numbers in
  65. succession, separate them with spaces or newlines.  These have no
  66. meaning as commands.
  67.  
  68. 
  69. File: dc.info,  Node: Printing Commands,  Next: Arithmetic,  Prev: Introduction,  Up: Top
  70.  
  71. Printing Commands
  72. *****************
  73.  
  74. `p'
  75.      Prints the value on the top of the stack, without altering the
  76.      stack.  A newline is printed after the value.
  77.  
  78. `P'
  79.      Prints the value on the top of the stack, popping it off, and does
  80.      not print a newline after.
  81.  
  82. `f'
  83.      Prints the entire contents of the stack without altering anything.
  84.      This is a good command to use if you are lost or want to figure
  85.      out what the effect of some command has been.
  86.  
  87. 
  88. File: dc.info,  Node: Arithmetic,  Next: Stack Control,  Prev: Printing Commands,  Up: Top
  89.  
  90. Arithmetic
  91. **********
  92.  
  93. `+'
  94.      Pops two values off the stack, adds them, and pushes the result.
  95.      The precision of the result is determined only by the values of
  96.      the arguments, and is enough to be exact.
  97.  
  98. `-'
  99.      Pops two values, subtracts the first one popped from the second
  100.      one popped, and pushes the result.
  101.  
  102. `*'
  103.      Pops two values, multiplies them, and pushes the result.  The
  104.      number of fraction digits in the result is controlled by the
  105.      current precision value (see below) and does not depend on the
  106.      values being multiplied.
  107.  
  108. `/'
  109.      Pops two values, divides the second one popped from the first one
  110.      popped, and pushes the result.  The number of fraction digits is
  111.      specified by the precision value.
  112.  
  113. `%'
  114.      Pops two values, computes the remainder of the division that the
  115.      `/' command would do, and pushes that.  The division is done with
  116.      as many fraction digits as the precision value specifies, and the
  117.      remainder is also computed with that many fraction digits.
  118.  
  119. `^'
  120.      Pops two values and exponentiates, using the first value popped as
  121.      the exponent and the second popped as the base.  The fraction part
  122.      of the exponent is ignored.  The precision value specifies the
  123.      number of fraction digits in the result.
  124.  
  125. `v'
  126.      Pops one value, computes its square root, and pushes that.  The
  127.      precision value specifies the number of fraction digits in the
  128.      result.
  129.  
  130.    Most arithmetic operations are affected by the *precision value*,
  131. which you can set with the `k' command.  The default precision value is
  132. zero, which means that all arithmetic except for addition and
  133. subtraction produces integer results.
  134.  
  135.    The remainder operation (`%') requires some explanation: applied to
  136. arguments `a' and `b' it produces `a - (b * (a / b))', where `a / b' is
  137. computed in the current precision.
  138.  
  139. 
  140. File: dc.info,  Node: Stack Control,  Next: Registers,  Prev: Arithmetic,  Up: Top
  141.  
  142. Stack Control
  143. *************
  144.  
  145. `c'
  146.      Clears the stack, rendering it empty.
  147.  
  148. `d'
  149.      Duplicates the value on the top of the stack, pushing another copy
  150.      of it.  Thus, `4d*p' computes 4 squared and prints it.
  151.  
  152. 
  153. File: dc.info,  Node: Registers,  Next: Parameters,  Prev: Stack Control,  Up: Top
  154.  
  155. Registers
  156. *********
  157.  
  158.    DC provides 256 memory registers, each named by a single character.
  159. You can store a number in a register and retrieve it later.
  160.  
  161. `sR'
  162.      Pop the value off the top of the stack and store it into register
  163.      R.
  164.  
  165. `lR'
  166.      Copy the value in register R, and push it onto the stack.  This
  167.      does not alter the contents of R.
  168.  
  169.      Each register also contains its own stack.  The current register
  170.      value is the top of the register's stack.
  171.  
  172. `SR'
  173.      Pop the value off the top of the (main) stack and push it onto the
  174.      stack of register R.  The previous value of the register becomes
  175.      inaccessible.
  176.  
  177. `LR'
  178.      Pop the value off the top of register R's stack and push it onto
  179.      the main stack.  The previous value in register R's stack, if any,
  180.      is now accessible via the `lR' command.
  181.  
  182. 
  183. File: dc.info,  Node: Parameters,  Next: Strings,  Prev: Registers,  Up: Top
  184.  
  185. Parameters
  186. **********
  187.  
  188.    DC has three parameters that control its operation: the precision,
  189. the input radix, and the output radix.  The precision specifies the
  190. number of fraction digits to keep in the result of most arithmetic
  191. operations.  The input radix controls the interpretation of numbers
  192. typed in; *all* numbers typed in use this radix.  The output radix is
  193. used for printing numbers.
  194.  
  195.    The input and output radices are separate parameters; you can make
  196. them unequal, which can be useful or confusing.  The input radix must
  197. be between 2 and 36 inclusive.  The output radix must be at least 2.
  198. The precision must be zero or greater.  The precision is always
  199. measured in decimal digits, regardless of the current input or output
  200. radix.
  201.  
  202. `i'
  203.      Pops the value off the top of the stack and uses it to set the
  204.      input radix.
  205.  
  206. `o'
  207.      Pops the value off the top of the stack and uses it to set the
  208.      output radix.
  209.  
  210. `k'
  211.      Pops the value off the top of the stack and uses it to set the
  212.      precision.
  213.  
  214. `I'
  215.      Pushes the current input radix on the stack.
  216.  
  217. `O'
  218.      Pushes the current output radix on the stack.
  219.  
  220. `K'
  221.      Pushes the current precision on the stack.
  222.  
  223. 
  224. File: dc.info,  Node: Strings,  Next: Status Inquiry,  Prev: Parameters,  Up: Top
  225.  
  226. Strings
  227. *******
  228.  
  229.    DC can operate on strings as well as on numbers.  The only things
  230. you can do with strings are print them and execute them as macros
  231. (which means that the contents of the string are processed as DC
  232. commands).  Both registers and the stack can hold strings, and DC
  233. always knows whether any given object is a string or a number.  Some
  234. commands such as arithmetic operations demand numbers as arguments and
  235. print errors if given strings.  Other commands can accept either a
  236. number or a string; for example, the `p' command can accept either and
  237. prints the object according to its type.
  238.  
  239. `[CHARACTERS]'
  240.      Makes a string containing CHARACTERS and pushes it on the stack.
  241.      For example, `[foo]P' prints the characters `foo' (with no
  242.      newline).
  243.  
  244. `x'
  245.      Pops a value off the stack and executes it as a macro.  Normally
  246.      it should be a string; if it is a number, it is simply pushed back
  247.      onto the stack.  For example, `[1p]x' executes the macro `1p',
  248.      which pushes 1 on the stack and prints `1' on a separate line.
  249.  
  250.      Macros are most often stored in registers; `[1p]sa' stores a macro
  251.      to print `1' into register `a', and `lax' invokes the macro.
  252.  
  253. `>R'
  254.      Pops two values off the stack and compares them assuming they are
  255.      numbers, executing the contents of register R as a macro if the
  256.      original top-of-stack is greater.  Thus, `1 2>a' will invoke
  257.      register `a''s contents and `2 1>a' will not.
  258.  
  259. `<R'
  260.      Similar but invokes the macro if the original top-of-stack is less.
  261.  
  262. `=R'
  263.      Similar but invokes the macro if the two numbers popped are equal.
  264.  
  265. `?'
  266.      Reads a line from the terminal and executes it.  This command
  267.      allows a macro to request input from the user.
  268.  
  269. `q'
  270.      During the execution of a macro, this command exits from the macro
  271.      and also from the macro which invoked it.  If called from the top
  272.      level, or from a macro which was called directly from the top
  273.      level, the `q' command will cause DC to exit.
  274.  
  275. `Q'
  276.      Pops a value off the stack and uses it as a count of levels of
  277.      macro execution to be exited.  Thus, `3Q' exits three levels.
  278.  
  279. 
  280. File: dc.info,  Node: Status Inquiry,  Next: Miscellaneous,  Prev: Strings,  Up: Top
  281.  
  282. Status Inquiry
  283. **************
  284.  
  285. `Z'
  286.      Pops a value off the stack, calculates the number of digits it has
  287.      (or number of characters, if it is a string) and pushes that
  288.      number.
  289.  
  290. `X'
  291.      Pops a value off the stack, calculates the number of fraction
  292.      digits it has, and pushes that number.  For a string, the value
  293.      pushed is 0.
  294.  
  295. `z'
  296.      Pushes the current stack depth; the number of objects on the stack
  297.      before the execution of the `z' command.
  298.  
  299. 
  300. File: dc.info,  Node: Miscellaneous,  Next: Notes,  Prev: Status Inquiry,  Up: Top
  301.  
  302. Miscellaneous
  303. *************
  304.  
  305. `!'
  306.      Will run the rest of the line as a system command.
  307.  
  308. `#'
  309.      Will interpret the rest of the line as a comment.
  310.  
  311. `:R'
  312.      Will pop the top two values off of the stack.  The old
  313.      second-to-top value will be stored in the array R, indexed by the
  314.      old top-of-stack value.
  315.  
  316. `;R'
  317.      Pops the top-of-stack and uses it as an index into the array R.
  318.      The selected value is then pushed onto the stack.
  319.  
  320. 
  321. File: dc.info,  Node: Notes,  Prev: Miscellaneous,  Up: Top
  322.  
  323. Notes
  324. *****
  325.  
  326.    The array operations `:' and `;' are usually only used by
  327. traditional implementations of BC.  (The GNU BC is self contained and
  328. does not need DC to run.) The comment operator `#' is a new command not
  329. found in traditional implementations of DC.
  330.  
  331.  
  332. 
  333. Tag Table:
  334. Node: Top960
  335. Node: Introduction1487
  336. Node: Printing Commands2707
  337. Node: Arithmetic3267
  338. Node: Stack Control5230
  339. Node: Registers5530
  340. Node: Parameters6446
  341. Node: Strings7707
  342. Node: Status Inquiry9932
  343. Node: Miscellaneous10489
  344. Node: Notes11021
  345. 
  346. End Tag Table
  347.