139 lines
1.8 KiB
Plaintext
139 lines
1.8 KiB
Plaintext
00 { 168-Byte Prgm }
|
||
01 LBL "Q2F"
|
||
|
||
02 CLRG
|
||
03 CF 01
|
||
|
||
// Save Stack
|
||
04 STO 01
|
||
05 R↓
|
||
06 STO 02
|
||
07 R↓
|
||
08 STO 03
|
||
09 R↓
|
||
10 STO 04
|
||
11 R↓
|
||
|
||
// Get precision
|
||
12 8
|
||
13 FS? 36
|
||
14 STO+ 05
|
||
15 4
|
||
16 FS? 37
|
||
17 STO+ 05
|
||
18 2
|
||
19 FS? 38
|
||
20 STO+ 05
|
||
21 1
|
||
22 FS? 39
|
||
23 STO+ 05
|
||
24 RCL 05
|
||
// If precision is 0, set default to 9
|
||
25 X=0?
|
||
26 9
|
||
27 +/-
|
||
28 10↑X
|
||
29 STO 05
|
||
|
||
// Init counter
|
||
//30 RCL "Q2MAX"
|
||
//31 X=0?
|
||
30 12
|
||
31 1
|
||
32 X<>Y
|
||
33 DIM "Q2XM"
|
||
34 1000
|
||
35 ÷
|
||
36 1.00001
|
||
37 +
|
||
38 STO 06
|
||
39 INDEX "Q2XM"
|
||
|
||
// Start with value from X
|
||
40 CLST
|
||
41 RCL 01
|
||
|
||
// [[A]] [LOOP-BEGIN] Build continued fraction
|
||
42 LBL A
|
||
43 ENTER
|
||
44 IP
|
||
45 STOEL
|
||
46 J+
|
||
47 X<>Y
|
||
48 FP
|
||
49 STO 08
|
||
|
||
// Check if configured tolerance is reached --> goto B
|
||
50 RCL 05
|
||
51 X>Y?
|
||
52 GTO B
|
||
// .. if not, roll-down check value
|
||
53 R↓
|
||
// ... and invert result for next round
|
||
54 1/X
|
||
|
||
// Proceed, if max num of rounds is reached --> repeat A
|
||
55 ISG 06
|
||
56 GTO A
|
||
|
||
// Set Flag 1 to indicate max rounds reached
|
||
57 SF 01
|
||
|
||
// [LOOP-END] Build continued fraction
|
||
58 GTO C
|
||
|
||
// [[B]] FINISHED building continued fraction by tolerance
|
||
59 LBL B
|
||
// Remove last stack entry used for tolerance check
|
||
60 R↓
|
||
|
||
// [[C]] FINISHED building continued fraction by max num of rounds
|
||
61 LBL C
|
||
// ... and reduce matrix-index, because it was increased by previous loop.
|
||
62 J-
|
||
|
||
// Init loop for reverse calculation from old value
|
||
63 RCLIJ
|
||
64 0.00101
|
||
65 +
|
||
66 STO 06
|
||
|
||
// Start calculation of final fraction
|
||
// NOTE: 1. fraction always has nominator =1
|
||
67 1
|
||
68 RCLEL
|
||
|
||
// [[D]] [LOOP-BEGIN] Reverse calculation
|
||
69 LBL D
|
||
70 ENTER
|
||
71 R↓
|
||
72 X<>Y
|
||
73 R↑
|
||
|
||
74 J-
|
||
75 RCLEL
|
||
76 ×
|
||
77 +
|
||
|
||
78 DSE 06
|
||
79 GTO D
|
||
// [LOOP-END] Perform reverse calculation
|
||
|
||
// Prepare Alpha-Register
|
||
80 CLA
|
||
81 AIP
|
||
82 X<>Y
|
||
83 ⊢"/"
|
||
84 AIP
|
||
|
||
// Revert Stack
|
||
85 RCL 04
|
||
86 RCL 03
|
||
87 RCL 02
|
||
88 RCL 01
|
||
|
||
// Show Result
|
||
//90 AVIEW
|
||
|
||
89 END
|