home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / bc-1.03-base.tgz / bc-1.03-base.tar / fsf / bc / dc.info (.txt) < prev    next >
GNU Info File  |  1994-11-02  |  12KB  |  219 lines

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