UPDATE OF PHYSICAL CONSTANTS & calculations with
SAVED STACK using
LOCAL VARIABLES
(The following work is also relevant for
LSTO illustrations and
Local Stack Save examples)
My goal was initially to make a simple exhaustive update of 42 physical constants (including some simple calculations of derived values and conversion coefficients) complying with the latest officially accepted values according to the CODATA (2018) complete data table :
https://pml.nist.gov/cuu/Constants/Table/allascii.txt.
I started with the interesting program from
Mr. Grsbanks which already provided a direct access to 40 physical constants (as in the HP-35s) through their respective keys, distributed on a 7 row’s menu: an explicit demonstration of these Key/Menu features of the DM42/Free42/HP42. I updated all the values and then realize that some derived quantity (like the proton Compton wavelength or other conversion coefficients) could be easily computed within the program itself (using internal calls, as it was done also in the
Mr. Bernd's version, as I understood it afterward). However, differing from a single entry to the X register (or executing a single number function), the drawback was that such intermediate calculations would potentially corrupt the top of the stack with unwanted repeated numbers which may turn out to be inconvenient in any other RPN-context scientific calculations.
An evident solution was to create some Push and Pop subroutines to reinstate the unperturbed remaining stack (Y, Z, T and LastX registers). But then, why not try to do this through the powerful use of
local variables (thanks to the
LSTO implementation of
Mr. Thomas Okken). Due to the consecutive RTN order precedencies, this posed however an interesting challenge because to retain the
local variables (“
Ys”, “
Zs”, “
Ts” and “
Ls”) up to the end, it required that the “PopST” final call had been performed after but through the initial call of the “PshST” subroutine where, in between, the desired calculations would have been achieved using an indirectly addressed subroutine (having the numeric label “xx”). And finally, the retained solution works correctly as I chose to pass the indirect value “xx” (identifying the specific calculation) in another
local variable “
LBLxx”, performing then the indirect call XEQ IND “
LBLxx” at the end of “PshST”, and thus, before the final invoking of “PopST” which terminates the subroutine “LBLxx”. “Et voilà, le tour est joué !” Anyway, a look at the code will probably explain more clearly my approach. Here, I applied successfully the technique for the calculations of λcn = h/(c mn), λcp = h/(c mp), e = exp(1) [with full 34 digits precision] and for the conversion coefficients “MeV/u” (in nuclear physics: c^2 ≈ 931,49 MeV/u ) and “eV*nm” (for the photoelectric effect: Eph[eV] ≈ 1240/ λ[nm]). Prolonging the
Mr. Grsbanks design, it would be easy to add even 18 more entries to suit all your needs. And this stack local-preservation-technique is easily adaptable to many other programs.
Finally, It was a fun exercise because as the code is executed, it is simply captivating to follow 1) the sudden creation of
local variables, 2) all achieving their specific tasks, 3) and completing them before they happen to disappear 4) just in time to avoid any side effect or corruption 5) even between consecutive calls within the same program (I suspect that this might also work recursively according to an example provided by
Mr. Thomas Okken on his site [Is it indeed the case?]). This on-demand dynamic memory management (creating and freeing
local variables “in flight”) provides a new and quite powerful tool for the development of your future programs specifically in the DM42/Free42 environment (with the hope that the 43S will soon share a similar behavior, as previously inaugurated with the WP34S). Let us know about your initiatives on this subject of dynamic memory!
Code: Select all
00 { 1372-Byte Prgm }
01▸LBL "ConstL"
02▸LBL A
03 "c"
04 KEY 1 XEQ 01
05 "g"
06 KEY 2 XEQ 02
07 "G"
08 KEY 3 XEQ 03
09 "Vm"
10 KEY 4 XEQ 04
11 "NA"
12 KEY 5 XEQ 05
13 "Rydb"
14 KEY 6 XEQ 06
15 KEY 7 GTO G
16 KEY 8 GTO B
17 KEY 9 GTO I
18 MENU
19 STOP
20 GTO A
21▸LBL I
22 EXITALL
23 STOP
24 GTO A
25▸LBL 01
26 299792458
27 RTN
28▸LBL 02
29 9.80665
30 RTN
31▸LBL 03
32 66743ᴇ-15
33 RTN
34▸LBL 04
35 0.022413996
36 RTN
37▸LBL 05
38 602214076ᴇ15
39 RTN
40▸LBL 06
41 10973731.56816
42 RTN
43▸LBL B
44 "eV"
45 KEY 1 XEQ 11
46 "me"
47 KEY 2 XEQ 12
48 "mp"
49 KEY 3 XEQ 13
50 "mn"
51 KEY 4 XEQ 14
52 "mμ"
53 KEY 5 XEQ 15
54 "k"
55 KEY 6 XEQ 16
56 KEY 7 GTO A
57 KEY 8 GTO C
58 KEY 9 GTO I
59 MENU
60 STOP
61 GTO B
62▸LBL 11
63 1602176634ᴇ-28
64 RTN
65▸LBL 12
66 91093837015ᴇ-41
67 RTN
68▸LBL 13
69 167262192369ᴇ-38
70 RTN
71▸LBL 14
72 167492749805ᴇ-38
73 RTN
74▸LBL 15
75 188353162739ᴇ-39
76 RTN
77▸LBL 16
78 1380649ᴇ-29
79 RTN
80▸LBL C
81 "h"
82 KEY 1 XEQ 21
83 "MagFQ"
84 KEY 2 XEQ 22
85 "ao"
86 KEY 3 XEQ 23
87 "ᴇo"
88 KEY 4 XEQ 24
89 "R"
90 KEY 5 XEQ 25
91 "F"
92 KEY 6 XEQ 26
93 KEY 7 GTO B
94 KEY 8 GTO D
95 KEY 9 GTO I
96 MENU
97 STOP
98 GTO C
99▸LBL 21
100 662607015ᴇ-42
101 RTN
102▸LBL 22
103 2067833848ᴇ-24
104 RTN
105▸LBL 23
106 529177210903ᴇ-22
107 RTN
108▸LBL 24
109 88541878128ᴇ-22
110 RTN
111▸LBL 25
112 8.314462618
113 RTN
114▸LBL 26
115 96485.33212
116 RTN
117▸LBL D
118 "u"
119 KEY 1 XEQ 31
120 "μo"
121 KEY 2 XEQ 32
122 "μB"
123 KEY 3 XEQ 33
124 "μN"
125 KEY 4 XEQ 34
126 "μP"
127 KEY 5 XEQ 35
128 "μe"
129 KEY 6 XEQ 36
130 KEY 7 GTO C
131 KEY 8 GTO E
132 KEY 9 GTO I
133 MENU
134 STOP
135 GTO D
136▸LBL 31
137 16605390666ᴇ-37
138 RTN
139▸LBL 32
140 1.25663706212ᴇ-6
141 RTN
142▸LBL 33
143 92740100783ᴇ-34
144 RTN
145▸LBL 34
146 50507837461ᴇ-37
147 RTN
148▸LBL 35
149 141060679736ᴇ-37
150 RTN
151▸LBL 36
152 -92847647043ᴇ-34
153 RTN
154▸LBL E
155 "μn"
156 KEY 1 XEQ 41
157 "μμ"
158 KEY 2 XEQ 42
159 "re"
160 KEY 3 XEQ 43
161 "Zo"
162 KEY 4 XEQ 44
163 "/\c"
164 KEY 5 XEQ 45
165 "/\cn"
166 KEY 6 XEQ "x46"
167 KEY 7 GTO D
168 KEY 8 GTO F
169 KEY 9 GTO I
170 MENU
171 STOP
172 GTO E
173▸LBL 41
174 -96623651ᴇ-34
175 RTN
176▸LBL 42
177 -4490448301ᴇ-35
178 RTN
179▸LBL 43
180 28179403262ᴇ-25
181 RTN
182▸LBL 44
183 376.730313668
184 RTN
185▸LBL 45
186 242631023867ᴇ-23
187 RTN
188▸LBL "x46"
189 46
190 XEQ "PshST"
191 RTN
192▸LBL 46
193 XEQ 21
194 XEQ 01
195 ÷
196 XEQ 14
197 ÷
198 XEQ "PopST"
199 RTN
200▸LBL F
201 "/\cp"
202 KEY 1 XEQ "x51"
203 "a"
204 KEY 2 XEQ 52
205 "s"
206 KEY 3 XEQ 53
207 "t"
208 KEY 4 XEQ 54
209 "atm"
210 KEY 5 XEQ 55
211 "gP"
212 KEY 6 XEQ 56
213 KEY 7 GTO E
214 KEY 8 GTO G
215 KEY 9 GTO I
216 MENU
217 STOP
218 GTO F
219▸LBL "x51"
220 51
221 XEQ "PshST"
222 RTN
223▸LBL 51
224 XEQ 21
225 XEQ 01
226 ÷
227 XEQ 13
228 ÷
229 XEQ "PopST"
230 RTN
231▸LBL 52
232 0.0072973525693
233 RTN
234▸LBL 53
235 5.670374419ᴇ-8
236 RTN
237▸LBL 54
238 273.15
239 RTN
240▸LBL 55
241 101325
242 RTN
243▸LBL 56
244 267522187.44
245 RTN
246▸LBL G
247 CLMENU
248 "C1"
249 KEY 1 XEQ 61
250 "C2"
251 KEY 2 XEQ 62
252 "Go"
253 KEY 3 XEQ 63
254 "e"
255 KEY 4 XEQ "x64"
256 "MeV/u"
257 KEY 5 XEQ "x65"
258 "eV*nm"
259 KEY 6 XEQ "x66"
260 KEY 7 GTO F
261 KEY 8 GTO A
262 KEY 9 GTO I
263 MENU
264 STOP
265 GTO G
266▸LBL 61
267 3741771852ᴇ-25
268 RTN
269▸LBL 62
270 0.01438776877
271 RTN
272▸LBL 63
273 7.748091729ᴇ-5
274 RTN
275▸LBL "x64"
276 64
277 XEQ "PshST"
278 RTN
279▸LBL 64
280 1
281 E↑X
282 XEQ "PopST"
283 RTN
284▸LBL "x65"
285 65
286 XEQ "PshST"
287 RTN
288▸LBL 65
289 XEQ 01
290 X↑2
291 XEQ 31
292 ×
293 XEQ 11
294 ÷
295 1ᴇ6
296 ÷
297 XEQ "PopST"
298 RTN
299▸LBL "x66"
300 66
301 XEQ "PshST"
302 RTN
303▸LBL 66
304 XEQ 21
305 XEQ 01
306 ×
307 XEQ 11
308 ÷
309 1ᴇ9
310 ×
311 XEQ "PopST"
312 RTN
313▸LBL "PshST"
314 LSTO "LBLxx"
315 R↓
316 LSTO "Ys"
317 R↓
318 LSTO "Zs"
319 R↓
320 LSTO "Ts"
321 R↓
322 CLX
323 LASTX
324 LSTO "Ls"
325 R↓
326 XEQ IND "LBLxx"
327 RTN
328▸LBL "PopST"
329 RCL "Ls"
330 STO ST L
331 RCL ST Y
332 RCL "Ts"
333 RCL "Zs"
334 RCL "Ys"
335 R↑
336 RTN
337 END