Re: chowchow for HP-42S Message #2 Posted by Robin (CH) on 4 Nov 2004, 4:07 p.m., in response to message #1 by Mike (Stgt)
I've written something similar. It doesn't check for "Divide by 0" nor if there only are real numbers, but you can enter
the numbers in any order.
-----------------------------------------------------------------------------------------
06.05.2004/RL
XMOD: Zum berechnen des ggT(GCD), kgV(LCM) und gleichzeitigem Kürzen der zwei Werte im X- und Y-Stack
USAGE: a ENTER b XEQ"XMOD"
DISPLAY: -------------------------
| a/b c d |
| as/bs |
-------------------------
DESCRIPTION: a= value entered in Y-stack
b= value entered in X-stack
c= GCD
d= LCM
as/bs=(a/b)/GCD
EXAMPLE: 488 ENTER 12 or alternatively 12 ENTER 488
OUTPUT: 488/12 4 1464 12/488 4 1464
122/3 3/122
-------------------------------------------------------------------------------
01 LBL "XMOD"
02 X<>Y // SWAP, to get Y 1st one into ALHA
03 CLA
04 AIP
05 ¬"/"
06 STO "Y"
07 X<>Y
08 STO "X"
09 AIP
10 ¬" " // add space in ALPHA between original fraction and GCD
11 X>Y? // if X ST is greater then Y ST then SWAP in prepare to the MOD-command in LBL 00
12 X<>Y
13 LBL 00 // GCD routine
14 MOD
15 X=0?
16 GTO 01
17 LAST X
18 X<>Y
19 GTO 00
20 LBL 01
21 LAST X
22 AIP
23 ¬" "
24 STO "GCD" // store GCD
25 RCL "X" // evaluate LCM
26 RCL* "Y"
27 RCL÷ "GCD"
28 AIP
29 STO "LCM" // store LCM
30 RCL "Y" // evaluate simplified fraction
31 RCL÷ "GCD"
32 ¬"LF" // Line Feed, next line shows simplified fraction
33 AIP
34 ¬"/"
35 RCL "X"
36 RCL÷ "GCD"
37 AIP
38 AVIEW
39 RCL "Y" // not necessary, Restores original y-value
40 RCL "X" // not necessary, Restores original X-value
41 CLV "LCM" // not necessary, deletes variable
42 CLV "GCD" // not necessary, deletes variable
43 END
-----------------------------------------------------------------------------------------
|