Post Reply 
Power-of-two fraction handling for the 41C
02-01-2016, 07:10 AM (This post was last modified: 02-01-2016 07:12 AM by Dieter.)
Post: #6
RE: Power-of-two fraction handling for the 41C
(02-01-2016 02:06 AM)quantalume Wrote:  OK, I shall then. We can compare code when I finish.

Fine. Here's my version:

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

Usage:
Store the maximum denominator in R00. No other data registers are used.
Set flag 04 if you want a fixed denominator, otherwise the fraction with the minimum denominator is returned.

64 STO 00
1,3525 XEQ"D2F"  =>  1 23/64

The rounded result is returned in X, the other stack registers hold the three values of the result.

T: 1
Z: 23
Y: 64
X: 1,359375


Variations:
The program can be easily modified to accept the max. denominator on the stack (fraction ENTER denominator XEQ"D2F") and/or return improper fractions (87/64 in this case).

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 07:10 AM



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