Modulo Modulo Icon

Mathematical.Modulo

Usage

PrimitiveComponents.Mathematical.Modulo()

Connectors

  • u1 - This connector represents a real signal as an input to a component (RealInput)
  • u2 - This connector represents a real signal as an input to a component (RealInput)
  • y - This connector represents a real signal as an output from a component (RealOutput)

Behavior

\[ \begin{align} y\left( t \right) &= ifelse\left( \mathtt{u1}\left( t \right), rem\left( \mathtt{u1}\left( t \right), \mathtt{u2}\left( t \right) \right); \mathtt{u2}\left( t \right) = 0 \right) \end{align} \]

Source

# This component computes the modulo (remainder) of two real-valued input signals `u1` and `u2`.
#
# It returns the remainder when `u1` is divided by `u2`. 
# If `u2` is zero, the output simply equals `u1` to avoid division errors.
#
# Examples:
#   u1 = 10,  u2 = 3   → y = 1   (10 % 3 = 1)
#   u1 = 7,   u2 = 2   → y = 1   (7 % 2 = 1)
#   u1 = 5,   u2 = 0   → y = 5   (division by zero avoided)
#   u1 = -10, u2 = 3   → y = -1  (-10 % 3 = -1)
component Modulo
  u1 = Dyad.RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"x1": -40, "x2": 0, "y1": 150, "y2": 190, "sh": 0.04, "sw": 0.04, "rot": 0},
        "icon": {"x1": -40, "x2": 0, "y1": 150, "y2": 190, "sh": 0.04, "sw": 0.04, "rot": 0}
      }
    }
  }
  u2 = Dyad.RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"x1": -40, "x2": 0, "y1": 790, "y2": 830, "sh": 0.04, "sw": 0.04, "rot": 0},
        "icon": {"x1": -40, "x2": 0, "y1": 790, "y2": 830, "sh": 0.04, "sw": 0.04, "rot": 0}
      }
    }
  }
  # y = u1 % u2
  y = Dyad.RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"x1": 1000, "x2": 1040, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0},
        "icon": {"x1": 1000, "x2": 1040, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0}
      }
    }
  }
relations
  y = ifelse(u2 == 0, u1, u1 % u2)
metadata {
  "Dyad": {
    "icons": {"default": "dyad://PrimitiveComponents/Modulo.svg"},
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100}]
  }
}
end
Flattened Source
component Modulo
  u1 = Dyad.RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"x1": -40, "x2": 0, "y1": 150, "y2": 190, "sh": 0.04, "sw": 0.04, "rot": 0},
        "icon": {"x1": -40, "x2": 0, "y1": 150, "y2": 190, "sh": 0.04, "sw": 0.04, "rot": 0}
      }
    }
  }
  u2 = Dyad.RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"x1": -40, "x2": 0, "y1": 790, "y2": 830, "sh": 0.04, "sw": 0.04, "rot": 0},
        "icon": {"x1": -40, "x2": 0, "y1": 790, "y2": 830, "sh": 0.04, "sw": 0.04, "rot": 0}
      }
    }
  }
  # y = u1 % u2
  y = Dyad.RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"x1": 1000, "x2": 1040, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0},
        "icon": {"x1": 1000, "x2": 1040, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0}
      }
    }
  }
relations
  y = ifelse(u2 == 0, u1, u1 % u2)
metadata {
  "Dyad": {
    "icons": {"default": "dyad://PrimitiveComponents/Modulo.svg"},
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100}]
  }
}
end


Test Cases

No test cases defined.

  • Examples
  • Experiments
  • Analyses