Calculator Program and ?CALC Command

The ?CALC CANDE command provides you with a small "desk calculator" when
working at a timesharing terminal. You type in an arithmetic expression,
and it returns the value of that expression. For example: ?CALC 2+2.
SYSTEM/CALC provides you with a program to make these calculations
and assign them to variables.

Numbers:

The calculator works with both base 10 and base 16 numbers. Base 10
numbers are formed in much the same way as FORTRAN constants. Base 16
numbers are preceded by a pound sign (#) and may have no fractional or
exponent part.
Examples of valid numbers: 12 -34 Integers 0.3 3.45 -3.2 Decimal numbers 12E4 3.47E+05 0.47E-2 Exponent notation #C #1FA5 -#3A7 Hexadecimal numbers Arithmetic operations: Operations are performed from left to right on a priority basis. Parentheses may be used freely to force operations to be done in a specific order. Thus, 3+5*2 gives 13, since multiplication is performed before addition, but (3+5)*2 gives 16 since parentheses force the addition to be done first. Available operations, in priority order (first to last) are: Operation Priority Meaning ** 4 Exponentiation (associates right to left) * 3 Multiplication / 3 Division MOD 3 Remainder upon integer division; thus 5 MOD 3 gives 2 DIV 3 Integer division; thus 50 DIV 7 gives 7 + 2 Addition - 2 Subtraction = 1 Assign to variables (associates right to left) Two special operators are provided for use with trigonometric functions; DEG and RAD. DEG multiplies the number preceding it by PI and divides by 180.0 (convert from degrees to radians); RAD multiplies the number pre- ceding it by 180.0 and divides by PI (convert from radians to degrees). DEG is probably more useful, since trigonometric functions expect their arguments to be in radians. Thus, to take the sine of 45 degrees we would type: ?CALC SIN(45 DEG) Functions: Last, but not least, the calculator comes with the following array of functions: FUNCTION MEANING ABS(X) absolute value of X ACOS(X) arccosine of X (-10) LOG(X) logarithm to the base 10 of X (X>0) MAX(X,Y,...Z) maximum of X, Y,...Z MIN(X,Y,...Z) minimum of X, Y,...Z NABS(X) negative absolute value of X ONES(X) number of nonzero bits in X PART(X,Y,Z) takes Z bits from X starting at position Y same as ALGOL X.[Y:Z] SIGN(X) returns -1 if X is less than zero 0 if X is equal to zero 1 if X is greater than zero SIN(X) sine of X SINH(X) hyperbolic sine of X SQRT(X) square root of X (X>=0) TAN(X) tangent of X TANH(X) hyperbolic tangent of X TRUNC(X) truncates fractional portion of X Note: 1) All trigonometric functions work with radians. Thus SIN(45) and ACOS(0.5) mean "sine of 45 radians" and "value n radians of the arccosine of 0.5". To use degree notation, you need SIN(45 DEG) and ACOS(0.5)RAD 2) You must give at least two values to the MAX and MIN functions. 3) The functions DEC, EBCDIC, and HEX do not alter their arguments; only the way in which they will be printed. Thus, ?CALC DEC(#C1) prints 193 ?CALC EBCDIC(#C1) prints "A" ?CALC HEX(193) prints #0000000000C1 General comments: Blanks may not appear within a number except around the "E" in exponent notation. Thus, 12.0 E +4 means 12.0E+4 or 120000 120. 357 means two numbers; 120.0 and 357 Functions may be nested ten deep. Parentheses may be nested twenty deep. Thus, the following are legal: (((((3.5 + 0.5))))) SQRT(ABS(MIN(SIN(.35),COS(TAN(.4))))) If you make an error in your expression (such as a missing parenthesis, two numbers in a row, etc.) you will be given an appropriate error message. -40 60 The range of valid numbers is from 10 to 10 . *The following are available only with the utility program, SYSTEM/CALC: 1. Variables: The calculator provides you with 26 variables, cleverly named A through Z. Their original value is 0.0 when you enter the program. You may reset them all to zero at any time by typing CLEAR when the program prompts you. 2. Constants automatically recognized: PI 3.141592653589 EE 2.718281828459 (note that we use two E's since the single E is a variable name) RNF #FFFFFFFFFFFF (a value of all bits on) AVGDRO 6.025E23 (Avogadro's number) PLANCK 6.624E-27 (Planck's constant in erg-seconds) Running the program: To access the program from CANDE, type: RUN $SYSTEM/CALC


Copyright 2003© Integrity Services, Inc. All rights reserved