Divide
MathThe Divide block performs algebraic division of two incoming signals: the numerator signal connected to the upper port (num) and the denominator signal connected to the lower port (den).
To guarantee numerical stability and prevent simulation crashes from mathematical singularities (such as floating-point or NaN values), the block features built-in division-by-zero protection implemented directly in Rust WebAssembly. When the denominator magnitude falls below machine precision, the block smoothly outputs a configurable fallback value and optionally alerts the developer.
Mathematical Model
The algebraic division with singular protection is evaluated as:
where:
- is the numerator signal entering the upper port.
- is the denominator signal entering the lower port.
- is the double-precision floating-point machine epsilon (
f64::EPSILON). - is the user-configured fallback value (
divByZeroValue).
Inputs & Outputs
| Direction | ID | Label | Type | Status |
|---|---|---|---|---|
| → In | num |
Num | number | Required |
| → In | den |
Den | number | Required |
| ← Out | out |
Result | number | Output |
Parameters
| Parameters | Label | Type | Default | Description |
|---|---|---|---|---|
divByZeroValue |
Zero-Div Value | number | 0 |
Value to return when denominator is zero |
reportWarning |
Report Warning | boolean | true |
Send alert to console on division by zero |
Usage Examples
Example 1: Signal Normalization and Unit Scaling
Normalizing a fluctuating process sensor measurement to a unit modulation index . Connecting the measurement signal to num and the setpoint span to den yields a scaled modulation signal for downstream control logic.
Example 2: Dynamic Resistance Calculation (Ohm's Law)
Computing dynamic electrical resistance from measured voltage and current signals. Setting divByZeroValue = 1e6 ensures that when current stops flowing (), the calculated impedance gracefully represents an open circuit without corrupting ODE solver integration.
Remarks & Best Practices
- Machine Precision Threshold: The zero-check evaluates , preventing floating-point overflow and IEEE 754 infinity propagation.
- Console Debouncing: Warning messages are debounced to prevent console spamming when a signal lingers at zero over many simulation timesteps.
- WASM Performance: The protection logic is implemented natively in Rust for maximum execution speed with zero runtime overhead during standard non-zero division.
- Port Identification: The upper input port is dedicated to the numerator (
num), while the lower input port accepts the denominator (den).
Related Components
- Product: Performs algebraic multiplication of multiple input signals.
- Gain: Scales a signal by a constant multiplication factor.
- MathFunction: Evaluates elementary mathematical functions ().
- NumericDisplay: Real-time numerical readout of instantaneous scalar values.