- REG x : input
- REG 00 : index
- REG 01~21 : work memory (continued fraction)
- REG 22 : input value
- REG 23 : accumulator
- REG 24 : work memory
- FLAG00 : terminate approximation
- LASTx : input value
- REG t : input value
- REG z : error
- REG y : numerator
- REG x : denominator
Fractional approximation
using continued fraction
recompose and
calculate error
00 { 138-Byte Prgm }
01 LBL "Frac"
02 CF 00
03 ABS
04 STO 22
05 STO 23
06 1.021
07 STO 00
08 CLχ
09 χ<>y
10 LBL B
11 IP
12 STO IND 00
13 χ≠0?
14 XEQ C
15 RCL 23
16 RCL- IND 00
17 χ=0?
18 SF 00
19 FS?C 00
20 GTO E
21 1/χ
22 STO 23
23 ISG 00
24 GTO B
25 LBL E
26 R↓
27 RCL 22
28 ABS
29 CLχ
30 LASTχ
31 R↓
32 RTN
33 LBL C
34 RCL 00
35 IP
36 χ<> 00
37 STO 24
38 0
39 1
40 LBL D
41 ENTER
42 ENTER
43 RCL IND 00
44 ×
45 R↑
46 +
47 DSE 00
48 GTO D
49 ABS
50 χ<>y
51 ENTER
52 ENTER
53 LASTχ
54 ÷
55 RCL× 22
56 1
57 -
58 χ<> 24
59 STO 00
60 CLχ
61 2E-12
62 RCL 24
63 ABS
64 χ<y?
65 SF 00
66 CLχ
67 RCL 24
68 CLA
69 ARCL ST χ
70 "LF"
71 R↑
72 AIP
73 "/"
74 R↑
75 AIP
76 PROMPT
77 RTN
78 END
ExamplesDISP SCI 3
π XEQ FRAC
4.720E-2
1/3-4.023E-4
22/72.649E-5
333/106-8.491E-8
355/1131.800E-10
103993/33102-1.060E-10
104348/332154.000E-11
208341/66317-9.000E-12
312689/995320.000E0
833719/265381
Note: Simple continued fraction expression of π, to 12 digits accuracy.
Franctional approximation of πAPPENDIX - HP42S Program library
Fractional approximation program for the HP-15C
Fractional approximation program for the HP-32sII
Fractional approximation program for the HP-35s
Find the nearest fraction in the E24 numbers