Menu ▾ ▴

#871 A function's formal argument is replaced by a global random parameter of the same name, or a temperature-dependent .param of the same name

v1.0 (example)
open
nobody
None
5
2026-10-03
2026-10-03
No

inp_fix_agauss_in_param() turns every .param holding agauss, gauss, aunif, unif or limit into a function, .param r1 = agauss(0,1,1) becoming .func r1() agauss(0,1,1). It then rewrites every later occurrence of the name r1 in the deck as r1().
inp_fix_temper_in_param() does the same for .params that depend on temper. Both rewrites also reach the bodies of user functions that have a formal argument with that name. There, the name should refer to the argument. After the rewrite it is a call to the global function, so the function ignores the value passed to it.

With a random global this makes a deterministic expression random: a different result each run, or each seed. With a temper global it gives a wrong but repeatable result.

For example, with the attached sample circuit arg_capture.cir -- the resistance should be 1 every time:

for trials in 1 2 3 4 5 6 7 8 9 10 ; do ngspice -b arg_capture.cir|fgrep resistance ; done
@r1[resistance] = 2.000000e+00
@r1[resistance] = 1.000000e+00
@r1[resistance] = 2.000000e+00
@r1[resistance] = 1.000000e+00
@r1[resistance] = 1.000000e+00
@r1[resistance] = 2.000000e+00
@r1[resistance] = 1.000000e+00
@r1[resistance] = 2.000000e+00
@r1[resistance] = 1.000000e+00
@r1[resistance] = 2.000000e+00

Similarly, the attached sample circuit temper_capture.cir should print a current of 0.1666A but instead prints 0.0179A.

1 Attachments

Discussion


Log in to post a comment.