Post Reply 
Power-of-two fraction handling for the 41C
02-01-2016, 09:36 PM (This post was last modified: 02-01-2016 09:41 PM by Dieter.)
Post: #12
RE: Power-of-two fraction handling for the 41C
(02-01-2016 08:43 PM)quantalume Wrote:  I took Dieter's code and added a check for the trivial case of calling the function with an integer. It now returns just the integer rather than the integer + "0/1".
(...)
Hopefully Dieter will be along soon to clean up the mess I made of his code. It now has too many labels and jumps for my liking.

That's why I prefer flags here. Just clear or set e.g. flag 05 if MOD yields zero and skip the x/y output routine.

(02-01-2016 08:43 PM)quantalume Wrote:  I won't bother saving/recalling flags as I keep the calculator in FIX 4 most of the time anyway.

Great – this avoids several problems I mentioned in my other post. Which does not mean it cannot be done... ;-)

Here's a new version that uses flag 02 to switch between constant or minimized denominator, and flag 01 toggles between proper and improper fractions (in this case integer input is returned as x/1 instead of just x).

Code:
01 LBL "D2F"
02 ABS
03 RCL 00
04 *
05 FIX 0
06 CF 29
07 RND
08 RCL 00
09 FS? 02
10 GTO 02
11 RCL Y
12 RCL Y
13 LBL 01
14 MOD
15 LASTX
16 X<>Y
17 X≠0?
18 GTO 01
19 +
20 ST/ Z
21 /
22 LBL 02
23 " "
24 RCL Y
25 RCL Y
26 /
27 FS? 01
28 GTO 03
29 ENTER
30 INT
31 ARCL X
32 RDN
33 RDN
34 MOD
35 CF 05
36 X=0?
37 SF 05
38 LASTX
39 R↑
40 FS?C 05
41 GTO 04
42 "├ "
43 LBL 03
44 ARCL Z
45 "├/"
46 ARCL Y
47 LBL 04
48 FIX 4
49 SF 29
50 AVIEW
51 END

And maybe we can also get this RCL d thing working... ;-)

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Power-of-two fraction handling for the 41C - Dieter - 02-01-2016 09:36 PM



User(s) browsing this thread: 1 Guest(s)