ngspice version: 45.2
OS: Linux
An error of pwr(V(X,Y),z) being out of range is somehow resolved by adding superfluous computations to the second argument of pwr.
Example:
.title pwr argument bug
VIN VIN 0 1.0
VCONTROL VCONTROL 0 1.0
X_VRES VIN 0 VCONTROL 0 VC_RES
.SUBCKT VC_RES 1 2 3 4
R_VAL 1 2 VALUE = { pwr(V(3,4), 0.685841) }
.ENDS
.control
pre_set strict_errorhandling
set filetype = ASCII
save i(vin)
dc VCONTROL 0.1 1.0 0.1
write pwr_bug.csv
exit
.endc
.end
ngspice reports:
Error: 0, -0.314159 out of range for pow
Which is the case when taking the derivative of pwr(V(X,Y),z) for V(X,Y)=0. Since there is a division by 0 when taking 0 to a negative exponent.
However, the simulation finishes without errors when a superfluous computation like "+0" or "*1" is added to the second argument, e.g.:
R_VAL 1 2 VALUE = { pwr(V(3,4), 0.685841*1) }
How does adding "*1" stop the computation of the derivative?
An interesting test case!
The expression parser generates expressions for the differentials of the primary expression with respect to the circuit variables. For pow(a, b), calculating pow(a, b -1) is a shortcut used only when b is a constant. When b is an expression a different formula is used (D(pow(a,b)) = pow(a,b) * (D(b)log(abs(a)) + bD(a)/a)).
So if there is a bug here, it is failing to check the constant value. With that added, no failure. Your test case also shows that constant-valued expressions are not evaluated at parse time, perhaps a useful optimisation.