141 lines
1.7 KiB
Plaintext
141 lines
1.7 KiB
Plaintext
00 { 172-Byte Prgm }
|
||
01 LBL "Q2F"
|
||
|
||
03 CLRG
|
||
|
||
// 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?
|
||
32 12
|
||
33 1000
|
||
34 ÷
|
||
35 0.00001
|
||
36 +
|
||
37 STO 06
|
||
38 10
|
||
39 STO 07
|
||
|
||
40 CLST
|
||
41 RCL 01
|
||
|
||
// [[A]] [LOOP-BEGIN] Build continued fraction
|
||
42 LBL A
|
||
43 ENTER
|
||
44 IP
|
||
45 STO IND 07
|
||
46 X<>Y
|
||
47 FP
|
||
48 STO 08
|
||
|
||
// Check if configured tolerance is reached --> goto B
|
||
49 RCL 05
|
||
50 X>Y?
|
||
51 GTO B
|
||
// .. if not, roll-down check value
|
||
52 R↓
|
||
// ... and invert result for next round
|
||
53 1/X
|
||
|
||
// Increase REG-index
|
||
54 1
|
||
55 STO+ 07
|
||
56 R↓
|
||
|
||
// Proceed, if max num of rounds is reached --> repeat A
|
||
57 ISG 06
|
||
58 GTO A
|
||
// [LOOP-END] Build continued fraction
|
||
59 GTO C
|
||
|
||
// [[B]] FINISHED building continued fraction by tolerance
|
||
60 LBL B
|
||
// Remove last stack entry used for tolerance check
|
||
61 R↓
|
||
|
||
// [[C]] FINISHED building continued fraction by max num of rounds
|
||
62 LBL C
|
||
|
||
// Init loop for reverse calculation from old value
|
||
63 RCL 06
|
||
64 IP
|
||
65 0.00001
|
||
66 +
|
||
67 STO 06
|
||
|
||
// Start calculation of final fraction
|
||
// NOTE: 1. fraction always has nominator =1
|
||
68 CLST
|
||
69 1
|
||
70 RCL IND 07
|
||
71 PRSTK
|
||
|
||
// [[D]] [LOOP-BEGIN] Reverse calculation
|
||
72 LBL D
|
||
73 ENTER
|
||
74 R↓
|
||
75 X<>Y
|
||
76 R↑
|
||
|
||
// Decrease REG-index
|
||
77 1
|
||
78 STO- 07
|
||
79 CLX
|
||
|
||
80 RCL IND 07
|
||
81 ×
|
||
82 +
|
||
83 PRSTK
|
||
|
||
84 DSE 06
|
||
85 GTO D
|
||
// [LOOP-END] Perform reverse calculation
|
||
|
||
// Prepare Alpha-Register
|
||
86 CLA
|
||
87 AIP
|
||
88 X<>Y
|
||
89 ⊢"/"
|
||
90 AIP
|
||
|
||
// Revert Stack
|
||
91 RCL 04
|
||
92 RCL 03
|
||
93 RCL 02
|
||
94 RCL 01
|
||
|
||
// Show Result
|
||
//90 AVIEW
|
||
|
||
95 END
|