Reference Guide
1-16 RPL Programming
Example: Two Conditional Actions.
This program takes a value x from the stack and calculates (sin x)/x. At x
= 0 the division would error, so the program returns the limit value 1 in this case.
« → x « IF 'x‹0' THEN x SIN x / ELSE 1 END » »
The following version uses IFTE algebraic syntax:
« → x 'IFTE(x‹0,SIN(x)/x,1' »
Example: Two Conditional Actions.
This program multiplies two numbers together if they’re both nonzero —
otherwise, it returns the string “ZERO”.
Program: Comments:
«
→ n1 n2
Creates the local variables.
«
Starts the defining procedure.
IF
Starts the test clause.
'n1‹0 AND n2‹0'
Tests n1 and n2.
THEN
n1 n2 *
If both numbers are nonzero, multiplies the two
values.
ELSE
"ZERO"
Otherwise, returns the string
ZERO
.
END
Ends the conditional.
»
»
Ends the defining procedure.
Example: Two Conditional Actions.
This program tests if two numbers on the stack have the same value. If
so, it drops one of the numbers and stores the other in variable V1 — otherwise, it stores the number from level 1
in V1 and the number from level 2 in V2.
Program: Comments:
«
IF
DUP2
SAME
For the test clause, copies the numbers in levels 1 and
2 and tests if they have the same value.
THEN
DROP
'V1' STO
For the true clause, drops one of the numbers and
stores the other in V1.
ELSE
'V1' STO
'V2' STO
For the false clause, stores the level 1 number in V1
and the level 2 number in V2.
END
Ends the conditional structure.
»
`
Puts the program on the stack.
O
TST
K
Stores it in TST.
Enter the numbers 26 and 52, then execute TST to compare their values. Because the two numbers aren’t equal, the
VAR menu now contains two new variables V1 and V2.
26 `52 J
%TST%