RealToInteger

block RealToInteger "Convert Real to Integer signal"
    extends Modelica.Blocks.Icons.IntegerBlock;

    Interfaces.RealInput u "Connector of Real input signal"
        annotation (Placement(transformation(extent = {
            {-140, -20}, 
            {-100, 20}})));
    Interfaces.IntegerOutput y "Connector of Integer output signal"
        annotation (Placement(transformation(extent = {
            {100, -10}, 
            {120, 10}})));
equation
    y = if 0 < u then integer(floor(u + 0.5)) else integer(ceil(u - 0.5));

    annotation (
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Text(
                    lineColor = {0, 0, 127},
                    extent = {
                        {-100, -40}, 
                        {0, 40}},
                    textString = "R"), 
                Text(
                    lineColor = {255, 127, 0},
                    extent = {
                        {20, -40}, 
                        {120, 40}},
                    textString = "I"), 
                Polygon(
                    lineColor = {255, 127, 0},
                    fillColor = {255, 127, 0},
                    fillPattern = FillPattern.Solid,
                    points = {
                        {50, 0}, 
                        {30, 20}, 
                        {30, 10}, 
                        {0, 10}, 
                        {0, -10}, 
                        {30, -10}, 
                        {30, -20}, 
                        {50, 0}})}),
        Documentation(info = "<html>\n<p>\nThis block computes the output <strong>y</strong>\nas <em>nearest integer value</em> of the input <strong>u</strong>:\n</p>\n<pre>    y = <strong>integer</strong>( <strong>floor</strong>( u + 0.5 ) )  for  u &gt; 0;\n    y = <strong>integer</strong>( <strong>ceil </strong>( u - 0.5 ) )  for  u &lt; 0;\n</pre>\n</html>"));
end RealToInteger;