The Museum of HP Calculators
Decimal To Rational for the HP-42S
This program is by Gerald Hillier and is used here by permission.
This program is supplied without representation or warranty of any kind.
Gerald Hillier and The Museum of HP Calculators therefore assume no responsibility
and shall have no liability, consequential or otherwise, of any kind arising
from the use of this program material or any part thereof.
Overview
A programme for converting a decimal number to a rational.
Listing
- { 135-Byte Prgm }
- LBL
”DEC2F”
- 1
- X>=Y?
- GTO 00
- R↓
- RCL ST Y
- FP
- X=0?
- GTO 00
- R↓
-
STO 00
-
R↓
-
STO 01
-
0
- STO ST Z
- SIGN
- RCL+ ST X
- STO 02
- RCL/ ST X
- X<>Y
- LBL
01
-
ENTER
-
X=0?
-
GTO 02
- R↓
- RCL 00
- RCL- ST Z
- X<=0?
- GTO 02
- R↓
-
1/X
-
ENTER
-
FP
-
R↓
- IP
- RCL* ST Y
- RCL+ ST Z
- RCL ST T
- GTO 01
- LBL
02
- R↓
- R↓
- STO ST Z
- RCL 00
- X>=Y?
- GTO 03
- –
- RCL/ ST Y
-
ENTER
-
FP
-
SF 25
- RCL/ ST X
- CF 25
- +
- IP
- RCL* ST Y
- +/-
- RCL+ ST Z
- LBL
03
- RCL ST Y
- RCL* 01
- FIX 00
- RND
- RCL/ ST Z
- RCL- 01
- ABS
- DSE 02
- GTO 03
- X>=Y?
- R↓
- RCL 01
- RCL* ST T
- RND
- ALL
- R↑
- RTN
- LBL
00
- R↓
- R↓
- END
e.g. Stack Y: 7.143
Stack X: 66
Returns
Stack Y: 50
Stack X:
7
i.e. 50/7 is the best approximation to 7.143 for
denominators up to 66.
Go back to the software library
Go
back to the main exhibit hall