From decwrl!shlump.nac.dec.com!decuac!haven!uflorida!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!mailrus!uunet!allbery Thu Jun 7 17:39:36 PDT 1990 Article 1638 of comp.sources.misc: Path: decwrl!shlump.nac.dec.com!decuac!haven!uflorida!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!mailrus!uunet!allbery From: daveg@csvax.caltech.edu (David Gillespie) Newsgroups: comp.sources.misc Subject: v13i041: Emacs Calculator 1.01, part 15/19 Message-ID: <92133@uunet.UU.NET> Date: 5 Jun 90 23:34:32 GMT Sender: allbery@uunet.UU.NET Lines: 1317 Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) Posting-number: Volume 13, Issue 41 Submitted-by: daveg@csvax.caltech.edu (David Gillespie) Archive-name: gmcalc/part15 ---- Cut Here and unpack ---- #!/bin/sh # this is part 15 of a multipart archive # do not concatenate these parts, unpack them in order with /bin/sh # file calc.texinfo continued # CurArch=15 if test ! -r s2_seq_.tmp then echo "Please unpack part 1 first!" exit 1; fi ( read Scheck if test "$Scheck" != $CurArch then echo "Please unpack part $Scheck next!" exit 1; else exit 0; fi ) < s2_seq_.tmp || exit 1 echo "x - Continuing file calc.texinfo" sed 's/^X//' << 'SHAR_EOF' >> calc.texinfo X@section Inverse and Hyperbolic Flags X X@kindex I X@pindex calc-inverse XThere is no single-key equivalent to the @code{calc-arcsin} function. XInstead, you must first press @kbd{I} (@code{calc-inverse}) to set Xthe @dfn{Inverse Flag}, then press @kbd{S} (@code{calc-sin}). XThe @kbd{I} key actually toggles the Inverse Flag. When this flag Xis set, the word @samp{Inv} appears in the mode line.@refill X X@kindex H X@pindex calc-hyperbolic XLikewise, the @kbd{H} key (@code{calc-hyperbolic}) sets or clears the XHyperbolic Flag, which transforms @code{calc-sin} into @code{calc-sinh}. XIf both of these flags are set at once, the effect will be X@code{calc-arcsinh}. (The Hyperbolic flag is also used by some Xnon-trigonometric commands; for example @kbd{H L} computes a base-10, Xinstead of base-e, logarithm.)@refill X XCommand names like @code{calc-arcsin} are provided for completeness, and Xmay be executed with @kbd{x} or @kbd{M-x}. Their effect is simply to Xtoggle the Inverse and/or Hyperbolic flags and then execute the Xcorresponding base command (@code{calc-sin} in this case). X XThe Inverse and Hyperbolic flags apply only to the next Calculator Xcommand, after which they are automatically cleared. X X@node Calculation Modes, Simplification Modes, Inverse and Hyperbolic, Mode Settings X@section Calculation Modes X XThe commands in this section are two-key sequences beginning with Xthe @kbd{m} prefix. (That's the letter @kbd{m}, not the @key{META} key.) X XThe @samp{m a} (@code{calc-algebraic-mode}) command is described elsewhere X(@pxref{Algebraic Entry}.) X X@menu X* Angular Modes:: X* Polar Mode:: X* Fraction Mode:: X* Symbolic Mode:: X* Working Message:: X@end menu X X@node Angular Modes, Polar Mode, Calculation Modes, Calculation Modes X@subsection Angular Modes X X@cindex Angular mode XThe Calculator supports three notations for angles: radians, degrees, Xand degrees-minutes-seconds. When a number is presented to a function Xlike @code{calc-sin} that requires an angle, the current angular mode is Xused to interpret the number as either radians or degrees. If an HMS Xform is presented to @code{calc-sin}, it is always interpreted as Xdegrees-minutes-seconds. X XFunctions that compute angles produce a number in radians, a number in Xdegrees, or an HMS form depending on the current angular mode. If the Xresult is a complex number and the current mode is HMS, the number is Xinstead expressed in degrees. (Complex-number calculations would Xnormally be done in radians mode, though. Complex numbers are converted Xto degrees by calculating the complex result in radians and then Xmultiplying by 180 over @samp{pi}.) X X@kindex m r X@pindex calc-radians-mode X@kindex m d X@pindex calc-degrees-mode X@kindex m h X@pindex calc-hms-mode XThe @kbd{m r} (@code{calc-radians-mode}), @kbd{m d} (@code{calc-degrees-mode}), Xand @kbd{m h} (@code{calc-hms-mode}) commands control the angular mode. XThe current angular mode is displayed on the Emacs mode line. XThe default angular mode is degrees.@refill X X@node Polar Mode, Fraction Mode, Angular Modes, Calculation Modes X@subsection Polar Mode X X@cindex Polar mode XThe Calculator normally ``prefers'' rectangular complex numbers in the Xsense that rectangular form is used when the proper form can not be Xdecided from the input. This might happen by multiplying a rectangular Xnumber by a polar one, by taking the square root of a negative real Xnumber, or by entering @kbd{( 2 @key{SPC} 3 )}. X X@kindex m p X@pindex calc-polar-mode XThe @kbd{m p} (@code{calc-polar-mode}) command toggles complex-number Xpreference between rectangular and polar forms. In polar mode, all Xof the above example situations would produce polar complex numbers. X X@node Fraction Mode, Symbolic Mode, Polar Mode, Calculation Modes X@subsection Fraction Mode X X@cindex Fraction mode X@cindex Division of integers XDivision of two integers normally yields a floating-point number if the Xresult cannot be expressed as an integer. In some cases you would Xrather get an exact fractional answer. One way to accomplish this is Xto multiply fractions instead: @kbd{6 @key{RET} 1:4 *} produces @samp{3:2} Xeven though @kbd{6 @key{RET} 4 /} produces @samp{1.5}. X X@kindex m f X@pindex calc-frac-mode XTo set the Calculator to produce fractional results for normal integer Xdivisions, use the @kbd{m f} (@code{calc-frac-mode}) command. XFor example, @samp{8/4} produces @samp{2} in either mode, Xbut @samp{6/4} produces @samp{3:2} in Fraction Mode, but @samp{1.5} in XFloat Mode.@refill X XAt any time you can use @kbd{c f} (@code{calc-float}) to convert a Xfraction to a float, or @kbd{c F} (@code{calc-fraction}) to convert a Xfloat to a fraction. @xref{Conversions}. X X@node Symbolic Mode, Working Message, Fraction Mode, Calculation Modes X@subsection Symbolic Mode X X@cindex Symbolic mode X@cindex Inexact results XCalculations are normally performed numerically wherever possible. XFor example, the @code{calc-sqrt} command, or @code{sqrt} function in an Xalgebraic expression, produces a numeric answer if the argument is a Xnumber or a symbolic expression if the argument is an expression: X@kbd{2 Q} pushes 1.4142 but @kbd{@key{'} x+1 @key{RET} Q} pushes @samp{sqrt(x+1)}. X X@kindex m s X@pindex calc-symbolic-mode XIn @dfn{symbolic mode}, controlled by the @kbd{m s} (@code{calc-symbolic-mode}) Xcommand, functions which would produce inexact, irrational results are Xleft in symbolic form. Thus @kbd{16 Q} pushes 4, but @kbd{2 Q} pushes X@samp{sqrt(2)}. X X@kindex N X@pindex calc-eval-num XThe shift-@kbd{N} (@code{calc-eval-num}) command evaluates numerically Xthe expression at the top of the stack, by temporarily disabling X@code{calc-symbolic-mode} and executing @kbd{=} (@code{calc-evaluate}). XGiven a numeric prefix argument, it also Xsets the floating-point precision to the specified value for the duration Xof the command.@refill X XTo evaluate a formula numerically without expanding the variables it Xcontains, you can use the key sequence @kbd{m a c c m a} (@code{calc-clean} Xresimplifies but doesn't evaluate variables). X X@node Working Message, , Symbolic Mode, Calculation Modes X@subsection Working Messages X X@cindex Performance X@cindex Working messages XSince the Calculator is written entirely in Emacs Lisp, which is not Xdesigned for heavy numerical work, many operations are quite slow. XThe Calculator normally displays the message @samp{Working...} in the Xecho area during any command that may be slow. In addition, iterative Xoperations such as square roots and trigonometric functions display the Xintermediate result at each step. Both of these types of messages can Xbe disabled if you find them distracting. X X@kindex m w X@pindex calc-working XType @kbd{m w} (@code{calc-working}) with a numeric prefix of 0 to Xdisable all ``working'' messages. Use a numeric prefix of 1 to enable Xonly the plain @samp{Working...} message. Use a numeric prefix of 2 to Xsee intermediate results as well. With no numeric prefix this displays Xthe current mode.@refill X X@node Simplification Modes, Display Modes, Calculation Modes, Mode Settings X@section Simplification Modes X XThe current @dfn{simplification mode} controls how numbers and formulas Xare ``normalized'' when being taken from or pushed onto the stack. XSome normalizations are unavoidable, such as rounding floating-point Xresults to the current precision, and reducing fractions to simplest Xform. Others, such as simplifying a formula like @samp{a+a} (or @samp{2+3}), Xare done by default but can be turned off when necessary. X XWhen you press a key like @kbd{+} when @samp{2} and @samp{3} are on the Xstack, Calc pops these numbers, normalizes them, creates the formula X@samp{2+3}, normalizes it, and pushes the result. Of course the standard Xrules for normalizing @samp{2+3} will produce the result @samp{5}. X XSimplification mode commands consist of the lower-case @kbd{m} prefix key Xfollowed by a shifted letter. X X@kindex m O X@pindex calc-no-simplify-mode XThe @kbd{m O} (@code{calc-no-simplify-mode}) command turns off all optional Xsimplifications. These would leave a formula like @samp{2+3} alone. In Xfact, nothing except simple numbers are ever affected by normalization Xin this mode. X X@kindex m N X@pindex calc-num-simplify-mode XThe @kbd{m N} (@code{calc-num-simplify-mode}) command turns off simplification Xof any formulas except those for which all arguments are constants. For Xexample, @samp{1+2} is simplified to @samp{3}, and @samp{a+(2-2)} is Xsimplified to @samp{a+0} but no further, since one argument of the sum Xis not a constant. X X@kindex m D X@pindex calc-default-simplify-mode XThe @kbd{m D} (@code{calc-default-simplify-mode}) command restores the Xdefault simplifications for all formulas. This includes some easy and Xfast simplifcations such as @samp{a+0} to @samp{a}, and @samp{a + 2 a} Xto @samp{3 a}. X X@kindex m B X@pindex calc-bin-simplify-mode XThe @kbd{m B} (@code{calc-bin-simplify-mode}) mode applies the default Xsimplifications to a result and then, if the result is an integer, Xuses the @code{calc-clip} command to clip the integer according to Xthe current binary word size. @xref{Binary Functions}. Real numbers Xare rounded to the nearest integer and then clipped; other kinds of Xresults (after the default simplifications) are left alone. X X@kindex m A X@pindex calc-alg-simplify-mode XThe @kbd{m A} (@code{calc-alg-simplify-mode}) mode does algebraic Xsimplification; it applies all the default simplifications, and also Xthe more powerful (and slower) simplifications made by @code{calc-simplify}. X@xref{Algebra}. X X@kindex m E X@pindex calc-ext-simplify-mode XThe @kbd{m E} (@code{calc-ext-simplify-mode}) mode does ``extended'' Xalgebraic simplification, as by the @code{calc-simplify-extended} command. X@xref{Algebra}. X X@kindex m U X@pindex calc-units-simplify-mode XThe @kbd{m U} (@code{calc-units-simplify-mode}) mode does units Xsimplification; it applies @code{calc-simplify-units}, which in turn Xis a superset of @code{calc-simplify}. In this mode, variable names Xwhich are identifiable as unit names (like @samp{mm} for ``millimeters'') Xare simplified with their unit definitions in mind. X XA common technique is to set the simplification mode down to the lowest Xamount of simplification you will allow to be applied automatically, then Xuse manual commands like @code{calc-clean} or @code{calc-simplify} to Xperform higher types of simplifications on demand. @xref{Algebraic XDefinitions}, for another sample use of no-simplification mode.@refill X X@node Display Modes, Language Modes, Simplification Modes, Mode Settings X@section Display Modes X XThe commands in this section are two-key sequences beginning with the X@kbd{d} prefix. The @kbd{d l} (@code{calc-line-numbering}) and @kbd{d b} X(@code{calc-line-breaking}) commands are described elsewhere; X@pxref{Stack Basics} and @pxref{Normal Language Modes}, respectively. XDisplay formats for vectors and matrices are also covered elsewhere; X@pxref{Vector and Matrix Formats}.@refill X X@menu X* Radix Modes:: X* Grouping Digits:: X* Float Formats:: X* Complex Formats:: X* Fraction Formats:: X* HMS Formats:: X* Truncating the Stack:: X* Justification:: X@end menu X X@node Radix Modes, Grouping Digits, Display Modes, Display Modes X@subsection Radix Modes X X@cindex Radix display X@cindex Non-decimal integers X@cindex Decimal and non-decimal integers XCalc normally displays integers in decimal, or @dfn{radix-10}, notation. XCalc can actually display in any radix from two (binary) to 36. When Xthe radix is above 10, the letters @samp{A} to @samp{Z} are used as digits. XWhen entering such a number, letter keys are interpreted as potential Xdigits rather than terminating numeric entry mode. X X@kindex d 2 X@kindex d 8 X@kindex d 6 X@kindex d 0 X@cindex Hexadecimal integers X@cindex Octal integers XThe key sequences @kbd{d 2}, @kbd{d 8}, @kbd{d 6}, and @kbd{d 0} select Xbinary, octal, hexadecimal, and decimal as the integer display radix, Xrespectively. Numbers can always be entered in any radix, though the Xcurrent radix is used as a default if you press @kbd{#} without any initial Xdigits. A number entered without a @kbd{#} is @emph{always} interpreted Xas decimal.@refill X X@kindex d r X@pindex calc-radix XTo set the radix generally, use @kbd{d r} (@code{calc-radix}) and enter Xan integer from 2 to 36. You can specify the radix as a numeric prefix Xargument; otherwise you will be prompted for it. X X@kindex d z X@pindex calc-leading-zeros X@cindex Leading zeros XIntegers normally are displayed with however many digits are necessary to Xrepresent the integer and no more. The @kbd{d z} (@code{calc-leading-zeros}) Xcommand causes integers to be padded out with leading zeros according to the Xcurrent binary word size. (@xref{Binary Functions}, for a discussion of Xword size.) If the absolute value of the word size is @samp{w}, all integers Xare displayed with at least enough digits to represent @samp{(2^w)-1} in the Xcurrent radix. (Larger integers will still be displayed in their entirety.) X XThe current radix is only used to display integers and fractions. XFloating-point numbers are always entered and displayed in decimal. X X@node Grouping Digits, Float Formats, Radix Modes, Display Modes X@subsection Grouping Digits X X@kindex d g X@pindex calc-group-digits X@cindex Grouping digits X@cindex Digit grouping XLong numbers can be hard to read if they have too many digits. For Xexample, the factorial of 30 is 33 digits long! Press @kbd{d g} X(@code{calc-group-digits}) to enable @dfn{grouping} mode, in which digits Xare displayed in clumps of 3 or 4 (depending on the current radix) Xseparated by commas. X XThe @kbd{d g} command toggles grouping on and off. XWith a numerix prefix of 0, this command displays the current state of Xthe grouping flag; with a @kbd{C-u} prefix, it pushes the grouping state Xonto the stack; with an argument of minus one it disables grouping; with Xa positive argument @samp{N} it enables grouping on every @samp{N} Xdigits. For floating-point numbers, grouping normally occurs only Xbefore the decimal point. A negative prefix argument @samp{-N} enables Xgrouping every @samp{N} digits both before and after the decimal point.@refill X X@kindex d , X@pindex calc-group-char XThe @kbd{d ,} (@code{calc-group-char}) command allows you to choose any Xcharacter as the grouping separator. The default is the comma character. XIf you find it difficult to read vectors of large integers grouped with Xcommas, you may wish to use spaces or some other character instead. X XPlease note that grouped numbers will not generally be parsed correctly Xif re-read in textual form, say by the use of @kbd{C-k} and @kbd{C-y}. X(@xref{Kill and Yank}, for details on these commands.) X X@node Float Formats, Complex Formats, Grouping Digits, Display Modes X@subsection Float Formats X XFloating-point quantities are normally displayed in standard decimal Xform, with scientific notation used if the exponent is especially high Xor low. All significant digits are normally displayed. The commands Xin this section allow you to choose among several alternative display Xformats for floats. X X@kindex d n X@pindex calc-normal-notation XThe @kbd{d n} (@code{calc-normal-notation}) command selects the normal Xdisplay format. All significant figures in a number are displayed. XWith a positive numeric prefix, numbers are rounded if necessary to Xthat number of significant digits. With a negative numerix prefix, Xthe specified number of significant digits less than the current Xprecision is used. (Thus @kbd{C-u -2 d n} displays 10 digits if the Xcurrent precision is 12.) X X@kindex d f X@pindex calc-fix-notation XThe @kbd{d f} (@code{calc-fix-notation}) command selects fixed-point Xnotation. The numeric argument is the number of digits after the Xdecimal point, zero or more. This format will relax into scientific Xnotation if a nonzero number would otherwise have been rounded all the Xway to zero. Specifying a negative number of digits is the same as Xfor a positive number, except that small nonzero numbers will be rounded Xto zero rather than switching to scientific notation. X X@kindex d s X@pindex calc-sci-notation XThe @kbd{d s} (@code{calc-sci-notation}) command selects scientific Xnotation. A positive argument sets the number of significant figures Xdisplayed, of which one will be before and the rest after the decimal Xpoint. A negative argument works the same as for @kbd{d n} format. XThe default is to display all significant digits. X X@kindex d e X@pindex calc-eng-notation XThe @kbd{d e} (@code{calc-eng-notation}) command selects engineering Xnotation. This is similar to scientific notation except that the Xexponent is rounded down to a multiple of three, with from one to three Xdigits before the decimal point. An optional numeric prefix sets the Xnumber of significant digits to display, as for @kbd{d s}. X XIt is important to distinguish between the current @emph{precision} and Xthe current @emph{display format}. After the commands @kbd{C-u 10 p} Xand @kbd{C-u 6 d n} the Calculator computes all results to ten Xsignificant figures but only displays six. (In fact, intermediate Xcalculations are often carried to one or two more significant figures, Xbut values placed on the stack are always rounded down to ten figures.) XNumbers are never actually rounded to the display precision for storage, Xexcept by ``kill'' commands like @kbd{C-k} which operate on the actual Xdisplayed text in the Calculator buffer. X X@kindex d . X@pindex calc-point-char XThe @kbd{d .} (@code{calc-point-char}) command controls the character used Xas a decimal point. Normally this is a period; users in some countries Xmay wish to change this to a comma. Note that this is only a display Xstyle; on entry, periods must always be used to denote floating-point Xnumbers, and commas to seperate elements in a list. X X@node Complex Formats, Fraction Formats, Float Formats, Display Modes X@subsection Complex Formats X X@kindex d c X@pindex calc-complex-notation XThere are three supported notations for complex numbers in rectangular Xform. The default is as a pair of real numbers enclosed in parentheses Xand separated by a comma: @samp{(a,b)}. The @kbd{d c} X(@code{calc-complex-notation}) command selects this style.@refill X X@kindex d i X@pindex calc-i-notation X@kindex d j X@pindex calc-j-notation XThe other notations are @kbd{d i} (@code{calc-i-notation}), in which Xnumbers are displayed in @samp{a+bi} form, and @kbd{d j} X(@code{calc-j-notation}) which displays the form @samp{a+bj} preferred Xin some disciplines.@refill X X@cindex @code{i} variable XComplex numbers are normally entered in @samp{(a,b)} format. XIf you enter @samp{2+3i} as an algebraic formula, it will be stored as Xthe formula @samp{2 + 3 * i}. However, if you use @kbd{=} to evaluate Xthis formula and you have not changed the variable @samp{i}, the @samp{i} Xwill be interpreted as @samp{(0,1)} and the formula will be simplified Xto @samp{(2,3)}. Other commands (like @code{calc-sin}) will @emph{not} Xinterpret the formula @samp{2 + 3 * i} as a complex number. X@xref{Variables}, under ``special constants.''@refill X X@node Fraction Formats, HMS Formats, Complex Formats, Display Modes X@subsection Fraction Formats X X@kindex d o X@pindex calc-over-notation XDisplay of fractional numbers is controlled by the @kbd{d o} X(@code{calc-over-notation}) command. By default, a number like Xeight thirds is displayed in the form @samp{8:3}. The @kbd{d o} command Xprompts for a one- or two-character format. If you give one character, Xthat character is used as the fraction separator. Common separators are X@samp{:} and @samp{/}. (During input of numbers, the @kbd{:} key must be Xused regardless of the display format; in particular, the @kbd{/} is used Xfor RPN-style division, @emph{not} for entering fractions.) X XIf you give two characters, fractions use ``integer-plus-fractional-part'' Xnotation. For example, the format @samp{+/} would display eight thirds Xas @samp{2+2/3}. If two colons are present in a number being entered, Xthe number is interpreted in this form. X X@node HMS Formats, Truncating the Stack, Fraction Formats, Display Modes X@subsection HMS Formats X X@kindex d h X@pindex calc-hms-notation XThe @kbd{d h} (@code{calc-hms-notation}) command controls the display of XHMS (hours-minutes-seconds) forms. It prompts for a string which Xconsists basically of an ``hours'' marker, optional punctuation, a X``minutes'' marker, more optional punctuation, and a ``seconds'' marker. XPunctuation is zero or more spaces, commas, or semicolons. The hours Xmarker is one or more non-punctuation characters. The minutes and Xseconds markers must be single non-punctuation characters. X XThe default HMS format is @samp{@@ ' "}, producing HMS values of the form X@samp{23@@ 30' 15.75"}. The format @samp{deg, ms} would display this same Xvalue as @samp{23deg, 30m15.75s}. During numeric entry, the @kbd{h} or @kbd{o} Xkeys are recognized as synonyms for @kbd{@@} regardless of display format. XThe @kbd{m} and @kbd{s} keys are recognized as synonyms for @kbd{'} and X@kbd{"}, respectively, but only if an @kbd{@@} (or @kbd{h} or @kbd{o}) has Xalready been typed; otherwise, they have their usual meanings X(@kbd{m-} prefix and @code{calc-store}). Thus, @kbd{5 "}, @kbd{0 @@ 5 "}, and X@kbd{0 h 5 s} are some of the ways to enter the quantity ``five seconds.'' XThe @kbd{'} key is recognized as ``minutes'' only if @kbd{@@} (or @kbd{h} or X@kbd{o}) has already been pressed; otherwise it means to switch to algebraic Xentry. X X@node Truncating the Stack, Justification, HMS Formats, Display Modes X@subsection Truncating the Stack X X@kindex d t X@pindex calc-truncate-stack X@cindex Truncating the stack X@cindex Narrowing the stack XThe @kbd{d t} (@code{calc-truncate-stack}) command moves the @samp{.}@: Xline that marks the top-of-stack up or down in the Calculator buffer. XThe number right above that line is considered to the be at the top of Xthe stack. Any numbers below that line are ``hidden'' from all stack Xoperations. This is similar to the Emacs ``narrowing'' feature, except Xthat the values below the @samp{.} are @emph{visible}, just temporarily Xfrozen. This feature allows you to keep several independent calculations Xrunning at once in different parts of the stack, or to apply a certain Xcommand to an element buried deep in the stack.@refill X XPressing @kbd{d t} by itself moves the @samp{.} to the line the cursor Xis on. Thus, this line and all those below it become hidden. To un-hide Xthese lines, move down to the end of the buffer and press @kbd{d t}. XWith a positive numeric prefix argument @samp{n}, @kbd{d t} hides the Xbottom @samp{n} values in the buffer. With a negative argument, it hides Xall but the top @samp{n} values. With an argument of zero, it hides zero Xvalues, i.e., moves the @samp{.} all the way down to the bottom.@refill X X@kindex d [ X@pindex calc-truncate-up X@kindex d ] X@pindex calc-truncate-down XThe @kbd{d [} (@code{calc-truncate-up}) and @kbd{d ]} X(@code{calc-truncate-down}) commands move the @samp{.} up or down one Xline at a time (or several lines with a prefix argument).@refill X X@node Justification, , Truncating the Stack, Display Modes X@subsection Justification X X@kindex d < X@pindex calc-left-justify X@kindex d = X@pindex calc-center-justify X@kindex d > X@pindex calc-right-justify XValues on the stack are normally left-justified in the window. You can Xcontrol this arrangement by typing @kbd{d <} (@code{calc-left-justify}), X@kbd{d >} (@code{calc-right-justify}), or @kbd{d =} X(@code{calc-center-justify}). For example, in right-justification mode, Xstack entries are displayed flush-right against the right edge of the Xwindow.@refill X XIf you change the width of the Calculator window you may have to type X@kbd{d ~} (@code{calc-refresh}) to re-align right-justified or centered text. X XRight-justification is especially useful together with fixed-point Xnotation (@code{d f}; @code{calc-fix-notation}). With these modes together, Xthe decimal points on numbers will always line up. X X@node Language Modes, , Display Modes, Mode Settings X@section Language Modes X XThe commands in this section change Calc to use a different notation for Xentry and display of formulas, corresponding to the conventions of some Xother common language such as Pascal or @TeX{}. Objects displayed on the Xstack or yanked from the Calculator to an editing buffer will be formatted Xin the current language; objects entered in algebraic entry or yanked from Xanother buffer will be interpreted according to the current language. X XThe current language has no effect on things written to or read from the Xtrail buffer, nor does it affect numeric entry. Only algebraic entry is Xaffected. X XFor example, suppose the formula @samp{2*a[1] + atan(a[2])} occurs in a C Xprogram; elsewhere in the program you need the derivatives of this formula Xwith respect to @samp{a[1]} and @samp{a[2]}. First, type @kbd{d C} Xto switch to C notation. Now use @code{calc-yank} to grab the formula Xinto the Calculator, @kbd{a d a[1] @key{RET}} to differentiate with respect Xto the first variable, and @kbd{y} to yank the formula for the derivative Xback into your C program. Press @kbd{U} to undo the differentiation and Xrepeat with @kbd{a d a[2] @key{RET}} for the other derivative. X XWithout being switched into C mode first, Calc would have misinterpreted Xthe brackets in @samp{a[1]} and @samp{a[2]}, would not have known that X@code{atan} was equivalent to Calc's built-in @code{arctan} function, Xand would have written the formula back with notations (like implicit Xmultiplication) which would not have been legal for a C program. X XAs another example, suppose you are maintaining a C program and a @TeX{} Xdocument, each of which needs a copy of the same formula. You can grab the Xformula from the program in C mode, switch to @TeX{} mode, and yank the Xformula into the document in @TeX{} math-mode format. X XLanguage modes are selected by typing the letter @kbd{d} followed by a Xshifted letter key. X X@menu X* Normal Language Modes:: X* C Fortran Pascal:: X* Tex Language Mode:: X* Mathematica Language Mode:: X@end menu X X@node Normal Language Modes, C Fortran Pascal, Language Modes, Language Modes X@subsection Normal Language Modes X X@kindex d N X@pindex calc-normal-language XThe @kbd{d N} (@code{calc-normal-language}) command selects the usual Xnotation for Calc formulas, as described in the rest of this manual. XMatrices are displayed in a multi-line tabular format, but all other Xobjects are written in linear form, as they would be typed from the Xkeyboard. X X@kindex d O X@pindex calc-flat-language X@cindex Matrix display XThe @kbd{d O} (@code{calc-flat-language}) command selects a language Xidentical with the normal one, except that matrices are written in Xone-line form along with everything else. In some applications this Xform may be more suitable for yanking data into other buffers. X X@kindex d b X@pindex calc-line-breaking X@cindex Line breaking X@cindex Breaking up long lines XEven in one-line mode, long formulas or vectors will still be split Xacross multiple lines if they exceed the width of the Calculator window. XThe @kbd{d b} (@code{calc-line-breaking}) command turns this line-breaking Xfeature on and off. (It works independently of the current language.) X X@kindex d B X@pindex calc-big-language XThe @kbd{d B} (@code{calc-big-language}) command selects a language Xwhich uses textual approximations to various mathematical notations, Xparticularly powers and quotients: X X@example Xa + 1 2 X----- + c X b X@end example X X@noindent Xin place of @samp{(a+1)/b + c^2}. X XIn ``big'' format, stack entries often take up several lines. To aid Xreadability, stack entries are separated by a blank line in this mode. XYou may find it useful to expand the Calc window's height using X@kbd{C-x ^} (@code{enlarge-window}) or to make the Calc window the only Xone on the screen with @kbd{C-x 1} (@code{delete-other-windows}). X X@kindex d U X@pindex calc-unformatted-language XThe @kbd{d U} (@code{calc-unformatted-language}) command altogether disables Xthe use of operator notation in formulas. In this mode, the formula Xshown above would be displayed: X X@example Xadd(div(add(a, 1), b), pow(c, 2)) X@end example X XThese four modes differ only in display format, not in the format Xexpected for algebraic entry. The standard Calc operators work in Xall four modes, and unformatted notation works in any language mode X(except that Mathematica mode expects square brackets instead of Xparentheses.) X X@node C Fortran Pascal, Tex Language Mode, Normal Language Modes, Language Modes X@subsection C, Fortran, and Pascal Modes X X@kindex d C X@pindex calc-c-language X@cindex C language XThe @kbd{d C} (@code{calc-c-language}) command selects the conventions Xof the C language for display and entry of formulas. This differs from Xthe normal language mode in a variety of (mostly minor) ways. In Xparticular, C language operators and operator precedences are used in Xplace of Calc's usual ones. For example, @samp{a^b} means @samp{xor(a,b)} Xin C mode; a value raised to a power is written as a function call, X@samp{pow(a,b)}. X XIn C mode, vectors and matrices use curly braces instead of brackets. XOctal and hexadecimal values are written with leading @samp{0} or @samp{0x} Xrather than using the @samp{#} symbol. Some operators, such as array Xsubscripting and assignments, are translated into functions like X@code{subscr} which the rest of Calc will leave alone. X XThe variables @code{var-pi} and @code{var-e} would be displayed @samp{pi} Xand @samp{e} in normal mode, but in C mode they are displayed as X@samp{M_PI} and @samp{M_E}, corresponding to the names of constants Xtypically provided in the @file{} header. Functions whose Xnames are different in C are translated automatically for entry and Xdisplay purposes. For example, entering @samp{asin(x)} will push the Xformula @samp{arcsin(x)} onto the stack; this formula will be displayed Xas @samp{asin(x)} as long as C mode is in effect. X X@kindex d P X@pindex calc-pascal-language X@cindex Pascal language XThe @kbd{d P} (@code{calc-pascal-language}) command selects Pascal Xconventions. Like C, Pascal mode interprets array brackets and uses Xa different table of operators. No special provisions are made for Xnon-decimal numbers, vectors, and so on, since there is no universally Xaccepted standard way of handling these in Pascal. X X@kindex d F X@pindex calc-fortran-language X@cindex Fortran language XThe @kbd{d F} (@code{calc-fortran-language}) command selects Fortran Xconventions. Various function names are transformed into Fortran Xequivalents. Vectors are written as @samp{/1, 2, 3/}, though they must Xstill be entered using square brackets. Since Fortran uses round Xparentheses for both function calls and array subscripts, Calc treats Xboth as if they were function calls. X XFortran and Pascal modes normally do not adjust the case of letters in Xformulas. All built-in Calc names use lower-case letters. If you use a Xpositive numeric prefix argument with @kbd{d P} or @kbd{d F}, these Xmodes will use upper-case letters exclusively for display, and will Xconvert to lower-case on input. With a negative prefix, these modes Xconvert to lower-case for display and input. X X@node Tex Language Mode, Mathematica Language Mode, C Fortran Pascal, Language Modes X@subsection @TeX{} Language Mode X X@kindex d T X@pindex calc-tex-language X@cindex TeX language XThe @kbd{d T} (@code{calc-tex-language}) command selects the conventions Xof ``math mode'' in the @TeX{} typesetting language, by Donald Knuth. XFormulas are entered Xand displayed in @TeX{} notation, as in @samp{\sin\left( a \over b \right)}. XMath formulas are usually enclosed by @samp{$ $} signs in @TeX{}; these Xshould be omitted when interfacing with Calc. To Calc, the @samp{$} sign Xhas the same meaning it always does in algebraic formulas (a reference to Xan existing entry on the stack).@refill X XComplex numbers are displayed as in @samp{3 + 4i}. Subscripts X(@samp{subscr(a, i)}, written @samp{a[i]} in C and Pascal modes) are Xwritten @samp{a_i} in @TeX{} mode. Fractions and quotients are written Xusing @code{\over}; binomial coefficients are written with @code{\choose}. XInterval forms are written with @code{\dots}, and Xerror forms are written with @code{\pm}. XAbsolute values are written as in @samp{|x + 1|}, and the floor and Xceiling functions are written with @code{\lfloor}, @code{\rfloor}, etc. XThe words @code{\left} and @code{\right} are ignored when reading Xformulas in @TeX{} mode.@refill X XFunction calls are written the usual way, with the function name followed Xby the arguments in parentheses. However, functions for which @TeX{} has Xspecial names (like @code{\sin}) will use curly braces instead of Xparentheses for very simple arguments. During input, curly braces and Xparentheses work equally well for grouping, but when the document is Xformatted the curly braces will be invisible. Thus the printed result is X@samp{sin 2x} but @samp{sin(2 + x)}. X XFunction and variable names not treated specially by @TeX{} are simply Xwritten out as-is, which will cause them to come out in italic letters Xin the printed document. If you invoke @kbd{d T} with any numeric Xprefix argument, names of more than one character will instead be written X@samp{\hbox@{@var{name}@}}. The @samp{\hbox@{ @}} notation is ignored Xduring reading. X X@node Mathematica Language Mode, , TeX Language Mode, Language Modes X@subsection Mathematica Language Mode X X@kindex d M X@pindex calc-mathematica-language X@cindex Mathematica language XThe @kbd{d M} (@code{calc-mathematica-language}) command selects the Xconventions of Mathematica, a powerful and popular mathematical tool Xfrom Wolfram Research, Inc. Notable differences in Mathematica mode Xare that the names of built-in functions are capitalized, and function Xcalls use square brackets instead of parentheses. Thus the Calc Xformula @samp{sin(2 x)} is entered and displayed @samp{Sin[2 x]} in XMathematica mode. X XVectors and matrices use curly braces in Mathematica. Complex numbers Xare written @samp{3 + 4 I}. The standard special constants in Calc are Xwritten @code{Pi}, @code{E}, and @code{I} in Mathematica mode. XNon-decimal numbers are written, e.g., @samp{16^^7fff}. Floating-point Xnumbers in scientific notation are written @samp{1.23*10^3}.@refill X X@node Arithmetic, Scientific Functions, Mode Settings, Top X@chapter Arithmetic Functions X XThis chapter describes the Calc commands for doing simple calculations Xon numbers, such as addition, absolute value, and square roots. These Xcommands work by removing the top one or two values from the stack, Xperforming the desired operation, and pushing the result back onto the Xstack. If the operation cannot be performed, the result pushed is a Xformula instead of a number, such as @samp{2/0} (because division by zero Xis illegal) or @samp{sqrt(x)} (because the argument @samp{x} is a formula). X X@xref{Prefix Arguments}, for a discussion of the effect of numeric Xprefix arguments on commands in this chapter which do not otherwise Xinterpret a prefix argument. X X@menu X* Basic Arithmetic:: X* Integer Truncation:: X* Complex Number Functions:: X* Conversions:: X@end menu X X@node Basic Arithmetic, Integer Truncation, Arithmetic, Arithmetic X@section Basic Arithmetic X X@kindex + X@pindex calc-plus XThe @kbd{+} (@code{calc-plus}) command adds two numbers. The numbers may Xbe any of the standard Calc data types. The resulting sum is pushed back Xonto the stack. X XIf both arguments of @kbd{+} are vectors or matrices (of matching dimensions), Xthe result is a vector or matrix sum. If one argument is a vector and the Xother a scalar (i.e., a non-vector), the scalar is added to each of the Xelements of the vector to form a new vector. If the scalar is not a Xnumber, the operation is left in symbolic form: Suppose you added @samp{x} Xto the vector @samp{[1,2]}. You may want the result @samp{[1+x,2+x]}, or Xyou may plan to substitute a 2-vector for @samp{x} in the future. Since Xthe Calculator can't tell which interpretation you want, it makes the Xsafest assumption. @xref{Reducing and Mapping}, for a way to add @samp{x} Xto every element of a vector. X XIf either argument of @kbd{+} is a complex number, the result will in general Xbe complex. If one argument is in rectangular form and the other polar, Xthe current Polar Mode determines the form of the result. If Symbolic XMode is enabled, the sum may be left as a formula if the necessary Xconversions for polar addition are non-trivial. X XIf both arguments of @kbd{+} are HMS forms, the forms are added according to Xthe usual conventions of hours-minutes-seconds notation. If one argument Xis an HMS form and the other is a number, that number is converted from Xdegrees or radians (depending on the current Angular Mode) to HMS format Xand then the two HMS forms are added. X XIf both arguments of @kbd{+} are error forms, the result is an error form Xwith an appropriately computed standard deviation. If one argument is an Xerror form and the other is a number, the number is taken to have zero error. XError forms may have symbolic formulas as their mean and/or error parts; Xadding these will produce a symbolic error form result. However, adding an Xerror form to a plain symbolic formula (as in @samp{(a +/- b) + c}) will not Xwork, for the same reasons just mentioned for vectors. Instead you must Xwrite @samp{(a +/- b) + (c +/- 0)}. X XIf both arguments of @kbd{+} are modulo forms with equal values of @samp{M}, Xor if one argument is a modulo form and the other a plain number, the Xresult is a modulo form which represents the sum, modulo @samp{M}, of Xthe two values. X XIf both arguments of @kbd{+} are intervals, the result is an interval Xwhich describes all possible sums of the possible input values. If one Xargument is a plain number, it is treated as the interval @samp{[x .. x]}. X X@kindex - X@pindex calc-minus XThe @kbd{-} (@code{calc-minus}) command subtracts two values. The top Xnumber on the stack is subtracted from the one behind it, so that the Xcomputation @kbd{5 @key{RET} 2 -} produces 3, not -3. All options Xavailable for @kbd{+} are available for @kbd{-} as well. X X@kindex * X@pindex calc-times XThe @kbd{*} (@code{calc-times}) command multiplies two numbers. If one Xargument is a vector and the other a scalar, the scalar is multiplied by Xthe elements of the vector to produce a new vector. If both arguments Xare vectors, the interpretation depends on the dimensions of the Xvectors: If both arguments are matrices, a matrix multiplication is Xdone. If one argument is a matrix and the other a plain vector, the Xvector is interpreted as a row vector or column vector, whichever is Xdimensionally correct. If both arguments are plain vectors, the result Xis a single scalar number which is the dot product of the two vectors. X XIf one argument of @kbd{*} is an HMS form and the other a number, the XHMS form is multiplied by that amount. It is an error to multiply two XHMS forms together. Error forms, modulo forms, and intervals can also Xbe multiplied; see the comments for addition of those forms. When two Xerror forms or intervals are multiplied they are considered to be Xindependent; thus, @samp{[-2 .. 3] * [-2 .. 3]} is @samp{[-6 .. 9]}, Xwhereas @samp{[-2 .. 3] ^ 2} is @samp{[0 .. 9]}. X X@kindex / X@pindex calc-divide XThe @kbd{/} (@code{calc-divide}) command divides two numbers. When Xdividing a scalar @samp{B} by a square matrix @samp{A}, the computation Xperformed is @samp{B} times the inverse of @samp{A}. This also occurs Xif @samp{A} is itself a vector or matrix, in which case the effect is Xto solve the set of linear equations represented by @samp{B}. If @samp{A} Xis a matrix with the same number of rows as @samp{B}, or a plain vector X(which is interpreted here as a column vector), then the equation X@samp{A X = B} is solved for the vector or matrix @samp{X}. Otherwise, Xif @samp{A} is a non-square matrix with the same number of @emph{columns} Xas @samp{B}, the equation @samp{X A = B} is solved. If you wish a vector X@samp{A} to be interpreted as a row vector to be solved as @samp{X A = B}, Xmake it into a one-row matrix with @kbd{C-u 1 v p} first. To force a Xleft-handed solution with a square matrix @samp{A}, transpose @samp{A} and X@samp{B} before dividing, then transpose the result. X XHMS forms can be divided by real numbers or by other HMS forms. Error Xforms can be divided in any combination of ways. Modulo forms where both Xvalues and the modulo are integers can be divided to get an integer modulo Xform result. Intervals can be divided, except that it is not possible to Xdivide by an interval that encompasses zero or has zero as a limit, since Xthis would result in an infinite interval. X X@kindex ^ X@pindex calc-power XThe @kbd{^} (@code{calc-power}) command raises a number to a power. If Xthe power is an integer, an exact result is computed using repeated Xmultiplications. For non-integer powers, Calc uses logarithms and Xexponentials. Square matrices can be raised to integer powers. If either Xargument is an error (or interval or modulo) form, the result is also an Xerror (or interval or modulo) form. X X@kindex % X@pindex calc-mod XThe @kbd{%} (@code{calc-mod}) command performs a ``modulo'' (or ``remainder'') Xoperation. Mathematically, @samp{a%b = a - floor(a/b)*b}, and is defined Xfor all real numbers @samp{a} and @samp{b} (except @samp{b}=0). For Xpositive @samp{b}, the result will always be between 0 (inclusive) and X@samp{b} (exclusive). Modulo does not work for HMS forms and error forms. Xif @samp{a} is a modulo form, its modulo is changed to @samp{b}, which Xmust be positive real number. X X@kindex \ X@pindex calc-idiv X@tindex idiv XThe @kbd{\} (@code{calc-idiv}) command divides two numbers on the stack Xto produce an integer result. It is equivalent to dividing with X@key{/}, then rounding down with @kbd{F} (@code{calc-floor}), only a bit Xmore convenient and efficient. X X@kindex : X@pindex calc-fdiv X@tindex fdiv XThe @kbd{:} (@code{calc-fdiv}) command [@code{fdiv} function in a formula] Xdivides the two integers on the top of the stack to produce a fractional Xresult. This is a convenient shorthand to enabling Fraction Mode (with X@code{calc-frac-mode}) temporarily and using @samp{/}. Note that during Xnumeric entry the @kbd{:} key is interpreted as a fraction separator, so Xto divide 8 by 6 you would have to type @kbd{8 @key{RET} 6 @key{RET} :}. X(Of course, in this case, it would be much easier simply to enter the Xfraction directly as @kbd{8:6 @key{RET}}!) X X@kindex n X@pindex calc-change-sign XThe @kbd{n} (@code{calc-change-sign}) command negates the number on the top Xof the stack. It works on numbers, vectors and matrices, HMS forms, error Xforms, and modulo forms. X X@kindex A X@pindex calc-abs X@tindex abs XThe @kbd{A} (@code{calc-abs}) [@code{abs}] command computes the absolute Xvalue of a number. The result of @code{abs} is always a nonnegative Xreal number: With a complex argument, it computes the complex magnitude. XWith a vector or matrix argument, it computes the Frobenius norm, i.e., Xthe square root of the sum of the squares of the absolute values of the Xelements. The absolute value of an error form is defined by replacing Xthe mean part with its absolute value and leaving the error part the same. XThe absolute value of a modulo form is undefined. X X@pindex calc-abssqr X@tindex abssqr XThe @code{calc-abssqr} [@code{abssqr}] command computes the absolute Xvalue squared of a number, vector or matrix, or error form. X X@pindex calc-sign X@tindex sign XThe @code{sign} algebraic function returns 1 if its argument is positive, X-1 if its argument is negative, or 0 if its argument is zero. X X@kindex & X@pindex calc-inv X@tindex inv X@cindex Reciprocal XThe @kbd{&} (@code{calc-inv}) [@code{inv}] command computes the Xreciprocal of a number. It is also available as the @kbd{V I} Xkey sequence, where it would normally be used to invert a matrix. X X@kindex Q X@pindex calc-sqrt X@tindex sqrt XThe @kbd{Q} (@code{calc-sqrt}) [@code{sqrt}] command computes the square Xroot of a number. For a negative real argument, the result will be a Xcomplex number whose form is determined by the current Polar Mode. X X@pindex calc-hypot X@tindex hypot XThe @code{calc-hypot} [@code{hypot}] command computes the square root of Xthe sum of the squares of two numbers. That is, @samp{hypot(a,b)} is the Xlength of the hypotenuse of a right triangle with sides @samp{a} and @samp{b}. X X@pindex calc-min X@tindex min X@pindex calc-max X@tindex max XThe @code{calc-min} [@code{min}] and @code{calc-max} [@code{max}] commands Xtake the minimum or maximum of two real numbers, respectively. These Xcommands also work on HMS forms. (In algebraic expressions, these functions Xtake any number of arguments and return the maximum or minimum among all Xthe arguments.)@refill X X@node Integer Truncation, Complex Number Functions, Basic Arithmetic, Arithmetic X@section Integer Truncation X XThere are four commands for truncating a real number to an integer, Xdiffering mainly in their treatment of negative numbers. All of these Xcommands have the property that if the argument is an integer, the result Xis the same integer. An integer-valued floating-point argument is converted Xto integer form. X XIf you press @kbd{H} (@code{calc-hyperbolic}) first, the result will be Xexpressed as an integer-valued floating-point number. X X@cindex Integer part of a number X@kindex F X@kindex H F X@pindex calc-floor X@tindex floor X@tindex ffloor XThe @kbd{F} (@code{calc-floor}) [@code{floor} or @code{ffloor}] command Xtruncates a real number to the next lower integer, i.e., toward minus Xinfinity. Thus @kbd{3.6 F} produces 3, but @kbd{_3.6 F} produces X-4.@refill X X@kindex I F X@kindex H I F X@pindex calc-ceiling X@tindex ceil X@tindex fceil XThe @kbd{I F} (@code{calc-ceiling}) [@code{ceil} or @code{fceil}] Xcommand truncates toward positive infinity. Thus @kbd{3.6 I F} produces X4, and @kbd{_3.6 I F} produces -3.@refill X X@kindex R X@kindex H R X@pindex calc-round X@tindex round X@tindex fround XThe @kbd{R} (@code{calc-round}) [@code{round} or @code{fround}] command Xrounds to the nearest integer. When the fractional part is .5 exactly, Xthis command rounds away from zero. (All other rounding in the XCalculator uses this convention as well.) Thus @kbd{3.5 R} produces 4 Xbut @kbd{3.4 R} produces 3; @kbd{_3.5 R} produces -4.@refill X X@kindex I R X@kindex H I R X@pindex calc-trunc X@tindex trunc X@tindex ftrunc XThe @kbd{I R} (@code{calc-trunc}) [@code{trunc} or @code{ftrunc}] Xcommand truncates toward zero. In other words, it ``chops off'' Xeverything after the decimal point. Thus @kbd{3.6 I R} produces 3 and X@kbd{_3.6 I R} produces -3.@refill X XThese functions may not be applied meaningfully to error forms, but they Xdo work for intervals. As a convenience, applying @code{floor} to a Xmodulo form floors the value part of the form. X X@cindex Fractional part of a number XTo compute the fractional part of a number (i.e., the amount which, when Xadded to @samp{floor(N)}, will produce @samp{N}) just take @samp{N} modulo 1 Xusing the @code{%} command.@refill X X@node Complex Number Functions, Conversions, Integer Truncation, Arithmetic X@section Complex Number Functions X X@kindex J X@pindex calc-conj X@tindex conj XThe @kbd{J} (@code{calc-conj}) [@code{conj}] command computes the Xcomplex conjugate of a number. For complex number @samp{a+bi}, the Xcomplex conjugate is @samp{a-bi}. If the argument is a real number, Xthis command leaves it the same. If the argument is a vector or matrix, Xthis command replaces each element by its complex conjugate. X X@kindex G X@pindex calc-argument X@tindex arg XThe @kbd{G} (@code{calc-argument}) [@code{arg}] command computes the X``argument'' or polar angle of a complex number. For a number in polar Xnotation, this is simply the second component of the pair @samp{(r,theta)}. XThe result is expressed according to the current angular mode and will Xbe in the range -180 degrees (exclusive) to +180 degrees (inclusive), Xor the equivalent range in radians.@refill X X@pindex calc-imaginary XThe @code{calc-imaginary} command multiplies the number on the Xtop of the stack by the imaginary number @samp{i = (0,1)}. X X@pindex calc-re X@tindex re XThe @code{calc-re} [@code{re}] command replaces a complex number by Xits real part. This command has no effect on real numbers. (As an Xadded convenience, @code{re} applied to an error or modulo form extracts Xthe value part.)@refill X X@pindex calc-im X@tindex im XThe @code{calc-im} [@code{im}] command replaces a complex number by its Ximaginary part; real numbers are converted to zero. With a vector or Xmatrix argument, these functions operate element-wise.@refill X X@kindex v p (complex) X@pindex calc-pack XThe @kbd{v p} (@code{calc-pack}) command takes the top two numbers on the Xthe stack and packs them into a complex number according to the current XPolar mode. With a prefix argument of -1, it always produces a rectangular Xcomplex number; with an argument of -2, it produces a polar complex number. X(Also, @xref{Building Vectors}.) X X@kindex v u (complex) X@pindex calc-unpack XThe @kbd{v u} (@code{calc-unpack}) command takes the complex number X(or other composite object) on the top of the stack and unpacks it Xinto its separate components. X X@node Conversions, , Complex Number Functions, Arithmetic X@section Conversions X XThe commands described in this section are two-key sequences beginning with Xthe letter @kbd{c}. X X@kindex c f X@pindex calc-float X@tindex float XThe @kbd{c f} (@code{calc-float}) [@code{float}] command converts the Xnumber on the top of the stack to floating-point form. For example, X@samp{23} is converted to @samp{23.0}, @samp{3:2} is converted to X@samp{1.5}, and @samp{2.3} is left the same. If the value is a composite Xobject such as a complex number or vector, each of the components is Xconverted to floating-point. Note that depending on the current Xfloating-point precision, conversion to floating-point format may lose Xinformation.@refill X X@kindex c F X@pindex calc-fraction X@tindex frac XThe @kbd{c F} (@code{calc-fraction}) [@code{frac}] command converts a Xfloating-point number into a fractional approximation. By default, it Xproduces a fraction whose decimal representation is the same as the Xinput number, to within the current precision. You can also give a Xnumeric prefix argument to specify a tolerance, either directly, or, Xif the prefix argument is zero, by using the number on top of the stack Xas the tolerance. If the tolerance is a positive integer, the fraction Xis correct to within that many significant figures. If the tolerance is Xa non-positive integer, it specifies how many digits fewer than the current Xprecision to use. If the tolerance is a floating-point number, the Xfraction is correct to within that absolute amount. X X@kindex c d X@pindex calc-to-degrees X@tindex deg XThe @kbd{c d} (@code{calc-to-degrees}) [@code{deg}] command converts a Xnumber into degrees form. The value on the top of the stack may be an XHMS form (interpreted as degrees-minutes-seconds), or a real number which Xwill be interpreted in radians regardless of the current angular mode.@refill X X@kindex c r X@pindex calc-to-radians X@tindex rad XThe @kbd{c r} (@code{calc-to-radians}) [@code{rad}] command converts an XHMS form or angle in degrees into an angle in radians. X X@kindex c h X@pindex calc-to-hms X@tindex hms XThe @kbd{c h} (@code{calc-to-hms}) [@code{hms}] command converts a real Xnumber, interpreted according to the current angular mode, to an HMS Xform describing the same angle. X X@pindex calc-from-hms XThe @code{calc-from-hms} command converts the HMS form on the top of the Xstack into a real number according to the current angular mode. X X@kindex c p X@pindex calc-polar X@tindex polar X@tindex rect XThe @kbd{c p} (@code{calc-polar}) command converts the complex number on Xthe top of the stack from polar to rectangular form, or from rectangular Xto polar form, whichever is appropriate. Real numbers are left the same. XThis command is equivalent to the @code{rect} or @code{polar} Xfunctions in algebraic formulas, depending on the direction of Xconversion.@refill X X@kindex c c X@pindex calc-clean X@tindex clean XThe @kbd{c c} (@code{calc-clean}) [@code{clean}] command ``cleans'' the Xnumber on the top of the stack. Floating point numbers are re-rounded Xaccording to the current precision. Polar numbers whose angular components Xhave strayed from the -180 to +180 degree range are normalized. (Note that Xresults will be undesirable if the current angular mode is different from Xthe one under which the number was produced!) Integers and fractions are Xgenerally unaffected by this operation.@refill X XIf the simplification mode is set below the default level, it is raised Xto the default level for the purposes of this command. Thus, you can Xuse @kbd{c c} to apply the default simplifications manually when their Xautomatic application is disabled. @xref{Simplification Modes}. X X@cindex Roundoff errors, correcting XA numeric prefix argument to @kbd{c c} sets the floating-point precision Xto that value for the duration of the command. A positive prefix (of at Xleast 3) sets the precision to the specified value; a negative prefix Xdecreases the precision by the specified amount. X X@kindex c 1 X@kindex c 2 X@kindex c 3 XThe keystroke sequences @kbd{c 1}, @kbd{c 2} and @kbd{c 3} are equivalent Xto @kbd{c c} with the corresponding negative prefix argument. If roundoff Xerrors have changed 2.0 into 1.999999, typing @kbd{c 1} to clip off one Xdecimal place often conveniently does the trick. X X@node Scientific Functions, Binary Functions, Arithmetic, Top X@chapter Scientific Functions X XThe functions described here perform trigonometric and other transcendental Xcalculations. They generally produce floating-point answers correct to the Xfull current precision. The @kbd{H} (Hyperbolic) and @kbd{I} (Inverse) Xflag keys must be used to get some of these functions from the keyboard. X X@kindex P X@pindex calc-pi X@cindex @code{pi} variable X@kindex H P X@cindex @code{e} variable XOne miscellanous command is shift-@kbd{P} (@code{calc-pi}), which pushes Xthe value of @samp{pi} (at the current precision) onto the stack. With the XHyperbolic flag, it pushes the value @samp{e}, the base of natural logarithms. XIn Symbolic mode, these commands push the actual variables @samp{pi} and X@samp{e} instead of their values; @pxref{Symbolic Mode}. X XThe @kbd{Q} (@code{calc-sqrt}) [@code{sqrt}] function is described elsewhere; X@pxref{Basic Arithmetic}. With the Inverse flag [@code{sqr}], this command Xcomputes the square of the argument. X X@xref{Prefix Arguments}, for a discussion of the effect of numeric Xprefix arguments on commands in this chapter which do not otherwise Xinterpret a prefix argument. X X@menu X* Logarithmic Functions:: X* Trigonometric and Hyperbolic Functions:: X* Branch Cuts:: X* Random Numbers:: X* Combinatorial Functions:: X@end menu X X@node Logarithmic Functions, Trigonometric and Hyperbolic Functions, Scientific Functions, Scientific Functions X@section Logarithmic Functions X X@kindex L X@kindex I E X@pindex calc-ln X@tindex ln XThe shift-@kbd{L} (@code{calc-ln}) [@code{ln}] command computes the natural Xlogarithm of the real or complex number on the top of the stack. With Xthe Inverse flag it computes the exponential function instead. With Xthe Hyperbolic flag it computes the common (base-10) logarithm. With Xboth flags, it computes 10 to a given power. X X@kindex E X@kindex I L X@pindex calc-exp X@tindex exp XThe shift-@kbd{E} (@code{calc-exp}) [@code{exp}] command computes the Xexponential, i.e., @samp{e} raised to the power of the number on the stack. XThe meanings of the Inverse and Hyperbolic flags follow from those for Xthe @code{calc-ln} command. X X@kindex H L X@kindex H I L X@kindex H E X@kindex H I E X@pindex calc-log10 X@tindex log10 X@tindex pow10 XThe @kbd{H L} (@code{calc-log10}) [@code{log10}] command computes the common X(base-10) logarithm of a number. The meanings of the Inverse [@code{pow10}] Xand Hyperbolic flags follow from those for the @code{calc-ln} command. Note Xthat the common logarithm of a complex number is computed by taking the Xnatural logarithm and dividing by @samp{ln(10)}. X X@kindex B X@pindex calc-log X@tindex log X@tindex ilog XThe @kbd{B} (@code{calc-log}) [@code{log}] command computes a logarithm Xto any base. For example, @kbd{1024 @key{RET} 2 B} produces 10, since X@samp{2^10 = 1024}. With the Inverse flag [@code{ilog}], this is similar Xto @kbd{^} except that the order of the arguments is reversed. X X@pindex calc-expm1 X@tindex expm1 XThe @code{calc-expm1} [@code{expm1}] command computes @samp{exp(x)-1}, but Xusing an algorithm that produces a more accurate answer when the result Xis close to zero, i.e., when @samp{exp(x)} is close to one. X X@pindex calc-lnp1 X@tindex lnp1 XThe @code{calc-lnp1} [@code{lnp1}] command computes @samp{ln(x+1)}, Xproducing a more accurate answer when @samp{x} is close to zero. X X@node Trigonometric and Hyperbolic Functions, Branch Cuts, Logarithmic Functions, Scientific Functions X@section Trigonometric and Hyperbolic Functions X X@kindex S X@pindex calc-sin X@tindex sin XThe shift-@kbd{S} (@code{calc-sin}) [@code{sin}] command computes the sine SHAR_EOF echo "End of part 15" echo "File calc.texinfo is continued in part 16" echo "16" > s2_seq_.tmp exit 0