home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
gnu
/
info
/
calc.info-3
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1994-12-22
|
41KB
|
762 lines
This is Info file calc.info, produced by Makeinfo-1.55 from the input
file calc.texinfo.
This file documents Calc, the GNU Emacs calculator.
Copyright (C) 1990, 1991 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided also
that the section entitled "GNU General Public License" is included
exactly as in the original, and provided that the entire resulting
derived work is distributed under the terms of a permission notice
identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that the section entitled "GNU General Public License"
may be included in a translation approved by the author instead of in
the original English.
File: calc.info, Node: Modes Tutorial, Prev: Undo Tutorial, Up: Basic Tutorial
Mode-Setting Commands
---------------------
Calc has many types of "modes" that affect the way it interprets your
commands or the way it displays data. We have already seen one mode,
namely algebraic mode. There are many others, too; we'll try some of
the most common ones here.
Perhaps the most fundamental mode in Calc is the current "precision".
Notice the `12' on the Calc window's mode line:
--%%-Calc: 12 Deg (Calculator)----All------
Most of the symbols there are Emacs things you don't need to worry
about, but the `12' and the `Deg' are mode indicators. The `12' means
that calculations should always be carried to 12 significant figures.
That is why, when we type `1 RET 7 /', we get `0.142857142857' with
exactly 12 digits, not counting leading and trailing zeros.
You can set the precision to anything you like by pressing `p', then
entering a suitable number. Try pressing `p 30 RET', then doing `1 RET
7 /' again:
1: 0.142857142857
2: 0.142857142857142857142857142857
.
Although the precision can be set arbitrarily high, Calc always has
to have *some* value for the current precision. After all, the true
value `1/7' is an infinitely repeating decimal; Calc has to stop
somewhere.
Of course, calculations are slower the more digits you request.
Press `p 12' now to set the precision back down to the default.
Calculations always use the current precision. For example, even
though we have a 30-digit value for `1/7' on the stack, if we use it in
a calculation in 12-digit mode it will be rounded down to 12 digits
before it is used. Try it; press RET to duplicate the number, then
`1 +'. Notice that the RET key didn't round the number, because it
doesn't do any calculation. But the instant we pressed `+', the number
was rounded down.
1: 0.142857142857
2: 0.142857142857142857142857142857
3: 1.14285714286
.
In fact, since we added a digit on the left, we had to lose one digit
on the right from even the 12-digit value of `1/7'.
How did we get more than 12 digits when we computed `2^3^4'? The
answer is that Calc makes a distinction between "integers" and
"floating-point" numbers, or "floats". An integer is a number that
does not contain a decimal point. There is no such thing as an
"infinitely repeating fraction integer," so Calc doesn't have to limit
itself. If you asked for `2^10000' (don't try this!), you would have
to wait a long time but you would eventually get an exact answer. If
you ask for `2.^10000', you will quickly get an answer which is correct
only to 12 places. The decimal point tells Calc that it should use
floating-point arithmetic to get the answer, not exact integer
arithmetic.
You can use the `F' (`calc-floor') command to convert a
floating-point value to an integer, and `c f' (`calc-float') to convert
an integer to floating-point form.
Let's try entering that last calculation:
1: 2. 2: 2. 1: 1.99506311689e3010
. 1: 10000 .
.
2.0 RET 10000 RET ^
Notice the letter `e' in there. It represents "times ten to the power
of," and is used by Calc automatically whenever writing the number out
fully would introduce more extra zeros than you probably want to see.
You can enter numbers in this notation, too.
1: 2. 2: 2. 1: 1.99506311678e3010
. 1: 10000. .
.
2.0 RET 1e4 RET ^
Hey, the answer is different! Look closely at the middle columns of
the two examples. In the first, the stack contained the exact integer
`10000', but in the second it contained a floating-point value with a
decimal point. When you raise a number to an integer power, Calc uses
repeated squaring and multiplication to get the answer. When you use a
floating-point power, Calc uses logarithms and exponentials. As you
can see, a slight error crept in during one of these methods. Which
one should we trust? Let's raise the precision a bit and find out:
. 1: 2. 2: 2. 1: 1.995063116880828e3010
. 1: 10000. .
.
p 16 RET 2. RET 1e4 ^ p 12 RET
Presumably, it doesn't matter whether we do this higher-precision
calculation using an integer or floating-point power, since we have
added enough "guard digits" to trust the first 12 digits no matter
what. And the verdict is... Integer powers were more accurate; in
fact, the result was only off by one unit in the last place.
Calc does many of its internal calculations to a slightly higher
precision, but it doesn't always bump the precision up enough. In each
case, Calc added about two digits of precision during its calculation
and then rounded back down to 12 digits afterward. In one case, it was
enough; in the the other, it wasn't. If you really need X digits of
precision, it never hurts to do the calculation with a few extra guard
digits.
What if we want guard digits but don't want to look at them? We can
set the "float format". Calc supports four major formats for
floating-point numbers, called "normal", "fixed-point", "scientific
notation", and "engineering notation". You get them by pressing `d n',
`d f', `d s', and `d e', respectively. In each case, you can supply a
numeric prefix argument which says how many digits should be displayed.
As an example, let's put a few numbers onto the stack and try some
different display modes. First, use `M-0 DEL' to clear the stack, then
enter the four numbers shown here:
4: 12345 4: 12345 4: 12345 4: 12345 4: 12345
3: 12345. 3: 12300. 3: 1.2345e4 3: 1.23e4 3: 12345.000
2: 123.45 2: 123. 2: 1.2345e2 2: 1.23e2 2: 123.450
1: 12.345 1: 12.3 1: 1.2345e1 1: 1.23e1 1: 12.345
. . . . .
d n M-3 d n d s M-3 d s M-3 d f
Notice that when we typed `M-3 d n', the numbers were rounded down to
three significant digits, but then when we typed `d s' all five
significant figures reappeared. The float format does not affect how
numbers are stored, it only affects how they are displayed. Only the
current precision governs the actual rounding of numbers in the
Calculator's memory.
Engineering notation, not shown here, is like scientific notation
except the exponent (the power-of-ten part) is always adjusted to be a
multiple of three (as in "kilo," "micro," etc.). As a result there
will be one, two, or three digits before the decimal point.
Whenever you change a display-related mode, Calc redraws everything
in the stack. This may be slow if there are many things on the stack,
so Calc allows you to type shift-`H' before any mode command to prevent
it from updating the stack. Anything Calc displays after the
mode-changing command will