.NA "CALC - a screen-oriented calculator program" "R.D Eager" .HD December 1983 DOC/EMAS/K2.5/45 .KE "CALCULATOR" .S1 Introduction .PG This document describes a program which provides simple on-line calculator facilities. Unlike its predecessor (the KDF9 program) it supports both real and integer arithmetic. .PG The program maintains a display of the current state of a calculation, and is thus unsuitable for use on 'dumb' terminals (those without cursor control capabilities). .S1 "Access" .PG Before the program is used for the first time, its object file must be inserted into a directory in the user's search list. The easiest way to do this is usually to issue the command: .sp .CP INSERT(PUBLIC.CALC) .EC .sp This need only be done once. .S1 "Using CALC" .PG Calculations are done in Reverse Polish, so no brackets are needed. For example: .sp .CP instead of 3+4 you would type 3 4 + .EC .sp This would place the values 3 and 4 onto the CALC .BD stack, and then the addition would be performed on the top two items on the stack. All operations take their operands from the top of the stack, and leave their results there as well. A more complex example, which would normally involve the use of brackets, is: .sp .CP instead of (6+7*(8+9)) you would type 6 7 + 8 9 + * .EC .PG Operators and operands must be separated by a space, a comma or a semi-colon. Numbers may be typed in several forms: .sp .CP 3 (simple integer) 1.78 (real number) 1.4@16 (real number as mantissa and exponent) 1.4E16 (same as 1.4@16) Xffc (hexadecimal number) PI 3.14159... E 2.71828... .EC .PG Available operators include: .sp .in +5 .LB 10 .LP "+" Addition. .sp .LP "-" Subtraction. .sp .LP "*" Multiplication. .sp .LP "/" Division (integer division with truncation of the result only if both operands are integers). .sp .LP "**" Exponentiation (both operands treated as real numbers). .sp .LP "SQRT" Square root. .sp .LP "DUP" Duplicate the item on the top of the stack. .sp .LP "NEG" Negate the item on the top of the stack. .sp .LP "POP" Pop (remove) the item on the top of the stack. .sp .LP "REV" Reverse the positions of the top two items on the stack. .sp .LP "SIN" Trigonometric sine; the argument should be in radians. .sp .LP "COS" Trigonometric cosine; the argument should be in radians. .sp .LP "TAN" Trigonometric tangent; the argument should be in radians. .sp .LP "SINH" Hyperbolic sine. .sp .LP "COSH" Hyperbolic cosine. .sp .LP "TANH" Hyperbolic tangent. .sp .LP "EXP" 'e' (2.71828...) raised to the power of the item on the top of the stack. .sp .LP "LOG" Logarithm (to the base 'e') of the item on the top of the stack. .sp .LP "ARCSIN" The angle whose sine is the item on the top of the stack. The result is in radians, and is always in the range .BD -pi/2 to .BD +pi/2. .sp .LP "ARCCOS" The angle whose cosine is the item on the top of the stack. The result is in radians, and is always in the range .BD 0 to .BD +pi. .sp .LP "ARCTAN" If .BD x is the item on the top of the stack, and .BD y is the item immediately 'below' it, then this operator yields the value, in radians, of the angle whose tangent is .BD y/x. This value lies in the range .BD -pi to .BD +pi, and is in the first or fourth quadrant if .BD x > 0, and in the second or third quadrant if .BD x < 0. .sp .LP "RADIUS" If .BD x and .BD y are the top two items on the stack, this operator yields the values of the radius of a circle whose equation is of the form .BD "x\u2\d\ +y\u2\d\ =\ r\u2\d" (where .BD r is the radius). .sp .LP "<<" Logical shift to the left. .sp .LP ">>" Logical shift to the right. .sp .LP "&" Logical (bitwise) .BD and. .sp .LP "!" Logical (bitwise) .BD or. .sp .LP "!!" Logical (bitwise) .BD "exclusive or." .sp .LP "CLEAR" Clear the stack completely. .sp .LP "HELP or ?" Display a screenful of help information. .sp .LP "QUIT or Q" Exit from CALC. .LE .in -5 .S1 "Error messages" .PG All error messages are self explanatory. .S1 "Acknowledgement" .PG CALC is based on a program supplied by Tony Gibbons of Edinburgh Regional Computing Centre.