This program is © 1984 by Fred E. Lusk III, PE and is used here by permission.
FEET performs feet-inches-fractions (F-I-F) calculations using a two-register RPN stack ("XX" and "YY"). The program handles addition and subtraction of two F-I-F numbers (as long as the result isn't negative), multiplication and division of an F-I-F number by a non-negative constant, and F-I-F to decimal and decimal to F-I-F conversions. The program also provides one data storage register ("RR").
One interesting feature of the program is that the user is not limited to 16ths of an inch, though that is the default, or even the binary fractions 1/2, 1/4, 1/8, etc. FEET can work with ANY fraction, including 1/10, 1/31, 1/88, etc. The program handles incompatible fractions by rounding values off to the nearest multiple of the selected fraction. For example, if FEET is set for 8ths of an inch, an entry of 17/23" will be rounded to 6/8", then reduced to 3/4" and displayed. In addition, an entry such as 1'15-25/8" will be corrected to 2'6-1/8". The program also provides a feet-inches (F-I) only mode that eliminates the need to enter fractions. F-I mode is set by entering an initial fraction value of 0 or 1.
As written, FEET requires an HP-41CX with at least 438 bytes of available program space plus 15 data registers. The program uses several extended functions, including X<>F, XTOA, and REGMOVE, though there are workarounds. The heart of the program (the part that reduces the fractions) is based on the fraction reduction routine in the PPC ROM. However, a PPC ROM is not required.
As well as this program works and as "cool" as I think it is, I am planning a major rewrite. FEET currently stores separate numbers for the feet, inches, numerator, and denominator that comprise each dimension value. The next version will store just one number for each dimension (e.g. 1'2-3/4" would be stored as 236 if the fraction is set to 16ths or 59 if the fraction is set to 4ths). The original programming decision was based on the false notion that big numbers with small fractions would lead to inaccuracies if the entire dimension was reduced to a single number. The reality is that 10000'1-1/16" (an absurdity) would reduce to 1,920,017 16ths, which is well within the non-scientific-notation dynamic range of the HP-41CX. This change will simplify data handling and eliminate the need for the REMOVE command. I may even expand the FEET stack to three or four registers, permit the use of negative numbers, and clean up the program structure. This will also accomplish what I was trying to do in creating an HP-42S version, but never got around to finishing.
RESET STO RCL D>F F>D [a] [b] [c] [d] [e] + - * / ENTER [A] [B] [C] [D] [E]
RESET | Restart the program. This is a quick alternative to XEQ "FEET", and is useful for changing the fraction setting, although the contents of XX and YY are cleared. | ||
STO | Copy the contents of XX to RR. XX and YY are left undisturbed. Flag 0 is set as a reminder that RR is in use. | ||
RCL | Recall the contents of RR to XX. The previous contents of XX are moved to YY. The original contents of YY are lost. | ||
D>F | Convert the decimal value in X (in the regular RPN stack) to F-I-F or F-I and place in XX. The previous contents of XX are moved to YY. The original contents of YY are lost. | ||
F>D | Convert the F-I-F or F-I contents of XX to decimal feet. The FEET stack is left undisturbed. | ||
+ | Add the contents of XX and YY. The result is placed in XX. Because YY is the top of the two-register FEET stack, YY remains intact. | ||
- | Subtract XX from YY (YY must be greater than XX). The result is placed in XX. Because YY is the top of the two-register FEET stack, YY remains intact. | ||
* | Multiply the contents of XX by the constant in X. The result is placed in XX. YY is undisturbed. | ||
/ | Divide the contents of XX by the constant in X. The result is placed in XX. YY is undisturbed. | ||
ENTER | ENTER: Process the contents of the four-register RPN stack and place in XX and YY | ||
RPN stack for F-I-F mode X: Denominator Y: Numerator Z: Inches T: Feet |
RPN Stack for F-I mode X: Inches Y: Feet |
1. a) Find the missing dimension to the nearest 1/16". b) Multiply the result by 2/3 (just for kicks). c) Convert to decimal feet and back again. (drawing not to scale) |<- 2'3-5/8" ->|<- 2'3-5/8" ->|<-- 7/16" -->|<- 30" ->|<- 1' ->| |<----- ??? ----->|<- 2'0-32/100" ->|<- 15-1/2" ->|<- 39/16" ->| KEYBOARD DISPLAY Notes -------------------------------------------------------------------- XEQ [ALPHA] FEET [ALPHA] FRACTION ? [R/S] FT^, IN^, N^, D {1.1} 2 [ENTER^] 3 [ENTER^] 5 [ENTER^] 8 [E] 2'3-5/8" [A] 4'7-1/4" {1.2} 7 [ENTER^] 16 [A] 0'0-7/16" {1.3} 4'7-11/16" 30 [ENTER^] 0 [ENTER^] 1 [A] 2'6" {1.4} 7'1-11/16" 1 [ENTER^] 0 [ENTER^] 0 [ENTER^] 1 [A] 1'0" 8'1-11/16" 39 [ENTER^] 16 [B] 0'2-7/16" 7'11-1/4" 15 [ENTER^] 1 [ENTER^] 2 [B] 1'3-1/2" 6'7-3/4" 2 [ENTER^] 0 [ENTER^] 32 [ENTER^] 100 [B] 2'0-5/16" 4'7-7/16" {1.5} 2 [ENTER^] 3 / [C] 3'0-15/16" {1.6} [e] 3.0781' {1.7} [d] 3'0-15/16" " Notes {1.1} The default value is 16, so no entry is needed this time. {1.2} Or: 2 [C] {1.3} The new number is displayed while the result is calculated (typ). {1.4} For a dimension without any fraction, any denominator will do. {1.5} The result for a). {1.6} The result for b). {1.7} The results for c).
2. A circle has a diameter of 1'6". Find the circumference and the quarter circle length to the nearest 1/8" and to the nearest 1/100". KEYBOARD DISPLAY Notes -------------------------------------------------------------------- XEQ [ALPHA] FEET [ALPHA] FRACTION ? 8 [R/S] FT^, IN^, N^, D 1 [ENTER^] 6 [ENTER^] 0 [ENTER^] 1 [E] 1'6" [b] {2.1} [pi] [C] 4'8-1/2" 4 [D] 1'2-1/8" {2.2} [a] FRACTION ? 100 [R/S] FT^, IN^, N^, D [c] 1'6" {2.3} [pi] [C] 4'8-11/20" 4 [D] 1'2-7/50" {2.4} Notes {2.1} The display shows F00 as set, indicating use of RR. {2.2} The first result. {2.3} Even though [a] clears F00, RR remains intact. {2.4} The second result.
3. A 24'0" long Archimedes screw pump is to be installed at an angle of 38°. What are the horizontal and vertical distances between the supports, first to the nearest inch, then to the nearest 1/4"? This is based on the real-life example that prompted me to write FEET: the headworks pumps at the Arvin, CA, wastewater treatment plant. KEYBOARD DISPLAY Notes -------------------------------------------------------------------- XEQ [ALPHA] FEET [ALPHA] FRACTION ? 0 [R/S] FT^, IN {3.1} 24 [ENTER^] 0 [E] 24'0" [b] 38 [COS] [C] 18'11" {3.2} [c] 24'0" 38 [SIN] [C] 14'9" {3.2} [a] FRACTION ? 4 [R/S] FT^, IN^, N^, D [c] 24'0" 38 [COS] [C] 18'11" {3.3} [c] 24'0" 38 [SIN] [C] 14'9-1/4" {3.3} Notes {3.1} Or: 1 [R/S]. The display shows F01 as set, indicating F-I mode. (3.2} The first two results. {3.3} The second two results.
The annotations included with the program listing are intended to explain generally how FEET works, and are by no means exhaustive.
LINE KEYS 01 * LBL "FEET" ; ### FEET ### 02 * LBL a ; ### RESET ### 03 0 ; [03-11] Clear XX (R01-R04) and YY (R05-R08) 04 STO 01 05 STO 02 06 STO 03 07 STO 04 08 STO 05 09 STO 06 10 STO 07 11 STO 08 12 X<>F ; Clear flags 0-7 13 1.005004 ; REGMOVE constant for XX and YY 14 STO 09 15 16 ; Default "Fraction" (FF) 16 "FRACTION ?" ; [16-17] Prompt for FF 17 PROMPT 18 ABS ; [18-19] Ensure FF is non-negative integer 19 INT 20 X=0? ; [20-21] Convert FF=0 to FF=1 21 SIGN 22 STO 00 ; Store FF 23 1 ; [23-25] If FF=1 (or previously 0) program sets 24 X=Y? ; F-I mode 25 SF 01 26 FIX 0 ; [26-30] Initialize remaining program settings 27 CLST 28 CF 22 29 SF 27 30 CF 29 31 "FT^, IN" ; [31-35] Display data entry prompt for F-I and 32 FC? 01 ; F-I-F calculations 33 "^, N^, D" 34 AVIEW 35 RTN 36 * LBL b ; ### STO ### ------------------------------------- 37 1.011004 ; [37-38] Copy contents of XX into RR 38 REGMOVE 39 SF 00 ; Indicate storage register is in use 40 CLST 41 CF 22 ; Clear data entry flag 42 AVIEW ; Redisplay XX 43 RTN 44 * LBL c ; ### RCL ### ------------------------------------- 45 RCL 09 ; [45-46] Copy contents of XX to YY 46 REGMOVE 47 11.001004 ; [47-48] Copy contents of RR to XX 48 REGMOVE 49 GTO 99 ; Go to routine to display XX 50 * LBL d ; ### D>F ### ------------------------------------- 51 RCL 09 ; [51-52] Copy contents of XX to YY 52 REGMOVE 53 X<>Y ; Bring input decimal value back to X 54 INT ; [54-69] Parse decimal value into F-I-F and store 55 STO 01 ; components 56 LASTX 57 FRC 58 12 59 * 60 FS? 01 ; [60-61] Jump out if only working with F-I 61 GTO 15 62 INT 63 STO 02 64 LASTX 65 FRC 66 RCL 00 67 * 68 RND 69 STO 03 70 GTO 98 ; Go to routine to display XX 71 * LBL e ; ### F>D ### -------------------------------------- 72 XEQ 02 ; Data handling 73 RCL 01 ; [73-78] Fill RPN stack with XX components 74 RCL 02 75 FS? 01 ; [75-76] Skip [77-80] if in F-I mode 76 GTO 10 77 RCL 03 78 RCL 04 79 / ; [79-84] Convert F-I-F or F-I to decimal feet 80 + 81 * LBL 10 82 12 83 / 84 + 85 FIX 4 ; [85-92] Display result 86 CLA 87 ARCL X 88 39 89 XTOA 90 X<>Y 91 FIX 0 92 AVIEW 93 RTN ; Result kept in X so [d] will "reverse" process 94 * LBL A ; ### + ### --------------------------------------- 95 SF 06 ; Set addition flag 96 * LBL B ; ### - ### 97 XEQ 02 ; XEQ routine to convert RPN stack to F-I-F or F-I 98 FS?C 06 ; [98-103] Subtraction = adding -XX to YY 99 GTO 01 100 -1 101 ST* 01 102 ST* 02 103 ST* 03 104 * LBL 01 105 RCL 05 ; [105-121] XX + YY 106 ST+ 01 107 RCL 06 108 ST+ 02 109 FS? 01 110 GTO 98 111 RCL 03 112 RCL 04 113 / 114 RCL 07 115 RCL 08 116 / 117 + 118 RCL 00 119 * 120 RND 121 STO 03 122 GTO 98 123 * LBL 02 ; ------------------------------------------------- 124 FS? 22 ; [124-125] If data entered into RPN stack, XEQ 21 125 XEQ 21 ; to raise FEET stack 126 FS?C 22 ; [126-127] if data entered into RPN stack, XEQ 97 127 XEQ 97 ; to process data in RPN stack 128 RTN 129 * LBL C ; ### * ### --------------------------------------- 130 ST* 01 131 ST* 02 132 ST* 03 133 GTO 03 134 * LBL D ; ### / ### --------------------------------------- 135 ST/ 01 136 ST/ 02 137 ST/ 03 138 * LBL 03 139 RCL 01 ; [139-166] Reduce XX to proper components 140 INT 141 STO 01 142 LAST X 143 FRC 144 12 145 * 146 ST+ 02 147 RCL 02 148 FS? 01 149 GTO 15 150 INT 151 STO 02 152 LASTX 153 FRC 154 RCL 03 155 RCL 04 156 / 157 + 158 RCL 00 159 * 160 RND 161 STO 03 162 GTO 98 163 * LBL 15 164 RND 165 STO 02 166 GTO 98 167 * LBL E ; ### ENTER ### ----------------------------------- 168 SF 05 ; Set FEET data entry flag 169 * LBL 97 ; Jump-in point for other subroutines 170 FS? 01 ; [170-171] If in F-I mode, skip fraction 171 GTO 07 172 / ; [172-175] Convert fraction to multiple of FF 173 RCL 00 174 * 175 RND 176 STO 03 ; Store fractional part of XX 177 RDN 178 * LBL 07 179 STO 02 ; Store inches part of XX 180 RDN 181 STO 01 ; Store feet part of XX 182 * LBL 98 183 RCL 03 ; [183-...] Normalize XX, incl. reducing fraction 184 X<0? 185 DSE 02 186 . ; The fasted NOP available 187 -12 188 RCL 02 189 X=Y? 190 GTO 03 191 X<0? 192 DSE 01 193 . 194 * LBL 03 195 RCL 03 196 RCL 00 197 RCL 03 198 RCL 00 199 XEQ 08 ; XEQ fraction reduction subroutine 200 ST/ Z 201 / 202 STO 04 203 X<>Y 204 STO 03 205 X<>Y 206 / 207 INT 208 ST+ 02 209 RCL 03 210 RCL 04 211 MOD 212 STO 03 213 RCL 02 214 12 215 / 216 INT 217 ST+ 01 218 RCL 02 219 12 220 MOD 221 STO 02 222 RCL 01 ; [222-224] After normalizing, if the feet part of 223 X<0? ; XX is negative, then it's all wrong. Create 224 SQRT ; an error in lieu of writing more code. 225 FS?C 05 226 XEQ 21 227 * LBL 99 ; ------------------------------------------------- 228 CLA ; [228-246] Display XX as F-I-F or F-I 229 ARCL 01 ; Feet 230 39 ; [230-231] Append feet (') symbol 231 XTOA 232 ARCL 02 ; Append Inches 233 RCL 03 ; [233-235] If no fraction, skip fraction display 234 X=0? 235 GTO 09 236 "-" ; Append hyphen (between inches and fraction) 237 ARCL 03 ; Append numerator 238 "/" ; Append virgule 239 ARCL 04 ; Append denominator 240 * LBL 09 241 34 ; [241-242] Append inches (") symbol 242 XTOA 243 CLST ; [243-244] Clean-up 244 CF 22 245 AVIEW ; Display XX 246 RTN 247 * LBL 08 ; ------------------------------------------------- 248 MOD ; [248-254] Part of fraction reduction routine 249 LASTX ; (see FR in the PPC ROM User's Manual) 250 X<>Y 251 X!=0? ; X not equal to 0? 252 GTO 08 253 + 254 RTN 255 * LBL 21 ; ------------------------------------------------- 256 X<> 09 ; [256-258] Raise stack 257 REGMOVE 258 X<> 09 259 END
R00: Fraction (FF) R01: XX Feet R02: XX Inches R03: XX Numerator (reduced) R04: XX Denominator (reduced) R05: YY Feet R06: YY Inches R07: YY Numerator (reduced) R08: YY Denominator (reduced) R09: REGMOVE constant for XX and YY R10: Not used R11: RR Feet R12: RR Inches R13: RR Numerator (reduced) R14: RR Denominator (reduced)
F00: RR in use F01: F-I mode set F22: Data entry F27: USER Mode F29: Digit separators (F02-F07 cleared for "clean" display)
Go back to the HP-41 software library
Go back to the general software library
Go
back to the main exhibit hall