Files in directory rlm-12cp/hypotenuse from the latest check-in of branch trunk
- hypotenuse.12c
- README.md
Description
Calculate either the length of a right triangle’s hypotenuse given the lengths of the legs, or one leg given the other and the hypotenuse.
Usage
Hypotenuse: Put legs a and b on the stack, then g
GTO
000
R/S
Other Leg: Put hypotenuse c on the stack followed by leg a, then g
GTO
007
R/S
Resources
X and Y are consumed, with the answer in X.
- X: leg length on input, answer on output
- Y: hypotenuse (
GTO
000
) or other leg (GTO
007
) on input - variables: none
- flags: none
Compatibility
I wrote this using the RLM 12c Platinum simulator, and it is directly openable as such.
Because this simulator’s program save format does not include a pretty-printed version, I provide it inline here, including comments to document the register contents:
001 x² ; T Z a b²
002 x≷y ; T Z b² a
003 x² ; T Z b² a²
004 + ; T T Z a²+b²
005 √x ; T T Z c
006 g GTO 000 ; “RTN” in 12c-speak
Notice that even a program this short exhibits a few of the extended HP 12c Platinum features:
The dedicated
x²
operation.The trivial effect of replacing the Platinum’s single-instruction operation with
2
yˣ
on the 12C is that it pushes the next program’s starting address down two steps since this program uses this operation twice.Less obvious is that doing this destroys the Z value from the first step; the starting register contents become
T a b 2
. Contrast a 12c Platinum, where we see above that the former Z is preserved as the new Y.In a strange quirk of HP RPN behavior, there is at the same time no change in the end state of T. Stack-end duplication logic causes both the 12C and the Platinum to copy T down as the new Z.
3-digit
GTO
addresses.That makes the “
RTN
” equivalent on the 12Cg
GTO
0
0
.Between this and the above point, the starting address for the next program on a 12C becomes not
009
but09
.
Now let us show the corresponding “leg” program:
007 x² ; T Z c b²
008 x≷y ; T Z b² c
009 x² ; T Z b² c²
010 x≷y ; T Z c² b²
011 - ; T T Z c²-b²
012 √x ; T T Z a
013 g GTO 000 ; “RTN” in 12c-speak
You might wish to contrast this with the versions for the HP 15C and the SwissMicros DM32.
See Also
Motivation here, plus other variants, including a version of the “leg” program with the HP-12C modification suggested above, plus adaptation to its weaker calling syntax.