home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume13 / gmcalc / part15 < prev    next >
Encoding:
Text File  |  1990-06-05  |  57.7 KB  |  1,323 lines

  1. Newsgroups: comp.sources.misc
  2. From: daveg@csvax.caltech.edu (David Gillespie)
  3. Subject: v13i041: Emacs Calculator 1.01, part 15/19
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 13, Issue 41
  7. Submitted-by: daveg@csvax.caltech.edu (David Gillespie)
  8. Archive-name: gmcalc/part15
  9.  
  10. ---- Cut Here and unpack ----
  11. #!/bin/sh
  12. # this is part 15 of a multipart archive
  13. # do not concatenate these parts, unpack them in order with /bin/sh
  14. # file calc.texinfo continued
  15. #
  16. CurArch=15
  17. if test ! -r s2_seq_.tmp
  18. then echo "Please unpack part 1 first!"
  19.      exit 1; fi
  20. ( read Scheck
  21.   if test "$Scheck" != $CurArch
  22.   then echo "Please unpack part $Scheck next!"
  23.        exit 1;
  24.   else exit 0; fi
  25. ) < s2_seq_.tmp || exit 1
  26. echo "x - Continuing file calc.texinfo"
  27. sed 's/^X//' << 'SHAR_EOF' >> calc.texinfo
  28. X@section Inverse and Hyperbolic Flags
  29. X
  30. X@kindex I
  31. X@pindex calc-inverse
  32. XThere is no single-key equivalent to the @code{calc-arcsin} function.
  33. XInstead, you must first press @kbd{I} (@code{calc-inverse}) to set
  34. Xthe @dfn{Inverse Flag}, then press @kbd{S} (@code{calc-sin}).
  35. XThe @kbd{I} key actually toggles the Inverse Flag.  When this flag
  36. Xis set, the word @samp{Inv} appears in the mode line.@refill
  37. X
  38. X@kindex H
  39. X@pindex calc-hyperbolic
  40. XLikewise, the @kbd{H} key (@code{calc-hyperbolic}) sets or clears the
  41. XHyperbolic Flag, which transforms @code{calc-sin} into @code{calc-sinh}.
  42. XIf both of these flags are set at once, the effect will be
  43. X@code{calc-arcsinh}.  (The Hyperbolic flag is also used by some
  44. Xnon-trigonometric commands; for example @kbd{H L} computes a base-10,
  45. Xinstead of base-e, logarithm.)@refill
  46. X
  47. XCommand names like @code{calc-arcsin} are provided for completeness, and
  48. Xmay be executed with @kbd{x} or @kbd{M-x}.  Their effect is simply to
  49. Xtoggle the Inverse and/or Hyperbolic flags and then execute the
  50. Xcorresponding base command (@code{calc-sin} in this case).
  51. X
  52. XThe Inverse and Hyperbolic flags apply only to the next Calculator
  53. Xcommand, after which they are automatically cleared.
  54. X
  55. X@node Calculation Modes, Simplification Modes, Inverse and Hyperbolic, Mode Settings
  56. X@section Calculation Modes
  57. X
  58. XThe commands in this section are two-key sequences beginning with
  59. Xthe @kbd{m} prefix.  (That's the letter @kbd{m}, not the @key{META} key.)
  60. X
  61. XThe @samp{m a} (@code{calc-algebraic-mode}) command is described elsewhere
  62. X(@pxref{Algebraic Entry}.)
  63. X
  64. X@menu
  65. X* Angular Modes::
  66. X* Polar Mode::
  67. X* Fraction Mode::
  68. X* Symbolic Mode::
  69. X* Working Message::
  70. X@end menu
  71. X
  72. X@node Angular Modes, Polar Mode, Calculation Modes, Calculation Modes
  73. X@subsection Angular Modes
  74. X
  75. X@cindex Angular mode
  76. XThe Calculator supports three notations for angles: radians, degrees,
  77. Xand degrees-minutes-seconds.  When a number is presented to a function
  78. Xlike @code{calc-sin} that requires an angle, the current angular mode is
  79. Xused to interpret the number as either radians or degrees.  If an HMS
  80. Xform is presented to @code{calc-sin}, it is always interpreted as
  81. Xdegrees-minutes-seconds.
  82. X
  83. XFunctions that compute angles produce a number in radians, a number in
  84. Xdegrees, or an HMS form depending on the current angular mode.  If the
  85. Xresult is a complex number and the current mode is HMS, the number is
  86. Xinstead expressed in degrees.  (Complex-number calculations would
  87. Xnormally be done in radians mode, though.  Complex numbers are converted
  88. Xto degrees by calculating the complex result in radians and then
  89. Xmultiplying by 180 over @samp{pi}.)
  90. X
  91. X@kindex m r
  92. X@pindex calc-radians-mode
  93. X@kindex m d
  94. X@pindex calc-degrees-mode
  95. X@kindex m h
  96. X@pindex calc-hms-mode
  97. XThe @kbd{m r} (@code{calc-radians-mode}), @kbd{m d} (@code{calc-degrees-mode}),
  98. Xand @kbd{m h} (@code{calc-hms-mode}) commands control the angular mode.
  99. XThe current angular mode is displayed on the Emacs mode line.
  100. XThe default angular mode is degrees.@refill
  101. X
  102. X@node Polar Mode, Fraction Mode, Angular Modes, Calculation Modes
  103. X@subsection Polar Mode
  104. X
  105. X@cindex Polar mode
  106. XThe Calculator normally ``prefers'' rectangular complex numbers in the
  107. Xsense that rectangular form is used when the proper form can not be
  108. Xdecided from the input.  This might happen by multiplying a rectangular
  109. Xnumber by a polar one, by taking the square root of a negative real
  110. Xnumber, or by entering @kbd{( 2 @key{SPC} 3 )}.
  111. X
  112. X@kindex m p
  113. X@pindex calc-polar-mode
  114. XThe @kbd{m p} (@code{calc-polar-mode}) command toggles complex-number
  115. Xpreference between rectangular and polar forms.  In polar mode, all
  116. Xof the above example situations would produce polar complex numbers.
  117. X
  118. X@node Fraction Mode, Symbolic Mode, Polar Mode, Calculation Modes
  119. X@subsection Fraction Mode
  120. X
  121. X@cindex Fraction mode
  122. X@cindex Division of integers
  123. XDivision of two integers normally yields a floating-point number if the
  124. Xresult cannot be expressed as an integer.  In some cases you would
  125. Xrather get an exact fractional answer.  One way to accomplish this is
  126. Xto multiply fractions instead:  @kbd{6 @key{RET} 1:4 *} produces @samp{3:2}
  127. Xeven though @kbd{6 @key{RET} 4 /} produces @samp{1.5}.
  128. X
  129. X@kindex m f
  130. X@pindex calc-frac-mode
  131. XTo set the Calculator to produce fractional results for normal integer
  132. Xdivisions, use the @kbd{m f} (@code{calc-frac-mode}) command.
  133. XFor example, @samp{8/4} produces @samp{2} in either mode,
  134. Xbut @samp{6/4} produces @samp{3:2} in Fraction Mode, but @samp{1.5} in
  135. XFloat Mode.@refill
  136. X
  137. XAt any time you can use @kbd{c f} (@code{calc-float}) to convert a
  138. Xfraction to a float, or @kbd{c F} (@code{calc-fraction}) to convert a
  139. Xfloat to a fraction.  @xref{Conversions}.
  140. X
  141. X@node Symbolic Mode, Working Message, Fraction Mode, Calculation Modes
  142. X@subsection Symbolic Mode
  143. X
  144. X@cindex Symbolic mode
  145. X@cindex Inexact results
  146. XCalculations are normally performed numerically wherever possible.
  147. XFor example, the @code{calc-sqrt} command, or @code{sqrt} function in an
  148. Xalgebraic expression, produces a numeric answer if the argument is a
  149. Xnumber or a symbolic expression if the argument is an expression:
  150. X@kbd{2 Q} pushes 1.4142 but @kbd{@key{'} x+1 @key{RET} Q} pushes @samp{sqrt(x+1)}.
  151. X
  152. X@kindex m s
  153. X@pindex calc-symbolic-mode
  154. XIn @dfn{symbolic mode}, controlled by the @kbd{m s} (@code{calc-symbolic-mode})
  155. Xcommand, functions which would produce inexact, irrational results are
  156. Xleft in symbolic form.  Thus @kbd{16 Q} pushes 4, but @kbd{2 Q} pushes
  157. X@samp{sqrt(2)}.
  158. X
  159. X@kindex N
  160. X@pindex calc-eval-num
  161. XThe shift-@kbd{N} (@code{calc-eval-num}) command evaluates numerically
  162. Xthe expression at the top of the stack, by temporarily disabling
  163. X@code{calc-symbolic-mode} and executing @kbd{=} (@code{calc-evaluate}).
  164. XGiven a numeric prefix argument, it also
  165. Xsets the floating-point precision to the specified value for the duration
  166. Xof the command.@refill
  167. X
  168. XTo evaluate a formula numerically without expanding the variables it
  169. Xcontains, you can use the key sequence @kbd{m a c c m a} (@code{calc-clean}
  170. Xresimplifies but doesn't evaluate variables).
  171. X
  172. X@node Working Message, , Symbolic Mode, Calculation Modes
  173. X@subsection Working Messages
  174. X
  175. X@cindex Performance
  176. X@cindex Working messages
  177. XSince the Calculator is written entirely in Emacs Lisp, which is not
  178. Xdesigned for heavy numerical work, many operations are quite slow.
  179. XThe Calculator normally displays the message @samp{Working...} in the
  180. Xecho area during any command that may be slow.  In addition, iterative
  181. Xoperations such as square roots and trigonometric functions display the
  182. Xintermediate result at each step.  Both of these types of messages can
  183. Xbe disabled if you find them distracting.
  184. X
  185. X@kindex m w
  186. X@pindex calc-working
  187. XType @kbd{m w} (@code{calc-working}) with a numeric prefix of 0 to
  188. Xdisable all ``working'' messages.  Use a numeric prefix of 1 to enable
  189. Xonly the plain @samp{Working...} message.  Use a numeric prefix of 2 to
  190. Xsee intermediate results as well.  With no numeric prefix this displays
  191. Xthe current mode.@refill
  192. X
  193. X@node Simplification Modes, Display Modes, Calculation Modes, Mode Settings
  194. X@section Simplification Modes
  195. X
  196. XThe current @dfn{simplification mode} controls how numbers and formulas
  197. Xare ``normalized'' when being taken from or pushed onto the stack.
  198. XSome normalizations are unavoidable, such as rounding floating-point
  199. Xresults to the current precision, and reducing fractions to simplest
  200. Xform.  Others, such as simplifying a formula like @samp{a+a} (or @samp{2+3}),
  201. Xare done by default but can be turned off when necessary.
  202. X
  203. XWhen you press a key like @kbd{+} when @samp{2} and @samp{3} are on the
  204. Xstack, Calc pops these numbers, normalizes them, creates the formula
  205. X@samp{2+3}, normalizes it, and pushes the result.  Of course the standard
  206. Xrules for normalizing @samp{2+3} will produce the result @samp{5}.
  207. X
  208. XSimplification mode commands consist of the lower-case @kbd{m} prefix key
  209. Xfollowed by a shifted letter.
  210. X
  211. X@kindex m O
  212. X@pindex calc-no-simplify-mode
  213. XThe @kbd{m O} (@code{calc-no-simplify-mode}) command turns off all optional
  214. Xsimplifications.  These would leave a formula like @samp{2+3} alone.  In
  215. Xfact, nothing except simple numbers are ever affected by normalization
  216. Xin this mode.
  217. X
  218. X@kindex m N
  219. X@pindex calc-num-simplify-mode
  220. XThe @kbd{m N} (@code{calc-num-simplify-mode}) command turns off simplification
  221. Xof any formulas except those for which all arguments are constants.  For
  222. Xexample, @samp{1+2} is simplified to @samp{3}, and @samp{a+(2-2)} is
  223. Xsimplified to @samp{a+0} but no further, since one argument of the sum
  224. Xis not a constant.
  225. X
  226. X@kindex m D
  227. X@pindex calc-default-simplify-mode
  228. XThe @kbd{m D} (@code{calc-default-simplify-mode}) command restores the
  229. Xdefault simplifications for all formulas.  This includes some easy and
  230. Xfast simplifcations such as @samp{a+0} to @samp{a}, and @samp{a + 2 a}
  231. Xto @samp{3 a}.
  232. X
  233. X@kindex m B
  234. X@pindex calc-bin-simplify-mode
  235. XThe @kbd{m B} (@code{calc-bin-simplify-mode}) mode applies the default
  236. Xsimplifications to a result and then, if the result is an integer,
  237. Xuses the @code{calc-clip} command to clip the integer according to
  238. Xthe current binary word size.  @xref{Binary Functions}.  Real numbers
  239. Xare rounded to the nearest integer and then clipped; other kinds of
  240. Xresults (after the default simplifications) are left alone.
  241. X
  242. X@kindex m A
  243. X@pindex calc-alg-simplify-mode
  244. XThe @kbd{m A} (@code{calc-alg-simplify-mode}) mode does algebraic
  245. Xsimplification; it applies all the default simplifications, and also
  246. Xthe more powerful (and slower) simplifications made by @code{calc-simplify}.
  247. X@xref{Algebra}.
  248. X
  249. X@kindex m E
  250. X@pindex calc-ext-simplify-mode
  251. XThe @kbd{m E} (@code{calc-ext-simplify-mode}) mode does ``extended''
  252. Xalgebraic simplification, as by the @code{calc-simplify-extended} command.
  253. X@xref{Algebra}.
  254. X
  255. X@kindex m U
  256. X@pindex calc-units-simplify-mode
  257. XThe @kbd{m U} (@code{calc-units-simplify-mode}) mode does units
  258. Xsimplification; it applies @code{calc-simplify-units}, which in turn
  259. Xis a superset of @code{calc-simplify}.  In this mode, variable names
  260. Xwhich are identifiable as unit names (like @samp{mm} for ``millimeters'')
  261. Xare simplified with their unit definitions in mind.
  262. X
  263. XA common technique is to set the simplification mode down to the lowest
  264. Xamount of simplification you will allow to be applied automatically, then
  265. Xuse manual commands like @code{calc-clean} or @code{calc-simplify} to
  266. Xperform higher types of simplifications on demand.  @xref{Algebraic
  267. XDefinitions}, for another sample use of no-simplification mode.@refill
  268. X
  269. X@node Display Modes, Language Modes, Simplification Modes, Mode Settings
  270. X@section Display Modes
  271. X
  272. XThe commands in this section are two-key sequences beginning with the
  273. X@kbd{d} prefix.  The @kbd{d l} (@code{calc-line-numbering}) and @kbd{d b}
  274. X(@code{calc-line-breaking}) commands are described elsewhere;
  275. X@pxref{Stack Basics} and @pxref{Normal Language Modes}, respectively.
  276. XDisplay formats for vectors and matrices are also covered elsewhere;
  277. X@pxref{Vector and Matrix Formats}.@refill
  278. X
  279. X@menu
  280. X* Radix Modes::
  281. X* Grouping Digits::
  282. X* Float Formats::
  283. X* Complex Formats::
  284. X* Fraction Formats::
  285. X* HMS Formats::
  286. X* Truncating the Stack::
  287. X* Justification::
  288. X@end menu
  289. X
  290. X@node Radix Modes, Grouping Digits, Display Modes, Display Modes
  291. X@subsection Radix Modes
  292. X
  293. X@cindex Radix display
  294. X@cindex Non-decimal integers
  295. X@cindex Decimal and non-decimal integers
  296. XCalc normally displays integers in decimal, or @dfn{radix-10}, notation.
  297. XCalc can actually display in any radix from two (binary) to 36.  When
  298. Xthe radix is above 10, the letters @samp{A} to @samp{Z} are used as digits.
  299. XWhen entering such a number, letter keys are interpreted as potential
  300. Xdigits rather than terminating numeric entry mode.
  301. X
  302. X@kindex d 2
  303. X@kindex d 8
  304. X@kindex d 6
  305. X@kindex d 0
  306. X@cindex Hexadecimal integers
  307. X@cindex Octal integers
  308. XThe key sequences @kbd{d 2}, @kbd{d 8}, @kbd{d 6}, and @kbd{d 0} select
  309. Xbinary, octal, hexadecimal, and decimal as the integer display radix,
  310. Xrespectively.  Numbers can always be entered in any radix, though the
  311. Xcurrent radix is used as a default if you press @kbd{#} without any initial
  312. Xdigits.  A number entered without a @kbd{#} is @emph{always} interpreted
  313. Xas decimal.@refill
  314. X
  315. X@kindex d r
  316. X@pindex calc-radix
  317. XTo set the radix generally, use @kbd{d r} (@code{calc-radix}) and enter
  318. Xan integer from 2 to 36.  You can specify the radix as a numeric prefix
  319. Xargument; otherwise you will be prompted for it.
  320. X
  321. X@kindex d z
  322. X@pindex calc-leading-zeros
  323. X@cindex Leading zeros
  324. XIntegers normally are displayed with however many digits are necessary to
  325. Xrepresent the integer and no more.  The @kbd{d z} (@code{calc-leading-zeros})
  326. Xcommand causes integers to be padded out with leading zeros according to the
  327. Xcurrent binary word size.  (@xref{Binary Functions}, for a discussion of
  328. Xword size.)  If the absolute value of the word size is @samp{w}, all integers
  329. Xare displayed with at least enough digits to represent @samp{(2^w)-1} in the
  330. Xcurrent radix.  (Larger integers will still be displayed in their entirety.)
  331. X
  332. XThe current radix is only used to display integers and fractions.
  333. XFloating-point numbers are always entered and displayed in decimal.
  334. X
  335. X@node Grouping Digits, Float Formats, Radix Modes, Display Modes
  336. X@subsection Grouping Digits
  337. X
  338. X@kindex d g
  339. X@pindex calc-group-digits
  340. X@cindex Grouping digits
  341. X@cindex Digit grouping
  342. XLong numbers can be hard to read if they have too many digits.  For
  343. Xexample, the factorial of 30 is 33 digits long!  Press @kbd{d g}
  344. X(@code{calc-group-digits}) to enable @dfn{grouping} mode, in which digits
  345. Xare displayed in clumps of 3 or 4 (depending on the current radix)
  346. Xseparated by commas.
  347. X
  348. XThe @kbd{d g} command toggles grouping on and off.
  349. XWith a numerix prefix of 0, this command displays the current state of
  350. Xthe grouping flag; with a @kbd{C-u} prefix, it pushes the grouping state
  351. Xonto the stack; with an argument of minus one it disables grouping; with
  352. Xa positive argument @samp{N} it enables grouping on every @samp{N}
  353. Xdigits.  For floating-point numbers, grouping normally occurs only
  354. Xbefore the decimal point.  A negative prefix argument @samp{-N} enables
  355. Xgrouping every @samp{N} digits both before and after the decimal point.@refill
  356. X
  357. X@kindex d ,
  358. X@pindex calc-group-char
  359. XThe @kbd{d ,} (@code{calc-group-char}) command allows you to choose any
  360. Xcharacter as the grouping separator.  The default is the comma character.
  361. XIf you find it difficult to read vectors of large integers grouped with
  362. Xcommas, you may wish to use spaces or some other character instead.
  363. X
  364. XPlease note that grouped numbers will not generally be parsed correctly
  365. Xif re-read in textual form, say by the use of @kbd{C-k} and @kbd{C-y}.
  366. X(@xref{Kill and Yank}, for details on these commands.)
  367. X
  368. X@node Float Formats, Complex Formats, Grouping Digits, Display Modes
  369. X@subsection Float Formats
  370. X
  371. XFloating-point quantities are normally displayed in standard decimal
  372. Xform, with scientific notation used if the exponent is especially high
  373. Xor low.  All significant digits are normally displayed.  The commands
  374. Xin this section allow you to choose among several alternative display
  375. Xformats for floats.
  376. X
  377. X@kindex d n
  378. X@pindex calc-normal-notation
  379. XThe @kbd{d n} (@code{calc-normal-notation}) command selects the normal
  380. Xdisplay format.  All significant figures in a number are displayed.
  381. XWith a positive numeric prefix, numbers are rounded if necessary to
  382. Xthat number of significant digits.  With a negative numerix prefix,
  383. Xthe specified number of significant digits less than the current
  384. Xprecision is used.  (Thus @kbd{C-u -2 d n} displays 10 digits if the
  385. Xcurrent precision is 12.)
  386. X
  387. X@kindex d f
  388. X@pindex calc-fix-notation
  389. XThe @kbd{d f} (@code{calc-fix-notation}) command selects fixed-point
  390. Xnotation.  The numeric argument is the number of digits after the
  391. Xdecimal point, zero or more.  This format will relax into scientific
  392. Xnotation if a nonzero number would otherwise have been rounded all the
  393. Xway to zero.  Specifying a negative number of digits is the same as
  394. Xfor a positive number, except that small nonzero numbers will be rounded
  395. Xto zero rather than switching to scientific notation.
  396. X
  397. X@kindex d s
  398. X@pindex calc-sci-notation
  399. XThe @kbd{d s} (@code{calc-sci-notation}) command selects scientific
  400. Xnotation.  A positive argument sets the number of significant figures
  401. Xdisplayed, of which one will be before and the rest after the decimal
  402. Xpoint.  A negative argument works the same as for @kbd{d n} format.
  403. XThe default is to display all significant digits.
  404. X
  405. X@kindex d e
  406. X@pindex calc-eng-notation
  407. XThe @kbd{d e} (@code{calc-eng-notation}) command selects engineering
  408. Xnotation.  This is similar to scientific notation except that the
  409. Xexponent is rounded down to a multiple of three, with from one to three
  410. Xdigits before the decimal point.  An optional numeric prefix sets the
  411. Xnumber of significant digits to display, as for @kbd{d s}.
  412. X
  413. XIt is important to distinguish between the current @emph{precision} and
  414. Xthe current @emph{display format}.  After the commands @kbd{C-u 10 p}
  415. Xand @kbd{C-u 6 d n} the Calculator computes all results to ten
  416. Xsignificant figures but only displays six.  (In fact, intermediate
  417. Xcalculations are often carried to one or two more significant figures,
  418. Xbut values placed on the stack are always rounded down to ten figures.)
  419. XNumbers are never actually rounded to the display precision for storage,
  420. Xexcept by ``kill'' commands like @kbd{C-k} which operate on the actual
  421. Xdisplayed text in the Calculator buffer.
  422. X
  423. X@kindex d .
  424. X@pindex calc-point-char
  425. XThe @kbd{d .} (@code{calc-point-char}) command controls the character used
  426. Xas a decimal point.  Normally this is a period; users in some countries
  427. Xmay wish to change this to a comma.  Note that this is only a display
  428. Xstyle; on entry, periods must always be used to denote floating-point
  429. Xnumbers, and commas to seperate elements in a list.
  430. X
  431. X@node Complex Formats, Fraction Formats, Float Formats, Display Modes
  432. X@subsection Complex Formats
  433. X
  434. X@kindex d c
  435. X@pindex calc-complex-notation
  436. XThere are three supported notations for complex numbers in rectangular
  437. Xform.  The default is as a pair of real numbers enclosed in parentheses
  438. Xand separated by a comma: @samp{(a,b)}.  The @kbd{d c}
  439. X(@code{calc-complex-notation}) command selects this style.@refill
  440. X
  441. X@kindex d i
  442. X@pindex calc-i-notation
  443. X@kindex d j
  444. X@pindex calc-j-notation
  445. XThe other notations are @kbd{d i} (@code{calc-i-notation}), in which
  446. Xnumbers are displayed in @samp{a+bi} form, and @kbd{d j}
  447. X(@code{calc-j-notation}) which displays the form @samp{a+bj} preferred
  448. Xin some disciplines.@refill
  449. X
  450. X@cindex @code{i} variable
  451. XComplex numbers are normally entered in @samp{(a,b)} format.
  452. XIf you enter @samp{2+3i} as an algebraic formula, it will be stored as
  453. Xthe formula @samp{2 + 3 * i}.  However, if you use @kbd{=} to evaluate
  454. Xthis formula and you have not changed the variable @samp{i}, the @samp{i}
  455. Xwill be interpreted as @samp{(0,1)} and the formula will be simplified
  456. Xto @samp{(2,3)}.  Other commands (like @code{calc-sin}) will @emph{not}
  457. Xinterpret the formula @samp{2 + 3 * i} as a complex number.
  458. X@xref{Variables}, under ``special constants.''@refill
  459. X
  460. X@node Fraction Formats, HMS Formats, Complex Formats, Display Modes
  461. X@subsection Fraction Formats
  462. X
  463. X@kindex d o
  464. X@pindex calc-over-notation
  465. XDisplay of fractional numbers is controlled by the @kbd{d o}
  466. X(@code{calc-over-notation}) command.  By default, a number like
  467. Xeight thirds is displayed in the form @samp{8:3}.  The @kbd{d o} command
  468. Xprompts for a one- or two-character format.  If you give one character,
  469. Xthat character is used as the fraction separator.  Common separators are
  470. X@samp{:} and @samp{/}.  (During input of numbers, the @kbd{:} key must be
  471. Xused regardless of the display format; in particular, the @kbd{/} is used
  472. Xfor RPN-style division, @emph{not} for entering fractions.)
  473. X
  474. XIf you give two characters, fractions use ``integer-plus-fractional-part''
  475. Xnotation.  For example, the format @samp{+/} would display eight thirds
  476. Xas @samp{2+2/3}.  If two colons are present in a number being entered,
  477. Xthe number is interpreted in this form.
  478. X
  479. X@node HMS Formats, Truncating the Stack, Fraction Formats, Display Modes
  480. X@subsection HMS Formats
  481. X
  482. X@kindex d h
  483. X@pindex calc-hms-notation
  484. XThe @kbd{d h} (@code{calc-hms-notation}) command controls the display of
  485. XHMS (hours-minutes-seconds) forms.  It prompts for a string which
  486. Xconsists basically of an ``hours'' marker, optional punctuation, a
  487. X``minutes'' marker, more optional punctuation, and a ``seconds'' marker.
  488. XPunctuation is zero or more spaces, commas, or semicolons.  The hours
  489. Xmarker is one or more non-punctuation characters.  The minutes and
  490. Xseconds markers must be single non-punctuation characters.
  491. X
  492. XThe default HMS format is @samp{@@ ' "}, producing HMS values of the form
  493. X@samp{23@@ 30' 15.75"}.  The format @samp{deg, ms} would display this same
  494. Xvalue as @samp{23deg, 30m15.75s}.  During numeric entry, the @kbd{h} or @kbd{o}
  495. Xkeys are recognized as synonyms for @kbd{@@} regardless of display format.
  496. XThe @kbd{m} and @kbd{s} keys are recognized as synonyms for @kbd{'} and
  497. X@kbd{"}, respectively, but only if an @kbd{@@} (or @kbd{h} or @kbd{o}) has
  498. Xalready been typed; otherwise, they have their usual meanings
  499. X(@kbd{m-} prefix and @code{calc-store}).  Thus, @kbd{5 "}, @kbd{0 @@ 5 "}, and
  500. X@kbd{0 h 5 s} are some of the ways to enter the quantity ``five seconds.''
  501. XThe @kbd{'} key is recognized as ``minutes'' only if @kbd{@@} (or @kbd{h} or
  502. X@kbd{o}) has already been pressed; otherwise it means to switch to algebraic
  503. Xentry.
  504. X
  505. X@node Truncating the Stack, Justification, HMS Formats, Display Modes
  506. X@subsection Truncating the Stack
  507. X
  508. X@kindex d t
  509. X@pindex calc-truncate-stack
  510. X@cindex Truncating the stack
  511. X@cindex Narrowing the stack
  512. XThe @kbd{d t} (@code{calc-truncate-stack}) command moves the @samp{.}@:
  513. Xline that marks the top-of-stack up or down in the Calculator buffer.
  514. XThe number right above that line is considered to the be at the top of
  515. Xthe stack.  Any numbers below that line are ``hidden'' from all stack
  516. Xoperations.  This is similar to the Emacs ``narrowing'' feature, except
  517. Xthat the values below the @samp{.} are @emph{visible}, just temporarily
  518. Xfrozen.  This feature allows you to keep several independent calculations
  519. Xrunning at once in different parts of the stack, or to apply a certain
  520. Xcommand to an element buried deep in the stack.@refill
  521. X
  522. XPressing @kbd{d t} by itself moves the @samp{.} to the line the cursor
  523. Xis on.  Thus, this line and all those below it become hidden.  To un-hide
  524. Xthese lines, move down to the end of the buffer and press @kbd{d t}.
  525. XWith a positive numeric prefix argument @samp{n}, @kbd{d t} hides the
  526. Xbottom @samp{n} values in the buffer.  With a negative argument, it hides
  527. Xall but the top @samp{n} values.  With an argument of zero, it hides zero
  528. Xvalues, i.e., moves the @samp{.} all the way down to the bottom.@refill
  529. X
  530. X@kindex d [
  531. X@pindex calc-truncate-up
  532. X@kindex d ]
  533. X@pindex calc-truncate-down
  534. XThe @kbd{d [} (@code{calc-truncate-up}) and @kbd{d ]}
  535. X(@code{calc-truncate-down}) commands move the @samp{.} up or down one
  536. Xline at a time (or several lines with a prefix argument).@refill
  537. X
  538. X@node Justification, , Truncating the Stack, Display Modes
  539. X@subsection Justification
  540. X
  541. X@kindex d <
  542. X@pindex calc-left-justify
  543. X@kindex d =
  544. X@pindex calc-center-justify
  545. X@kindex d >
  546. X@pindex calc-right-justify
  547. XValues on the stack are normally left-justified in the window.  You can
  548. Xcontrol this arrangement by typing @kbd{d <} (@code{calc-left-justify}),
  549. X@kbd{d >} (@code{calc-right-justify}), or @kbd{d =}
  550. X(@code{calc-center-justify}).  For example, in right-justification mode,
  551. Xstack entries are displayed flush-right against the right edge of the
  552. Xwindow.@refill
  553. X
  554. XIf you change the width of the Calculator window you may have to type
  555. X@kbd{d ~} (@code{calc-refresh}) to re-align right-justified or centered text.
  556. X
  557. XRight-justification is especially useful together with fixed-point
  558. Xnotation (@code{d f}; @code{calc-fix-notation}).  With these modes together,
  559. Xthe decimal points on numbers will always line up.
  560. X
  561. X@node Language Modes, , Display Modes, Mode Settings
  562. X@section Language Modes
  563. X
  564. XThe commands in this section change Calc to use a different notation for
  565. Xentry and display of formulas, corresponding to the conventions of some
  566. Xother common language such as Pascal or @TeX{}.  Objects displayed on the
  567. Xstack or yanked from the Calculator to an editing buffer will be formatted
  568. Xin the current language; objects entered in algebraic entry or yanked from
  569. Xanother buffer will be interpreted according to the current language.
  570. X
  571. XThe current language has no effect on things written to or read from the
  572. Xtrail buffer, nor does it affect numeric entry.  Only algebraic entry is
  573. Xaffected.
  574. X
  575. XFor example, suppose the formula @samp{2*a[1] + atan(a[2])} occurs in a C
  576. Xprogram; elsewhere in the program you need the derivatives of this formula
  577. Xwith respect to @samp{a[1]} and @samp{a[2]}.  First, type @kbd{d C}
  578. Xto switch to C notation.  Now use @code{calc-yank} to grab the formula
  579. Xinto the Calculator, @kbd{a d a[1] @key{RET}} to differentiate with respect
  580. Xto the first variable, and @kbd{y} to yank the formula for the derivative
  581. Xback into your C program.  Press @kbd{U} to undo the differentiation and
  582. Xrepeat with @kbd{a d a[2] @key{RET}} for the other derivative.
  583. X
  584. XWithout being switched into C mode first, Calc would have misinterpreted
  585. Xthe brackets in @samp{a[1]} and @samp{a[2]}, would not have known that
  586. X@code{atan} was equivalent to Calc's built-in @code{arctan} function,
  587. Xand would have written the formula back with notations (like implicit
  588. Xmultiplication) which would not have been legal for a C program.
  589. X
  590. XAs another example, suppose you are maintaining a C program and a @TeX{}
  591. Xdocument, each of which needs a copy of the same formula.  You can grab the
  592. Xformula from the program in C mode, switch to @TeX{} mode, and yank the
  593. Xformula into the document in @TeX{} math-mode format.
  594. X
  595. XLanguage modes are selected by typing the letter @kbd{d} followed by a
  596. Xshifted letter key.
  597. X
  598. X@menu
  599. X* Normal Language Modes::
  600. X* C Fortran Pascal::
  601. X* Tex Language Mode::
  602. X* Mathematica Language Mode::
  603. X@end menu
  604. X
  605. X@node Normal Language Modes, C Fortran Pascal, Language Modes, Language Modes
  606. X@subsection Normal Language Modes
  607. X
  608. X@kindex d N
  609. X@pindex calc-normal-language
  610. XThe @kbd{d N} (@code{calc-normal-language}) command selects the usual
  611. Xnotation for Calc formulas, as described in the rest of this manual.
  612. XMatrices are displayed in a multi-line tabular format, but all other
  613. Xobjects are written in linear form, as they would be typed from the
  614. Xkeyboard.
  615. X
  616. X@kindex d O
  617. X@pindex calc-flat-language
  618. X@cindex Matrix display
  619. XThe @kbd{d O} (@code{calc-flat-language}) command selects a language
  620. Xidentical with the normal one, except that matrices are written in
  621. Xone-line form along with everything else.  In some applications this
  622. Xform may be more suitable for yanking data into other buffers.
  623. X
  624. X@kindex d b
  625. X@pindex calc-line-breaking
  626. X@cindex Line breaking
  627. X@cindex Breaking up long lines
  628. XEven in one-line mode, long formulas or vectors will still be split
  629. Xacross multiple lines if they exceed the width of the Calculator window.
  630. XThe @kbd{d b} (@code{calc-line-breaking}) command turns this line-breaking
  631. Xfeature on and off.  (It works independently of the current language.)
  632. X
  633. X@kindex d B
  634. X@pindex calc-big-language
  635. XThe @kbd{d B} (@code{calc-big-language}) command selects a language
  636. Xwhich uses textual approximations to various mathematical notations,
  637. Xparticularly powers and quotients:
  638. X
  639. X@example
  640. Xa + 1    2
  641. X----- + c
  642. X  b
  643. X@end example
  644. X
  645. X@noindent
  646. Xin place of @samp{(a+1)/b + c^2}.
  647. X
  648. XIn ``big'' format, stack entries often take up several lines.  To aid
  649. Xreadability, stack entries are separated by a blank line in this mode.
  650. XYou may find it useful to expand the Calc window's height using
  651. X@kbd{C-x ^} (@code{enlarge-window}) or to make the Calc window the only
  652. Xone on the screen with @kbd{C-x 1} (@code{delete-other-windows}).
  653. X
  654. X@kindex d U
  655. X@pindex calc-unformatted-language
  656. XThe @kbd{d U} (@code{calc-unformatted-language}) command altogether disables
  657. Xthe use of operator notation in formulas.  In this mode, the formula
  658. Xshown above would be displayed:
  659. X
  660. X@example
  661. Xadd(div(add(a, 1), b), pow(c, 2))
  662. X@end example
  663. X
  664. XThese four modes differ only in display format, not in the format
  665. Xexpected for algebraic entry.  The standard Calc operators work in
  666. Xall four modes, and unformatted notation works in any language mode
  667. X(except that Mathematica mode expects square brackets instead of
  668. Xparentheses.)
  669. X
  670. X@node C Fortran Pascal, Tex Language Mode, Normal Language Modes, Language Modes
  671. X@subsection C, Fortran, and Pascal Modes
  672. X
  673. X@kindex d C
  674. X@pindex calc-c-language
  675. X@cindex C language
  676. XThe @kbd{d C} (@code{calc-c-language}) command selects the conventions
  677. Xof the C language for display and entry of formulas.  This differs from
  678. Xthe normal language mode in a variety of (mostly minor) ways.  In
  679. Xparticular, C language operators and operator precedences are used in
  680. Xplace of Calc's usual ones.  For example, @samp{a^b} means @samp{xor(a,b)}
  681. Xin C mode; a value raised to a power is written as a function call,
  682. X@samp{pow(a,b)}.
  683. X
  684. XIn C mode, vectors and matrices use curly braces instead of brackets.
  685. XOctal and hexadecimal values are written with leading @samp{0} or @samp{0x}
  686. Xrather than using the @samp{#} symbol.  Some operators, such as array
  687. Xsubscripting and assignments, are translated into functions like
  688. X@code{subscr} which the rest of Calc will leave alone.
  689. X
  690. XThe variables @code{var-pi} and @code{var-e} would be displayed @samp{pi}
  691. Xand @samp{e} in normal mode, but in C mode they are displayed as
  692. X@samp{M_PI} and @samp{M_E}, corresponding to the names of constants
  693. Xtypically provided in the @file{<math.h>} header.  Functions whose
  694. Xnames are different in C are translated automatically for entry and
  695. Xdisplay purposes.  For example, entering @samp{asin(x)} will push the
  696. Xformula @samp{arcsin(x)} onto the stack; this formula will be displayed
  697. Xas @samp{asin(x)} as long as C mode is in effect.
  698. X
  699. X@kindex d P
  700. X@pindex calc-pascal-language
  701. X@cindex Pascal language
  702. XThe @kbd{d P} (@code{calc-pascal-language}) command selects Pascal
  703. Xconventions.  Like C, Pascal mode interprets array brackets and uses
  704. Xa different table of operators.  No special provisions are made for
  705. Xnon-decimal numbers, vectors, and so on, since there is no universally
  706. Xaccepted standard way of handling these in Pascal.
  707. X
  708. X@kindex d F
  709. X@pindex calc-fortran-language
  710. X@cindex Fortran language
  711. XThe @kbd{d F} (@code{calc-fortran-language}) command selects Fortran
  712. Xconventions.  Various function names are transformed into Fortran
  713. Xequivalents.  Vectors are written as @samp{/1, 2, 3/}, though they must
  714. Xstill be entered using square brackets.  Since Fortran uses round
  715. Xparentheses for both function calls and array subscripts, Calc treats
  716. Xboth as if they were function calls.
  717. X
  718. XFortran and Pascal modes normally do not adjust the case of letters in
  719. Xformulas.  All built-in Calc names use lower-case letters.  If you use a
  720. Xpositive numeric prefix argument with @kbd{d P} or @kbd{d F}, these
  721. Xmodes will use upper-case letters exclusively for display, and will
  722. Xconvert to lower-case on input.  With a negative prefix, these modes
  723. Xconvert to lower-case for display and input.
  724. X
  725. X@node Tex Language Mode, Mathematica Language Mode, C Fortran Pascal, Language Modes
  726. X@subsection @TeX{} Language Mode
  727. X
  728. X@kindex d T
  729. X@pindex calc-tex-language
  730. X@cindex TeX language
  731. XThe @kbd{d T} (@code{calc-tex-language}) command selects the conventions
  732. Xof ``math mode'' in the @TeX{} typesetting language, by Donald Knuth.
  733. XFormulas are entered
  734. Xand displayed in @TeX{} notation, as in @samp{\sin\left( a \over b \right)}.
  735. XMath formulas are usually enclosed by @samp{$ $} signs in @TeX{}; these
  736. Xshould be omitted when interfacing with Calc.  To Calc, the @samp{$} sign
  737. Xhas the same meaning it always does in algebraic formulas (a reference to
  738. Xan existing entry on the stack).@refill
  739. X
  740. XComplex numbers are displayed as in @samp{3 + 4i}.  Subscripts
  741. X(@samp{subscr(a, i)}, written @samp{a[i]} in C and Pascal modes) are
  742. Xwritten @samp{a_i} in @TeX{} mode.  Fractions and quotients are written
  743. Xusing @code{\over}; binomial coefficients are written with @code{\choose}.
  744. XInterval forms are written with @code{\dots}, and
  745. Xerror forms are written with @code{\pm}.
  746. XAbsolute values are written as in @samp{|x + 1|}, and the floor and
  747. Xceiling functions are written with @code{\lfloor}, @code{\rfloor}, etc.
  748. XThe words @code{\left} and @code{\right} are ignored when reading
  749. Xformulas in @TeX{} mode.@refill
  750. X
  751. XFunction calls are written the usual way, with the function name followed
  752. Xby the arguments in parentheses.  However, functions for which @TeX{} has
  753. Xspecial names (like @code{\sin}) will use curly braces instead of
  754. Xparentheses for very simple arguments.  During input, curly braces and
  755. Xparentheses work equally well for grouping, but when the document is
  756. Xformatted the curly braces will be invisible.  Thus the printed result is
  757. X@samp{sin 2x} but @samp{sin(2 + x)}.
  758. X
  759. XFunction and variable names not treated specially by @TeX{} are simply
  760. Xwritten out as-is, which will cause them to come out in italic letters
  761. Xin the printed document.  If you invoke @kbd{d T} with any numeric
  762. Xprefix argument, names of more than one character will instead be written
  763. X@samp{\hbox@{@var{name}@}}.  The @samp{\hbox@{ @}} notation is ignored
  764. Xduring reading.
  765. X
  766. X@node Mathematica Language Mode, , TeX Language Mode, Language Modes
  767. X@subsection Mathematica Language Mode
  768. X
  769. X@kindex d M
  770. X@pindex calc-mathematica-language
  771. X@cindex Mathematica language
  772. XThe @kbd{d M} (@code{calc-mathematica-language}) command selects the
  773. Xconventions of Mathematica, a powerful and popular mathematical tool
  774. Xfrom Wolfram Research, Inc.  Notable differences in Mathematica mode
  775. Xare that the names of built-in functions are capitalized, and function
  776. Xcalls use square brackets instead of parentheses.  Thus the Calc
  777. Xformula @samp{sin(2 x)} is entered and displayed @samp{Sin[2 x]} in
  778. XMathematica mode.
  779. X
  780. XVectors and matrices use curly braces in Mathematica.  Complex numbers
  781. Xare written @samp{3 + 4 I}.  The standard special constants in Calc are
  782. Xwritten @code{Pi}, @code{E}, and @code{I} in Mathematica mode.
  783. XNon-decimal numbers are written, e.g., @samp{16^^7fff}.  Floating-point
  784. Xnumbers in scientific notation are written @samp{1.23*10^3}.@refill
  785. X
  786. X@node Arithmetic, Scientific Functions, Mode Settings, Top
  787. X@chapter Arithmetic Functions
  788. X
  789. XThis chapter describes the Calc commands for doing simple calculations
  790. Xon numbers, such as addition, absolute value, and square roots.  These
  791. Xcommands work by removing the top one or two values from the stack,
  792. Xperforming the desired operation, and pushing the result back onto the
  793. Xstack.  If the operation cannot be performed, the result pushed is a
  794. Xformula instead of a number, such as @samp{2/0} (because division by zero
  795. Xis illegal) or @samp{sqrt(x)} (because the argument @samp{x} is a formula).
  796. X
  797. X@xref{Prefix Arguments}, for a discussion of the effect of numeric
  798. Xprefix arguments on commands in this chapter which do not otherwise
  799. Xinterpret a prefix argument.
  800. X
  801. X@menu
  802. X* Basic Arithmetic::
  803. X* Integer Truncation::
  804. X* Complex Number Functions::
  805. X* Conversions::
  806. X@end menu
  807. X
  808. X@node Basic Arithmetic, Integer Truncation, Arithmetic, Arithmetic
  809. X@section Basic Arithmetic
  810. X
  811. X@kindex +
  812. X@pindex calc-plus
  813. XThe @kbd{+} (@code{calc-plus}) command adds two numbers.  The numbers may
  814. Xbe any of the standard Calc data types.  The resulting sum is pushed back
  815. Xonto the stack.
  816. X
  817. XIf both arguments of @kbd{+} are vectors or matrices (of matching dimensions),
  818. Xthe result is a vector or matrix sum.  If one argument is a vector and the
  819. Xother a scalar (i.e., a non-vector), the scalar is added to each of the
  820. Xelements of the vector to form a new vector.  If the scalar is not a
  821. Xnumber, the operation is left in symbolic form:  Suppose you added @samp{x}
  822. Xto the vector @samp{[1,2]}.  You may want the result @samp{[1+x,2+x]}, or
  823. Xyou may plan to substitute a 2-vector for @samp{x} in the future.  Since
  824. Xthe Calculator can't tell which interpretation you want, it makes the
  825. Xsafest assumption.  @xref{Reducing and Mapping}, for a way to add @samp{x}
  826. Xto every element of a vector.
  827. X
  828. XIf either argument of @kbd{+} is a complex number, the result will in general
  829. Xbe complex.  If one argument is in rectangular form and the other polar,
  830. Xthe current Polar Mode determines the form of the result.  If Symbolic
  831. XMode is enabled, the sum may be left as a formula if the necessary
  832. Xconversions for polar addition are non-trivial.
  833. X
  834. XIf both arguments of @kbd{+} are HMS forms, the forms are added according to
  835. Xthe usual conventions of hours-minutes-seconds notation.  If one argument
  836. Xis an HMS form and the other is a number, that number is converted from
  837. Xdegrees or radians (depending on the current Angular Mode) to HMS format
  838. Xand then the two HMS forms are added.
  839. X
  840. XIf both arguments of @kbd{+} are error forms, the result is an error form
  841. Xwith an appropriately computed standard deviation.  If one argument is an
  842. Xerror form and the other is a number, the number is taken to have zero error.
  843. XError forms may have symbolic formulas as their mean and/or error parts;
  844. Xadding these will produce a symbolic error form result.  However, adding an
  845. Xerror form to a plain symbolic formula (as in @samp{(a +/- b) + c}) will not
  846. Xwork, for the same reasons just mentioned for vectors.  Instead you must
  847. Xwrite @samp{(a +/- b) + (c +/- 0)}.
  848. X
  849. XIf both arguments of @kbd{+} are modulo forms with equal values of @samp{M},
  850. Xor if one argument is a modulo form and the other a plain number, the
  851. Xresult is a modulo form which represents the sum, modulo @samp{M}, of
  852. Xthe two values.
  853. X
  854. XIf both arguments of @kbd{+} are intervals, the result is an interval
  855. Xwhich describes all possible sums of the possible input values.  If one
  856. Xargument is a plain number, it is treated as the interval @samp{[x .. x]}.
  857. X
  858. X@kindex -
  859. X@pindex calc-minus
  860. XThe @kbd{-} (@code{calc-minus}) command subtracts two values.  The top
  861. Xnumber on the stack is subtracted from the one behind it, so that the
  862. Xcomputation @kbd{5 @key{RET} 2 -} produces 3, not -3.  All options
  863. Xavailable for @kbd{+} are available for @kbd{-} as well.
  864. X
  865. X@kindex *
  866. X@pindex calc-times
  867. XThe @kbd{*} (@code{calc-times}) command multiplies two numbers.  If one
  868. Xargument is a vector and the other a scalar, the scalar is multiplied by
  869. Xthe elements of the vector to produce a new vector.  If both arguments
  870. Xare vectors, the interpretation depends on the dimensions of the
  871. Xvectors:  If both arguments are matrices, a matrix multiplication is
  872. Xdone.  If one argument is a matrix and the other a plain vector, the
  873. Xvector is interpreted as a row vector or column vector, whichever is
  874. Xdimensionally correct.  If both arguments are plain vectors, the result
  875. Xis a single scalar number which is the dot product of the two vectors.
  876. X
  877. XIf one argument of @kbd{*} is an HMS form and the other a number, the
  878. XHMS form is multiplied by that amount.  It is an error to multiply two
  879. XHMS forms together.  Error forms, modulo forms, and intervals can also
  880. Xbe multiplied; see the comments for addition of those forms.  When two
  881. Xerror forms or intervals are multiplied they are considered to be
  882. Xindependent; thus, @samp{[-2 .. 3] * [-2 .. 3]} is @samp{[-6 .. 9]},
  883. Xwhereas @samp{[-2 .. 3] ^ 2} is @samp{[0 .. 9]}.
  884. X
  885. X@kindex /
  886. X@pindex calc-divide
  887. XThe @kbd{/} (@code{calc-divide}) command divides two numbers.  When
  888. Xdividing a scalar @samp{B} by a square matrix @samp{A}, the computation
  889. Xperformed is @samp{B} times the inverse of @samp{A}.  This also occurs
  890. Xif @samp{A} is itself a vector or matrix, in which case the effect is
  891. Xto solve the set of linear equations represented by @samp{B}.  If @samp{A}
  892. Xis a matrix with the same number of rows as @samp{B}, or a plain vector
  893. X(which is interpreted here as a column vector), then the equation
  894. X@samp{A X = B} is solved for the vector or matrix @samp{X}.  Otherwise,
  895. Xif @samp{A} is a non-square matrix with the same number of @emph{columns}
  896. Xas @samp{B}, the equation @samp{X A = B} is solved.  If you wish a vector
  897. X@samp{A} to be interpreted as a row vector to be solved as @samp{X A = B},
  898. Xmake it into a one-row matrix with @kbd{C-u 1 v p} first.  To force a
  899. Xleft-handed solution with a square matrix @samp{A}, transpose @samp{A} and
  900. X@samp{B} before dividing, then transpose the result.
  901. X
  902. XHMS forms can be divided by real numbers or by other HMS forms.  Error
  903. Xforms can be divided in any combination of ways.  Modulo forms where both
  904. Xvalues and the modulo are integers can be divided to get an integer modulo
  905. Xform result.  Intervals can be divided, except that it is not possible to
  906. Xdivide by an interval that encompasses zero or has zero as a limit, since
  907. Xthis would result in an infinite interval.
  908. X
  909. X@kindex ^
  910. X@pindex calc-power
  911. XThe @kbd{^} (@code{calc-power}) command raises a number to a power.  If
  912. Xthe power is an integer, an exact result is computed using repeated
  913. Xmultiplications.  For non-integer powers, Calc uses logarithms and
  914. Xexponentials.  Square matrices can be raised to integer powers.  If either
  915. Xargument is an error (or interval or modulo) form, the result is also an
  916. Xerror (or interval or modulo) form.
  917. X
  918. X@kindex %
  919. X@pindex calc-mod
  920. XThe @kbd{%} (@code{calc-mod}) command performs a ``modulo'' (or ``remainder'')
  921. Xoperation.  Mathematically, @samp{a%b = a - floor(a/b)*b}, and is defined
  922. Xfor all real numbers @samp{a} and @samp{b} (except @samp{b}=0).  For
  923. Xpositive @samp{b}, the result will always be between 0 (inclusive) and
  924. X@samp{b} (exclusive).  Modulo does not work for HMS forms and error forms.
  925. Xif @samp{a} is a modulo form, its modulo is changed to @samp{b}, which
  926. Xmust be positive real number.
  927. X
  928. X@kindex \
  929. X@pindex calc-idiv
  930. X@tindex idiv
  931. XThe @kbd{\} (@code{calc-idiv}) command divides two numbers on the stack
  932. Xto produce an integer result.  It is equivalent to dividing with
  933. X@key{/}, then rounding down with @kbd{F} (@code{calc-floor}), only a bit
  934. Xmore convenient and efficient.
  935. X
  936. X@kindex :
  937. X@pindex calc-fdiv
  938. X@tindex fdiv
  939. XThe @kbd{:} (@code{calc-fdiv}) command [@code{fdiv} function in a formula]
  940. Xdivides the two integers on the top of the stack to produce a fractional
  941. Xresult.  This is a convenient shorthand to enabling Fraction Mode (with
  942. X@code{calc-frac-mode}) temporarily and using @samp{/}.  Note that during
  943. Xnumeric entry the @kbd{:} key is interpreted as a fraction separator, so
  944. Xto divide 8 by 6 you would have to type @kbd{8 @key{RET} 6 @key{RET} :}.
  945. X(Of course, in this case, it would be much easier simply to enter the
  946. Xfraction directly as @kbd{8:6 @key{RET}}!)
  947. X
  948. X@kindex n
  949. X@pindex calc-change-sign
  950. XThe @kbd{n} (@code{calc-change-sign}) command negates the number on the top
  951. Xof the stack.  It works on numbers, vectors and matrices, HMS forms, error
  952. Xforms, and modulo forms.
  953. X
  954. X@kindex A
  955. X@pindex calc-abs
  956. X@tindex abs
  957. XThe @kbd{A} (@code{calc-abs}) [@code{abs}] command computes the absolute
  958. Xvalue of a number.  The result of @code{abs} is always a nonnegative
  959. Xreal number:  With a complex argument, it computes the complex magnitude.
  960. XWith a vector or matrix argument, it computes the Frobenius norm, i.e.,
  961. Xthe square root of the sum of the squares of the absolute values of the
  962. Xelements.  The absolute value of an error form is defined by replacing
  963. Xthe mean part with its absolute value and leaving the error part the same.
  964. XThe absolute value of a modulo form is undefined.
  965. X
  966. X@pindex calc-abssqr
  967. X@tindex abssqr
  968. XThe @code{calc-abssqr} [@code{abssqr}] command computes the absolute
  969. Xvalue squared of a number, vector or matrix, or error form.
  970. X
  971. X@pindex calc-sign
  972. X@tindex sign
  973. XThe @code{sign} algebraic function returns 1 if its argument is positive,
  974. X-1 if its argument is negative, or 0 if its argument is zero.
  975. X
  976. X@kindex &
  977. X@pindex calc-inv
  978. X@tindex inv
  979. X@cindex Reciprocal
  980. XThe @kbd{&} (@code{calc-inv}) [@code{inv}] command computes the
  981. Xreciprocal of a number.  It is also available as the @kbd{V I}
  982. Xkey sequence, where it would normally be used to invert a matrix.
  983. X
  984. X@kindex Q
  985. X@pindex calc-sqrt
  986. X@tindex sqrt
  987. XThe @kbd{Q} (@code{calc-sqrt}) [@code{sqrt}] command computes the square
  988. Xroot of a number.  For a negative real argument, the result will be a
  989. Xcomplex number whose form is determined by the current Polar Mode.
  990. X
  991. X@pindex calc-hypot
  992. X@tindex hypot
  993. XThe @code{calc-hypot} [@code{hypot}] command computes the square root of
  994. Xthe sum of the squares of two numbers.  That is, @samp{hypot(a,b)} is the
  995. Xlength of the hypotenuse of a right triangle with sides @samp{a} and @samp{b}.
  996. X
  997. X@pindex calc-min
  998. X@tindex min
  999. X@pindex calc-max
  1000. X@tindex max
  1001. XThe @code{calc-min} [@code{min}] and @code{calc-max} [@code{max}] commands
  1002. Xtake the minimum or maximum of two real numbers, respectively.  These
  1003. Xcommands also work on HMS forms.  (In algebraic expressions, these functions
  1004. Xtake any number of arguments and return the maximum or minimum among all
  1005. Xthe arguments.)@refill
  1006. X
  1007. X@node Integer Truncation, Complex Number Functions, Basic Arithmetic, Arithmetic
  1008. X@section Integer Truncation
  1009. X
  1010. XThere are four commands for truncating a real number to an integer,
  1011. Xdiffering mainly in their treatment of negative numbers.  All of these
  1012. Xcommands have the property that if the argument is an integer, the result
  1013. Xis the same integer.  An integer-valued floating-point argument is converted
  1014. Xto integer form.
  1015. X
  1016. XIf you press @kbd{H} (@code{calc-hyperbolic}) first, the result will be
  1017. Xexpressed as an integer-valued floating-point number.
  1018. X
  1019. X@cindex Integer part of a number
  1020. X@kindex F
  1021. X@kindex H F
  1022. X@pindex calc-floor
  1023. X@tindex floor
  1024. X@tindex ffloor
  1025. XThe @kbd{F} (@code{calc-floor}) [@code{floor} or @code{ffloor}] command
  1026. Xtruncates a real number to the next lower integer, i.e., toward minus
  1027. Xinfinity.  Thus @kbd{3.6 F} produces 3, but @kbd{_3.6 F} produces
  1028. X-4.@refill
  1029. X
  1030. X@kindex I F
  1031. X@kindex H I F
  1032. X@pindex calc-ceiling
  1033. X@tindex ceil
  1034. X@tindex fceil
  1035. XThe @kbd{I F} (@code{calc-ceiling}) [@code{ceil} or @code{fceil}]
  1036. Xcommand truncates toward positive infinity.  Thus @kbd{3.6 I F} produces
  1037. X4, and @kbd{_3.6 I F} produces -3.@refill
  1038. X
  1039. X@kindex R
  1040. X@kindex H R
  1041. X@pindex calc-round
  1042. X@tindex round
  1043. X@tindex fround
  1044. XThe @kbd{R} (@code{calc-round}) [@code{round} or @code{fround}] command
  1045. Xrounds to the nearest integer.  When the fractional part is .5 exactly,
  1046. Xthis command rounds away from zero.  (All other rounding in the
  1047. XCalculator uses this convention as well.)  Thus @kbd{3.5 R} produces 4
  1048. Xbut @kbd{3.4 R} produces 3; @kbd{_3.5 R} produces -4.@refill
  1049. X
  1050. X@kindex I R
  1051. X@kindex H I R
  1052. X@pindex calc-trunc
  1053. X@tindex trunc
  1054. X@tindex ftrunc
  1055. XThe @kbd{I R} (@code{calc-trunc}) [@code{trunc} or @code{ftrunc}]
  1056. Xcommand truncates toward zero.  In other words, it ``chops off''
  1057. Xeverything after the decimal point.  Thus @kbd{3.6 I R} produces 3 and
  1058. X@kbd{_3.6 I R} produces -3.@refill
  1059. X
  1060. XThese functions may not be applied meaningfully to error forms, but they
  1061. Xdo work for intervals.  As a convenience, applying @code{floor} to a
  1062. Xmodulo form floors the value part of the form.
  1063. X
  1064. X@cindex Fractional part of a number
  1065. XTo compute the fractional part of a number (i.e., the amount which, when
  1066. Xadded to @samp{floor(N)}, will produce @samp{N}) just take @samp{N} modulo 1
  1067. Xusing the @code{%} command.@refill
  1068. X
  1069. X@node Complex Number Functions, Conversions, Integer Truncation, Arithmetic
  1070. X@section Complex Number Functions
  1071. X
  1072. X@kindex J
  1073. X@pindex calc-conj
  1074. X@tindex conj
  1075. XThe @kbd{J} (@code{calc-conj}) [@code{conj}] command computes the
  1076. Xcomplex conjugate of a number.  For complex number @samp{a+bi}, the
  1077. Xcomplex conjugate is @samp{a-bi}.  If the argument is a real number,
  1078. Xthis command leaves it the same.  If the argument is a vector or matrix,
  1079. Xthis command replaces each element by its complex conjugate.
  1080. X
  1081. X@kindex G
  1082. X@pindex calc-argument
  1083. X@tindex arg
  1084. XThe @kbd{G} (@code{calc-argument}) [@code{arg}] command computes the
  1085. X``argument'' or polar angle of a complex number.  For a number in polar
  1086. Xnotation, this is simply the second component of the pair @samp{(r,theta)}.
  1087. XThe result is expressed according to the current angular mode and will
  1088. Xbe in the range -180 degrees (exclusive) to +180 degrees (inclusive),
  1089. Xor the equivalent range in radians.@refill
  1090. X
  1091. X@pindex calc-imaginary
  1092. XThe @code{calc-imaginary} command multiplies the number on the
  1093. Xtop of the stack by the imaginary number @samp{i = (0,1)}.
  1094. X
  1095. X@pindex calc-re
  1096. X@tindex re
  1097. XThe @code{calc-re} [@code{re}] command replaces a complex number by
  1098. Xits real part.  This command has no effect on real numbers.  (As an
  1099. Xadded convenience, @code{re} applied to an error or modulo form extracts
  1100. Xthe value part.)@refill
  1101. X
  1102. X@pindex calc-im
  1103. X@tindex im
  1104. XThe @code{calc-im} [@code{im}] command replaces a complex number by its
  1105. Ximaginary part; real numbers are converted to zero.  With a vector or
  1106. Xmatrix argument, these functions operate element-wise.@refill
  1107. X
  1108. X@kindex v p (complex)
  1109. X@pindex calc-pack
  1110. XThe @kbd{v p} (@code{calc-pack}) command takes the top two numbers on the
  1111. Xthe stack and packs them into a complex number according to the current
  1112. XPolar mode.  With a prefix argument of -1, it always produces a rectangular
  1113. Xcomplex number; with an argument of -2, it produces a polar complex number.
  1114. X(Also, @xref{Building Vectors}.)
  1115. X
  1116. X@kindex v u (complex)
  1117. X@pindex calc-unpack
  1118. XThe @kbd{v u} (@code{calc-unpack}) command takes the complex number
  1119. X(or other composite object) on the top of the stack and unpacks it
  1120. Xinto its separate components.
  1121. X
  1122. X@node Conversions, , Complex Number Functions, Arithmetic
  1123. X@section Conversions
  1124. X
  1125. XThe commands described in this section are two-key sequences beginning with
  1126. Xthe letter @kbd{c}.
  1127. X
  1128. X@kindex c f
  1129. X@pindex calc-float
  1130. X@tindex float
  1131. XThe @kbd{c f} (@code{calc-float}) [@code{float}] command converts the
  1132. Xnumber on the top of the stack to floating-point form.  For example,
  1133. X@samp{23} is converted to @samp{23.0}, @samp{3:2} is converted to
  1134. X@samp{1.5}, and @samp{2.3} is left the same.  If the value is a composite
  1135. Xobject such as a complex number or vector, each of the components is
  1136. Xconverted to floating-point.  Note that depending on the current
  1137. Xfloating-point precision, conversion to floating-point format may lose
  1138. Xinformation.@refill
  1139. X
  1140. X@kindex c F
  1141. X@pindex calc-fraction
  1142. X@tindex frac
  1143. XThe @kbd{c F} (@code{calc-fraction}) [@code{frac}] command converts a
  1144. Xfloating-point number into a fractional approximation.  By default, it
  1145. Xproduces a fraction whose decimal representation is the same as the
  1146. Xinput number, to within the current precision.  You can also give a
  1147. Xnumeric prefix argument to specify a tolerance, either directly, or,
  1148. Xif the prefix argument is zero, by using the number on top of the stack
  1149. Xas the tolerance.  If the tolerance is a positive integer, the fraction
  1150. Xis correct to within that many significant figures.  If the tolerance is
  1151. Xa non-positive integer, it specifies how many digits fewer than the current
  1152. Xprecision to use.  If the tolerance is a floating-point number, the
  1153. Xfraction is correct to within that absolute amount.
  1154. X
  1155. X@kindex c d
  1156. X@pindex calc-to-degrees
  1157. X@tindex deg
  1158. XThe @kbd{c d} (@code{calc-to-degrees}) [@code{deg}] command converts a
  1159. Xnumber into degrees form.  The value on the top of the stack may be an
  1160. XHMS form (interpreted as degrees-minutes-seconds), or a real number which
  1161. Xwill be interpreted in radians regardless of the current angular mode.@refill
  1162. X
  1163. X@kindex c r
  1164. X@pindex calc-to-radians
  1165. X@tindex rad
  1166. XThe @kbd{c r} (@code{calc-to-radians}) [@code{rad}] command converts an
  1167. XHMS form or angle in degrees into an angle in radians.
  1168. X
  1169. X@kindex c h
  1170. X@pindex calc-to-hms
  1171. X@tindex hms
  1172. XThe @kbd{c h} (@code{calc-to-hms}) [@code{hms}] command converts a real
  1173. Xnumber, interpreted according to the current angular mode, to an HMS
  1174. Xform describing the same angle.
  1175. X
  1176. X@pindex calc-from-hms
  1177. XThe @code{calc-from-hms} command converts the HMS form on the top of the
  1178. Xstack into a real number according to the current angular mode.
  1179. X
  1180. X@kindex c p
  1181. X@pindex calc-polar
  1182. X@tindex polar
  1183. X@tindex rect
  1184. XThe @kbd{c p} (@code{calc-polar}) command converts the complex number on
  1185. Xthe top of the stack from polar to rectangular form, or from rectangular
  1186. Xto polar form, whichever is appropriate.  Real numbers are left the same.
  1187. XThis command is equivalent to the @code{rect} or @code{polar}
  1188. Xfunctions in algebraic formulas, depending on the direction of
  1189. Xconversion.@refill
  1190. X
  1191. X@kindex c c
  1192. X@pindex calc-clean
  1193. X@tindex clean
  1194. XThe @kbd{c c} (@code{calc-clean}) [@code{clean}] command ``cleans'' the
  1195. Xnumber on the top of the stack.  Floating point numbers are re-rounded
  1196. Xaccording to the current precision.  Polar numbers whose angular components
  1197. Xhave strayed from the -180 to +180 degree range are normalized.  (Note that
  1198. Xresults will be undesirable if the current angular mode is different from
  1199. Xthe one under which the number was produced!)  Integers and fractions are
  1200. Xgenerally unaffected by this operation.@refill
  1201. X
  1202. XIf the simplification mode is set below the default level, it is raised
  1203. Xto the default level for the purposes of this command.  Thus, you can
  1204. Xuse @kbd{c c} to apply the default simplifications manually when their
  1205. Xautomatic application is disabled.  @xref{Simplification Modes}.
  1206. X
  1207. X@cindex Roundoff errors, correcting
  1208. XA numeric prefix argument to @kbd{c c} sets the floating-point precision
  1209. Xto that value for the duration of the command.  A positive prefix (of at
  1210. Xleast 3) sets the precision to the specified value; a negative prefix
  1211. Xdecreases the precision by the specified amount.
  1212. X
  1213. X@kindex c 1
  1214. X@kindex c 2
  1215. X@kindex c 3
  1216. XThe keystroke sequences @kbd{c 1}, @kbd{c 2} and @kbd{c 3} are equivalent
  1217. Xto @kbd{c c} with the corresponding negative prefix argument.  If roundoff
  1218. Xerrors have changed 2.0 into 1.999999, typing @kbd{c 1} to clip off one
  1219. Xdecimal place often conveniently does the trick.
  1220. X
  1221. X@node Scientific Functions, Binary Functions, Arithmetic, Top
  1222. X@chapter Scientific Functions
  1223. X
  1224. XThe functions described here perform trigonometric and other transcendental
  1225. Xcalculations.  They generally produce floating-point answers correct to the
  1226. Xfull current precision.  The @kbd{H} (Hyperbolic) and @kbd{I} (Inverse)
  1227. Xflag keys must be used to get some of these functions from the keyboard.
  1228. X
  1229. X@kindex P
  1230. X@pindex calc-pi
  1231. X@cindex @code{pi} variable
  1232. X@kindex H P
  1233. X@cindex @code{e} variable
  1234. XOne miscellanous command is shift-@kbd{P} (@code{calc-pi}), which pushes
  1235. Xthe value of @samp{pi} (at the current precision) onto the stack.  With the
  1236. XHyperbolic flag, it pushes the value @samp{e}, the base of natural logarithms.
  1237. XIn Symbolic mode, these commands push the actual variables @samp{pi} and
  1238. X@samp{e} instead of their values; @pxref{Symbolic Mode}.
  1239. X
  1240. XThe @kbd{Q} (@code{calc-sqrt}) [@code{sqrt}] function is described elsewhere;
  1241. X@pxref{Basic Arithmetic}.  With the Inverse flag [@code{sqr}], this command
  1242. Xcomputes the square of the argument.
  1243. X
  1244. X@xref{Prefix Arguments}, for a discussion of the effect of numeric
  1245. Xprefix arguments on commands in this chapter which do not otherwise
  1246. Xinterpret a prefix argument.
  1247. X
  1248. X@menu
  1249. X* Logarithmic Functions::
  1250. X* Trigonometric and Hyperbolic Functions::
  1251. X* Branch Cuts::
  1252. X* Random Numbers::
  1253. X* Combinatorial Functions::
  1254. X@end menu
  1255. X
  1256. X@node Logarithmic Functions, Trigonometric and Hyperbolic Functions, Scientific Functions, Scientific Functions
  1257. X@section Logarithmic Functions
  1258. X
  1259. X@kindex L
  1260. X@kindex I E
  1261. X@pindex calc-ln
  1262. X@tindex ln
  1263. XThe shift-@kbd{L} (@code{calc-ln}) [@code{ln}] command computes the natural
  1264. Xlogarithm of the real or complex number on the top of the stack.  With
  1265. Xthe Inverse flag it computes the exponential function instead.  With
  1266. Xthe Hyperbolic flag it computes the common (base-10) logarithm.  With
  1267. Xboth flags, it computes 10 to a given power.
  1268. X
  1269. X@kindex E
  1270. X@kindex I L
  1271. X@pindex calc-exp
  1272. X@tindex exp
  1273. XThe shift-@kbd{E} (@code{calc-exp}) [@code{exp}] command computes the
  1274. Xexponential, i.e., @samp{e} raised to the power of the number on the stack.
  1275. XThe meanings of the Inverse and Hyperbolic flags follow from those for
  1276. Xthe @code{calc-ln} command.
  1277. X
  1278. X@kindex H L
  1279. X@kindex H I L
  1280. X@kindex H E
  1281. X@kindex H I E
  1282. X@pindex calc-log10
  1283. X@tindex log10
  1284. X@tindex pow10
  1285. XThe @kbd{H L} (@code{calc-log10}) [@code{log10}] command computes the common
  1286. X(base-10) logarithm of a number.  The meanings of the Inverse [@code{pow10}]
  1287. Xand Hyperbolic flags follow from those for the @code{calc-ln} command.  Note
  1288. Xthat the common logarithm of a complex number is computed by taking the
  1289. Xnatural logarithm and dividing by @samp{ln(10)}.
  1290. X
  1291. X@kindex B
  1292. X@pindex calc-log
  1293. X@tindex log
  1294. X@tindex ilog
  1295. XThe @kbd{B} (@code{calc-log}) [@code{log}] command computes a logarithm
  1296. Xto any base.  For example, @kbd{1024 @key{RET} 2 B} produces 10, since
  1297. X@samp{2^10 = 1024}.  With the Inverse flag [@code{ilog}], this is similar
  1298. Xto @kbd{^} except that the order of the arguments is reversed.
  1299. X
  1300. X@pindex calc-expm1
  1301. X@tindex expm1
  1302. XThe @code{calc-expm1} [@code{expm1}] command computes @samp{exp(x)-1}, but
  1303. Xusing an algorithm that produces a more accurate answer when the result
  1304. Xis close to zero, i.e., when @samp{exp(x)} is close to one.
  1305. X
  1306. X@pindex calc-lnp1
  1307. X@tindex lnp1
  1308. XThe @code{calc-lnp1} [@code{lnp1}] command computes @samp{ln(x+1)},
  1309. Xproducing a more accurate answer when @samp{x} is close to zero.
  1310. X
  1311. X@node Trigonometric and Hyperbolic Functions, Branch Cuts, Logarithmic Functions, Scientific Functions
  1312. X@section Trigonometric and Hyperbolic Functions
  1313. X
  1314. X@kindex S
  1315. X@pindex calc-sin
  1316. X@tindex sin
  1317. XThe shift-@kbd{S} (@code{calc-sin}) [@code{sin}] command computes the sine
  1318. SHAR_EOF
  1319. echo "End of part 15"
  1320. echo "File calc.texinfo is continued in part 16"
  1321. echo "16" > s2_seq_.tmp
  1322. exit 0
  1323.