---
url: /dyad/dev/stdlib/BlockComponents/tests/Math.Tests.IntegerToReal.md
description: >-
  Dyad Math.Tests.IntegerToReal docs.  Converts constant and time-varying
  Integer signals back to Real.
---

# `Math.Tests.IntegerToReal` {#Math.Tests.IntegerToReal}

Converts constant and time-varying Integer signals back to Real.

Chains Constant(5.0) → RealToInteger → IntegerToReal and verifies that the final Real output is 5. A second chain feeds a sine wave (amplitude 5) through RealToInteger into IntegerToReal so the Real output steps through the rounded integer values over time.

## Usage {#Usage}

`BlockComponents.Math.Tests.IntegerToReal()`

## Behavior {#Behavior}

$$ \begin{align}
0 &= \mathrm{connect}\left( c1\_{+}y, r2i\_{+}u \right) \\
0 &= \mathrm{connect}\left( r2i\_{+}y, i2r\_{+}u \right) \\
0 &= \mathrm{connect}\left( sine\_{+}y, r2i\_{2\_{+}u} \right) \\
0 &= \mathrm{connect}\left( r2i\_{2\_{+}y}, i2r\_{2\_{+}u} \right) \\
\mathtt{c1.y}\left( t \right) &= \mathtt{c1.k} \\
\mathtt{r2i.y}\left( t \right) &= round_int\left( \mathtt{r2i.u}\left( t \right) \right) \\
\mathtt{i2r.y}\left( t \right) &= \mathtt{i2r.u}\left( t \right) \\
\mathtt{sine.y}\left( t \right) &= ifelse\left( \mathtt{sine.continuous}, ifelse\left( t \geq \mathtt{sine.start_time}, \sin\left( \mathtt{sine.phase} + 6.2832 ~ \mathtt{sine.frequency} ~ \left(  - \mathtt{sine.shift_time} + t \right) \right), \sin\left( \mathtt{sine.phase} + 6.2832 ~ \mathtt{sine.frequency} ~ \left(  - \mathtt{sine.shift_time} + \mathtt{sine.start_time} \right) \right) \right) ~ \mathtt{sine.amplitude}, ifelse\left( t \geq \mathtt{sine.start_time}, \sin\left( \mathtt{sine.phase} + 6.2832 ~ \mathtt{sine.frequency} ~ \left(  - \mathtt{sine.shift_time} + t \right) \right) ~ \mathtt{sine.amplitude}, 0 \right) \right) + \mathtt{sine.offset} \\
\mathtt{r2i_2.y}\left( t \right) &= round_int\left( \mathtt{r2i_2.u}\left( t \right) \right) \\
\mathtt{i2r_2.y}\left( t \right) &= \mathtt{i2r_2.u}\left( t \right)
\end{align}
$$

## Source {#Source}

```dyad
"""
Converts constant and time-varying Integer signals back to Real.

Chains Constant(5.0) → RealToInteger → IntegerToReal and verifies that the
final Real output is 5. A second chain feeds a sine wave (amplitude 5) through
RealToInteger into IntegerToReal so the Real output steps through the rounded
integer values over time.
"""
test component IntegerToReal
  "Constant source providing the Real input"
  c1 = BlockComponents.Sources.Constant(k = 5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "RealToInteger adapter to produce Integer signal"
  r2i = BlockComponents.Math.RealToInteger() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "IntegerToReal block under test"
  i2r = BlockComponents.Math.IntegerToReal() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 310, "y1": 20, "x2": 410, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source sweeping negative and positive values"
  sine = BlockComponents.Sources.Sine(amplitude = 5, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "RealToInteger adapter for the second chain"
  r2i_2 = BlockComponents.Math.RealToInteger() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "Second IntegerToReal block driven by the sine chain"
  i2r_2 = BlockComponents.Math.IntegerToReal() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300, "y1": 140, "x2": 400, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(c1.y, r2i.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(r2i.y, i2r.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sine.y, r2i_2.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(r2i_2.y, i2r_2.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {"case1": {"stop": 1, "expect": {"signals": ["i2r.y", "i2r_2.y", "sine.y"]}}}
  }
}
end
```

```dyad
"""
Converts constant and time-varying Integer signals back to Real.

Chains Constant(5.0) → RealToInteger → IntegerToReal and verifies that the
final Real output is 5. A second chain feeds a sine wave (amplitude 5) through
RealToInteger into IntegerToReal so the Real output steps through the rounded
integer values over time.
"""
test component IntegerToReal
  "Constant source providing the Real input"
  c1 = BlockComponents.Sources.Constant(k = 5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "RealToInteger adapter to produce Integer signal"
  r2i = BlockComponents.Math.RealToInteger() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "IntegerToReal block under test"
  i2r = BlockComponents.Math.IntegerToReal() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 310, "y1": 20, "x2": 410, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source sweeping negative and positive values"
  sine = BlockComponents.Sources.Sine(amplitude = 5, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "RealToInteger adapter for the second chain"
  r2i_2 = BlockComponents.Math.RealToInteger() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "Second IntegerToReal block driven by the sine chain"
  i2r_2 = BlockComponents.Math.IntegerToReal() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300, "y1": 140, "x2": 400, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(c1.y, r2i.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(r2i.y, i2r.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sine.y, r2i_2.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(r2i_2.y, i2r_2.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {"case1": {"stop": 1, "expect": {"signals": ["i2r.y", "i2r_2.y", "sine.y"]}}}
  }
}
end
```

## Test Cases {#Test-Cases}

### Test Case `case1` {#Test-Case-case1}

```julia
plt
```

![](humorlp.svg)

```julia
plt
```

![](khhaump.svg)

```julia
plt
```

![](ztxmlvt.svg)

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`Constant`](Math.Tests.IntegerToReal.md)

  * [`IntegerConstant`](Math.Tests.IntegerToReal.md)

  * [`IntegerStep`](Math.Tests.IntegerToReal.md)

  * [`IntegerToReal`](Math.Tests.IntegerToReal.md)

  * [`IntegerToReal`](Math.Tests.IntegerToReal.md)

  * [`RealToInteger`](Math.Tests.IntegerToReal.md)

  * [`Sine`](Math.Tests.IntegerToReal.md)
