Divide
MathThe Divide block performs algebraic division of two input signals: the numerator and the denominator. This block includes built-in protection against division by zero, allowing simulations to remain stable even when mathematical singularities are encountered.
The block features two distinct input ports: the upper port for the numerator (num) and the lower port for the denominator (den).
Mathematical Model
The Divide block implements:
Where:
y(t)is the output signal at time tnum(t)is the numerator signalden(t)is the denominator signal
Division by Zero Protection
If the absolute value of the denominator is less than 2.22e-16 (machine epsilon), the block applies protection logic:
- Returns the user-configurable
divByZeroValue. - Displays a one-time visual popup warning in the UI to notify you of the event.
- Logs a detailed message to the browser console.
The visual warning is only shown once per singular event (it resets if the denominator becomes non-zero and then zero again).
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
Signal Normalization
Normalize a signal within the range of 0 to 1:
Measurement → Divide (num)
MaxValue → Divide (den)
Resistance Calculation (Ohm's Law)
Calculate resistance from voltage and current:
Voltage → Divide (num)
Current → Divide (den)
_Tip: Set divByZeroValue to a very high number to represent the infinite resistance of an open circuit when current is 0._
Remarks & Best Practices
- Machine Epsilon: The zero-check uses a small tolerance (
f64::EPSILON) to handle floating-point precision issues. - WASM Performance: The protection logic is implemented natively in Rust for maximum performance with zero overhead during normal operation.
Related Components
- Product: For signal multiplication
- Gain: For fixed-factor signal scaling
- NumericDisplay: To monitor results and console warnings