# Calculations In A Program - HP 48gII Advanced User's Reference Manual

Graphing calculator.

Programs can also contain structures. A structure is a program segment with a defined organization. Two basic
kinds of structure are available:
Local variable structure. The  command defines local variable names and a corresponding algebraic or
!
program object that's evaluated using those variables.
Branching structures. Structure words (like DO... UNTIL...END) define conditional or loop structures to
!
control the order of execution within a program.
A local variable structure has one of the following organizations inside a program:
«  name
... name
' algebraic ' "
1
n
«  name
... name
« program " "
1
n
The " command removes n objects from the stack and stores them in the named local variables. The algebraic
or program object in the structure is automatically evaluated because it's an element of the structure – even
though algebraic and program objects are put on the stack in other situations. Each time a local variable name
appears in the algebraic or program object, the variable's contents are substituted.
So the following program takes two numbers from the stack and returns a numeric result:
«  a b 'ABS(a-b)' "

## Calculations in a Program

Many calculations in programs take data from the stack. Two typical ways to manipulate stack data are:
Stack commands. Operate directly on the objects on the stack.
!
Local variable structures. Store the stack objects in temporary local variables, then use the variable names
!
to represent the data in the following algebraic or program object.
Numeric calculations provide convenient examples of these methods. The following programs use two numbers
from the stack to calculate the hypotenuse of a right triangle using the formula
« SQ SWAP SQ + ƒ
«  x y « x SQ y SQ + ƒ " "
«  x y 'ƒ(x^2+y^2)' "
The first program uses stack commands to manipulate the numbers on the stack – the calculation uses stack
syntax. The second program uses a local variable structure to store and retrieve the numbers – the calculation
uses stack syntax. The third program also uses a local variable structure — the calculation uses algebraic syntax.
Note that the underlying formula is most apparent in the third program. This third method is often the easiest to
1-2 RPL Programming
Examples of Program Actions
Program
« 1 2 "
« "Hello" {A B}"
« '1+2' "
« '1+2' NUM"
« « 1 2 + " "
« « 1 2 + " EVAL "
"
Results
2:
1
1:
2
2:
"Hello"
1:
{ A B }
1:
'1+2'
1:
3
1:
« 1 2 + "
1:
3
2
2
.
x
+
y