Post Reply 
(42) Feet inches fractions
07-11-2021, 08:31 PM
Post: #1
(42) Feet inches fractions
This code takes decimal inches, e.g., 14.25 in X and returns the following in Alpha:
  • feet inches-fractions if flag 1 is clear, e.g., 1' 2-1/4"
  • inches-fractions if flag 1 is set, e.g., 14-1/4"
The intended application is formatting inches for display or printing after performing decimal calculations.

The maximum denominator, which should be a power of 2, is assumed to be set in variable DEN (store 16 in DEN if you don't want anything smaller than sixteenths, for example). Note that the code rounds to the nearest fraction.

The code uses flag 82 internally and doesn't preserve the stack (but see suggested modification in comments).

Code:

00 { 127-Byte Prgm }
01▸LBL "FIF" 
02 CLA  @ Free42 (including DM42): insert FUNC 00 above to preserve stack
03 CF 82
04 ENTER
05 FS? 01
06 GTO 00
07 IP
08 X=0?
09 GTO 01
10 ENTER
11 12
12 ÷
13 IP
14 X=0?
15 GTO 01
16 AIP
17 ├"' "
18▸LBL 01
19 R↓
20 ENTER
21 ENTER
22 12
23 MOD
24▸LBL 00
25 IP
26 X=0?
27 GTO 02
28 SF 82
29 AIP
30▸LBL 02
31 R↓
32 FP
33 X=0?
34 GTO 05
35 FS? 82
36 ├"-"
37 SF 82
38 RCL× "DEN"
39 0.5
40 +
41 IP
42 STO "N"  @ Use LSTO on Free 42 (including DM42)
43 RCL "DEN"
44 STO "D" @ Use LSTO on Free 42 (including DM42)
45▸LBL 03
46 RCL "N"
47 0
48 BIT?
49 GTO 04
50 2
51 STO÷ "D"
52 STO÷ "N"
53 GTO 03
54▸LBL 04
55 RCL "N"
56 AIP
57 ├"/"
58 RCL "D"
59 AIP
60▸LBL 05
61 FS? 82
62 ├"""
63 RTN
64 END
Find all posts by this user
Quote this message in a reply
Post Reply 




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