home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / info / calc.info-3 (.txt) < prev    next >
GNU Info File  |  1994-12-22  |  41KB  |  762 lines

  1. This is Info file calc.info, produced by Makeinfo-1.55 from the input
  2. file calc.texinfo.
  3.    This file documents Calc, the GNU Emacs calculator.
  4.    Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  5.    Permission is granted to make and distribute verbatim copies of this
  6. manual provided the copyright notice and this permission notice are
  7. preserved on all copies.
  8.    Permission is granted to copy and distribute modified versions of
  9. this manual under the conditions for verbatim copying, provided also
  10. that the section entitled "GNU General Public License" is included
  11. exactly as in the original, and provided that the entire resulting
  12. derived work is distributed under the terms of a permission notice
  13. 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 the section entitled "GNU General Public License"
  17. may be included in a translation approved by the author instead of in
  18. the original English.
  19. File: calc.info,  Node: Modes Tutorial,  Prev: Undo Tutorial,  Up: Basic Tutorial
  20. Mode-Setting Commands
  21. ---------------------
  22. Calc has many types of "modes" that affect the way it interprets your
  23. commands or the way it displays data.  We have already seen one mode,
  24. namely algebraic mode.  There are many others, too; we'll try some of
  25. the most common ones here.
  26.    Perhaps the most fundamental mode in Calc is the current "precision".
  27. Notice the `12' on the Calc window's mode line:
  28.      --%%-Calc: 12 Deg       (Calculator)----All------
  29. Most of the symbols there are Emacs things you don't need to worry
  30. about, but the `12' and the `Deg' are mode indicators.  The `12' means
  31. that calculations should always be carried to 12 significant figures.
  32. That is why, when we type `1 RET 7 /', we get `0.142857142857' with
  33. exactly 12 digits, not counting leading and trailing zeros.
  34.    You can set the precision to anything you like by pressing `p', then
  35. entering a suitable number.  Try pressing `p 30 RET', then doing `1 RET
  36. 7 /' again:
  37.      1:  0.142857142857
  38.      2:  0.142857142857142857142857142857
  39.          .
  40.    Although the precision can be set arbitrarily high, Calc always has
  41. to have *some* value for the current precision.  After all, the true
  42. value `1/7' is an infinitely repeating decimal; Calc has to stop
  43. somewhere.
  44.    Of course, calculations are slower the more digits you request.
  45. Press `p 12' now to set the precision back down to the default.
  46.    Calculations always use the current precision.  For example, even
  47. though we have a 30-digit value for `1/7' on the stack, if we use it in
  48. a calculation in 12-digit mode it will be rounded down to 12 digits
  49. before it is used.  Try it; press RET to duplicate the number, then
  50. `1 +'.  Notice that the RET key didn't round the number, because it
  51. doesn't do any calculation.  But the instant we pressed `+', the number
  52. was rounded down.
  53.      1:  0.142857142857
  54.      2:  0.142857142857142857142857142857
  55.      3:  1.14285714286
  56.          .
  57. In fact, since we added a digit on the left, we had to lose one digit
  58. on the right from even the 12-digit value of `1/7'.
  59.    How did we get more than 12 digits when we computed `2^3^4'?  The
  60. answer is that Calc makes a distinction between "integers" and
  61. "floating-point" numbers, or "floats".  An integer is a number that
  62. does not contain a decimal point.  There is no such thing as an
  63. "infinitely repeating fraction integer," so Calc doesn't have to limit
  64. itself.  If you asked for `2^10000' (don't try this!), you would have
  65. to wait a long time but you would eventually get an exact answer.  If
  66. you ask for `2.^10000', you will quickly get an answer which is correct
  67. only to 12 places.  The decimal point tells Calc that it should use
  68. floating-point arithmetic to get the answer, not exact integer
  69. arithmetic.
  70.    You can use the `F' (`calc-floor') command to convert a
  71. floating-point value to an integer, and `c f' (`calc-float') to convert
  72. an integer to floating-point form.
  73.    Let's try entering that last calculation:
  74.      1:  2.         2:  2.         1:  1.99506311689e3010
  75.          .          1:  10000          .
  76.                         .
  77.      
  78.        2.0 RET          10000 RET      ^
  79. Notice the letter `e' in there.  It represents "times ten to the power
  80. of," and is used by Calc automatically whenever writing the number out
  81. fully would introduce more extra zeros than you probably want to see.
  82. You can enter numbers in this notation, too.
  83.      1:  2.         2:  2.         1:  1.99506311678e3010
  84.          .          1:  10000.         .
  85.                         .
  86.      
  87.        2.0 RET          1e4 RET        ^
  88. Hey, the answer is different!  Look closely at the middle columns of
  89. the two examples.  In the first, the stack contained the exact integer
  90. `10000', but in the second it contained a floating-point value with a
  91. decimal point.  When you raise a number to an integer power, Calc uses
  92. repeated squaring and multiplication to get the answer.  When you use a
  93. floating-point power, Calc uses logarithms and exponentials.  As you
  94. can see, a slight error crept in during one of these methods.  Which
  95. one should we trust?  Let's raise the precision a bit and find out:
  96.          .          1:  2.         2:  2.         1:  1.995063116880828e3010
  97.                         .          1:  10000.         .
  98.                                        .
  99.      
  100.       p 16 RET        2. RET           1e4            ^    p 12 RET
  101. Presumably, it doesn't matter whether we do this higher-precision
  102. calculation using an integer or floating-point power, since we have
  103. added enough "guard digits" to trust the first 12 digits no matter
  104. what.  And the verdict is...  Integer powers were more accurate; in
  105. fact, the result was only off by one unit in the last place.
  106.    Calc does many of its internal calculations to a slightly higher
  107. precision, but it doesn't always bump the precision up enough.  In each
  108. case, Calc added about two digits of precision during its calculation
  109. and then rounded back down to 12 digits afterward.  In one case, it was
  110. enough; in the the other, it wasn't.  If you really need X digits of
  111. precision, it never hurts to do the calculation with a few extra guard
  112. digits.
  113.    What if we want guard digits but don't want to look at them?  We can
  114. set the "float format".  Calc supports four major formats for
  115. floating-point numbers, called "normal", "fixed-point", "scientific
  116. notation", and "engineering notation".  You get them by pressing `d n',
  117. `d f', `d s', and `d e', respectively.  In each case, you can supply a
  118. numeric prefix argument which says how many digits should be displayed.
  119. As an example, let's put a few numbers onto the stack and try some
  120. different display modes.  First, use `M-0 DEL' to clear the stack, then
  121. enter the four numbers shown here:
  122.      4:  12345      4:  12345      4:  12345      4:  12345      4:  12345
  123.      3:  12345.     3:  12300.     3:  1.2345e4   3:  1.23e4     3:  12345.000
  124.      2:  123.45     2:  123.       2:  1.2345e2   2:  1.23e2     2:  123.450
  125.      1:  12.345     1:  12.3       1:  1.2345e1   1:  1.23e1     1:  12.345
  126.          .              .              .              .              .
  127.      
  128.         d n          M-3 d n          d s          M-3 d s        M-3 d f
  129. Notice that when we typed `M-3 d n', the numbers were rounded down to
  130. three significant digits, but then when we typed `d s' all five
  131. significant figures reappeared.  The float format does not affect how
  132. numbers are stored, it only affects how they are displayed.  Only the
  133. current precision governs the actual rounding of numbers in the
  134. Calculator's memory.
  135.    Engineering notation, not shown here, is like scientific notation
  136. except the exponent (the power-of-ten part) is always adjusted to be a
  137. multiple of three (as in "kilo," "micro," etc.).  As a result there
  138. will be one, two, or three digits before the decimal point.
  139.    Whenever you change a display-related mode, Calc redraws everything
  140. in the stack.  This may be slow if there are many things on the stack,
  141. so Calc allows you to type shift-`H' before any mode command to prevent
  142. it from updating the stack.  Anything Calc displays after the
  143. mode-changing command will