Mathematic Utilities
Mathematic Utilities
The mathematic utilities are:
%EXP: Raises one number to the power of another number.
%SQROOT: Calculates the square root of a number.
The mathematic utilities can be invoked as extrinsic functions.
The “%” sign has been removed from the topic headings below, intentionally.
%EXP
The %EXP utility raises one number provided to the power of another number provided. While this utility provides an interactive interface for exponential calculations, most production code would perform inline calculation with the “**” operator. The routine has entry points for interactive or non-interactive use.
If the number provided is negative, and the power is a fraction whose absolute value is less than 1, the result of the operation is defined as an empty string.
Utility Labels
INT: Calculates a number to the power of another number interactively.
FUNC(i,j): Invokes %EXP as an extrinsic function returning the first argument raised to the power of the second argument.
Prompts
Power: Requests an exponent or power.
Number: Requests a base number to raise by the power.
Input Variables
%I: As input, contains number to be raised to a power.
%J: Contains exponential power by which to raise %I.
Output Variables
%I: As output, contains the result of the exponential calculation.
Examples of %EXP
Example:
GTM>DO INT^%EXP
Power: 3
Number: 12
12 raised to 3 is 1728This example invokes %EXP in interactive mode using INT^%EXP. %EXP prompts for an exponent (power) and a base number.
Example:
GTM>SET %I=2,%J=9
GTM>DO ^%EXP
GTM>ZWRITE
%I=512
%J=9This example sets the read-write variable %I to 2, variable %J to 9, and invokes %EXP to calculate the result. ZWRITE displays the contents of the variables. %I contains the result.
Example:
GTM>WRITE $$FUNC^%EXP(2,9)
512This example invokes %EXP as an extrinsic function with the label FUNC.
%SQROOT
The %SQROOT utility calculates the square root of a number provided. While this utility provides an interactive interface for taking square roots, most production code would perform inline calculation by raising a number to the .5 power (n**.5). The routine has entry points for interactive or non-interactive use.
Utility Labels
INT: Calculates the square root of a number interactively.
FUNC(s): Invokes %SQROOT as an extrinsic function returning the square root of the argument.
Prompts
The square root of: Requests a number.
Input Variables
%X: Contains the number for which to calculate the square root.
Output Variables
%Y: Contains the square root of %X.
Examples of %SQROOT
Example:
GTM>SET %X=81
GTM>DO ^%SQROOT
GTM>ZWRITE
%X=81
%Y=9This example sets the variable %X to 81 and invokes %SQROOT to calculate the square root non-interactively. ZWRITE displays the contents of the variables.
Example:
GTM>DO INT^%SQROOT
The square root of: 81 is: 9
The square root of: <RETURN>
GTM>This example invokes INT^%SQROOT interactively that prompts for a number. The square root of the number appears on the same line. %SQROOT then prompts for another number. Press
Example:
GTM>WRITE $$FUNC^%SQROOT(81)
9This example invokes %SQROOT as an extrinsic function with the label FUNC.