diff --git a/q2x.free42 b/q2x.free42 index 37b0607..7e76811 100644 --- a/q2x.free42 +++ b/q2x.free42 @@ -1,7 +1,8 @@ -00 { 172-Byte Prgm } +00 { 168-Byte Prgm } 01 LBL "Q2F" -03 CLRG +02 CLRG +03 CF 01 // Save Stack 04 STO 01 @@ -35,17 +36,20 @@ 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 +//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 @@ -53,88 +57,82 @@ 42 LBL A 43 ENTER 44 IP -45 STO IND 07 -46 X<>Y -47 FP -48 STO 08 +45 STOEL +46 J+ +47 X<>Y +48 FP +49 STO 08 // Check if configured tolerance is reached --> goto B -49 RCL 05 -50 X>Y? -51 GTO B +50 RCL 05 +51 X>Y? +52 GTO B // .. if not, roll-down check value -52 R↓ +53 R↓ // ... and invert result for next round -53 1/X - -// Increase REG-index -54 1 -55 STO+ 07 -56 R↓ +54 1/X // Proceed, if max num of rounds is reached --> repeat A -57 ISG 06 -58 GTO A +55 ISG 06 +56 GTO A + +// Set Flag 1 to indicate max rounds reached +57 SF 01 + // [LOOP-END] Build continued fraction -59 GTO C +58 GTO C // [[B]] FINISHED building continued fraction by tolerance -60 LBL B +59 LBL B // Remove last stack entry used for tolerance check -61 R↓ +60 R↓ // [[C]] FINISHED building continued fraction by max num of rounds -62 LBL C +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 RCL 06 -64 IP -65 0.00001 -66 + -67 STO 06 +63 RCLIJ +64 0.00101 +65 + +66 STO 06 // Start calculation of final fraction // NOTE: 1. fraction always has nominator =1 -68 CLST -69 1 -70 RCL IND 07 -71 PRSTK +67 1 +68 RCLEL // [[D]] [LOOP-BEGIN] Reverse calculation -72 LBL D -73 ENTER -74 R↓ -75 X<>Y -76 R↑ +69 LBL D +70 ENTER +71 R↓ +72 X<>Y +73 R↑ -// Decrease REG-index -77 1 -78 STO- 07 -79 CLX +74 J- +75 RCLEL +76 × +77 + -80 RCL IND 07 -81 × -82 + -83 PRSTK - -84 DSE 06 -85 GTO D +78 DSE 06 +79 GTO D // [LOOP-END] Perform reverse calculation // Prepare Alpha-Register -86 CLA -87 AIP -88 X<>Y -89 ⊢"/" -90 AIP +80 CLA +81 AIP +82 X<>Y +83 ⊢"/" +84 AIP // Revert Stack -91 RCL 04 -92 RCL 03 -93 RCL 02 -94 RCL 01 +85 RCL 04 +86 RCL 03 +87 RCL 02 +88 RCL 01 // Show Result //90 AVIEW -95 END +89 END