Skip to main content

Module waveform_arithmetic

Module waveform_arithmetic 

Source
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 explicit StateSpace; 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/limit below 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
1 if x > 0.5, else 0 — a threshold/buffer, the companion to inv.
if_then_else
y if x > 0.5, else z — 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
0 if x > 0.5, else 1 — the complement of buf.
limit
Clamps x to the range spanned by y and z (whichever of y/z is 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 — pwr with the original sign of x reapplied, an odd-symmetric power function (stays real and odd-symmetric where a plain signed power would not).
sgn
Sign of x: -1, 0, or 1 — deliberately not f64::signum (which returns 1.0 for 0.0; this sgn returns 0 at the origin instead, the conventional signum definition).
table
Linear interpolation through a set of (x, y) points (sorted by x, not necessarily evenly spaced) — a table(x, a, b, c, d, ...)-style lookup. Clamped (not extrapolated) outside the given range, holding the nearest endpoint’s y. points must have at least one entry and be sorted ascending by x (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: 1 if x > 0, else 0.
uramp
x if x > 0, else 0 (a ramp that starts at the origin — the same function most block-diagram tools call Relu/Ramp).