BlockWerk Documentation
÷

Divide

Math

The 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).

Simulate in BlockWerk

Interactive sandbox directly in your browser — zero installation, WASM-powered.

Simulate in BlockWerk →

Mathematical Model

The Divide block implements:

y(t)=num(t)den(t)y(t) = \frac{\text{num}(t)}{\text{den}(t)}

Where:

  • y(t) is the output signal at time t
  • num(t) is the numerator signal
  • den(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:

  1. Returns the user-configurable divByZeroValue.
  2. Displays a one-time visual popup warning in the UI to notify you of the event.
  3. 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