Expand description
A standard real-valued scalar function library — trig, exponential/log, rounding, sign,
select/clamp, and table lookup — offered here as ordinary stateless blocks alongside
crate::math_ops’s gain/sum/product/saturation. This is the common vocabulary
most waveform-arithmetic/expression languages across circuit simulation tools converge on
(trig, exponential/log, sign, min/max, a select/if, a clamp, a lookup table), offered here
as composable blocks instead of a second expression language. Each function is a pure
function of its argument(s), evaluated fresh every step, exactly like the rest of
math_ops.
Not included, on purpose:
- A finite-difference derivative, or random/noise generators — genuinely stateful or
history-dependent, not stateless math, so they don’t belong in this module (a derivative
belongs in
dynamics/an explicitStateSpace; a real PRNG/noise block would be a legitimate future addition, just a different one). - Complex-data functions (real/imaginary part, phase, magnitude, conjugate) — this project has no complex-valued signals; everything here is a real-valued time-domain transient.
- Boolean/comparison operators (bitwise and/or/xor, greater/less-than, negation) — those
belong to a plot-expression language for post-processing saved waveforms, not simulation
blocks;
if/limitbelow cover the actual control-logic use case (a comparator/select block) a real circuit’s controller would need.
MathFn1/MathFn2/MathFn3 group the one/two/three-argument functions so
dae-runtime’s block graph (and general-simulator-cli’s device-file parser) can dispatch by
name without one bespoke BlockKind variant per function.
Enums§
- MathFn1
- One of the single-argument real waveform-arithmetic functions.
- MathFn2
- One of the two-argument real waveform-arithmetic functions.
- MathFn3
- One of the three-argument real waveform-arithmetic functions.
Functions§
- buf
1ifx > 0.5, else0— a threshold/buffer, the companion toinv.- if_
then_ else yifx > 0.5, elsez— a select/comparator block (the control-logic use case a separate Boolean expression language would otherwise cover, expressed here as an ordinary three-input block instead).- inv
0ifx > 0.5, else1— the complement ofbuf.- limit
- Clamps
xto the range spanned byyandz(whichever ofy/zis smaller is the floor) — the “intermediate value of x, y, and z.” - pwr
abs(x)**y— like [pow], but always real-valued (a negative base raised to a non-integer power would otherwise be complex).- pwrs
sgn(x) * abs(x)**y—pwrwith the original sign ofxreapplied, an odd-symmetric power function (stays real and odd-symmetric where a plain signed power would not).- sgn
- Sign of
x:-1,0, or1— deliberately notf64::signum(which returns1.0for0.0; thissgnreturns0at the origin instead, the conventional signum definition). - table
- Linear interpolation through a set of
(x, y)points (sorted byx, not necessarily evenly spaced) — atable(x, a, b, c, d, ...)-style lookup. Clamped (not extrapolated) outside the given range, holding the nearest endpoint’sy.pointsmust have at least one entry and be sorted ascending byx(the caller’s responsibility — a device-file-level parser is the natural place to sort once at load time, not every step). - u
- Unit step:
1ifx > 0, else0. - uramp
xifx > 0, else0(a ramp that starts at the origin — the same function most block-diagram tools callRelu/Ramp).