Skip to content

Commit b648cd2

Browse files
committed
Can use Modelica.Math.nearestInteger
1 parent 3ebfbb8 commit b648cd2

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

Modelica/Blocks/Math.mo

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ Otherwise the input angle <code>u</code> is wrapped to the <a href=\"https://en.
19391939
Interfaces.IntegerOutput y "Connector of Integer output signal" annotation (
19401940
Placement(transformation(extent={{100,-10},{120,10}})));
19411941
equation
1942-
y = if (u > 0) then integer(floor(u + 0.5)) else integer(ceil(u - 0.5));
1942+
y = Modelica.Math.nearestInteger(u);
19431943
annotation (Icon(coordinateSystem(
19441944
preserveAspectRatio=true,
19451945
extent={{-100.0,-100.0},{100.0,100.0}}), graphics={
@@ -1959,11 +1959,11 @@ Otherwise the input angle <code>u</code> is wrapped to the <a href=\"https://en.
19591959
30.0,-10.0},{30.0,-20.0},{50.0,0.0}})}), Documentation(info="<html>
19601960
<p>
19611961
This block computes the output <strong>y</strong>
1962-
as <em>nearest integer value</em> of the input <strong>u</strong>:
1962+
as <em>nearest integer value</em> of the input <strong>u</strong> utilizing the
1963+
function <a href=\"modelica://Modelica.Math.nearestInteger\">nearestInteger</a>:
19631964
</p>
19641965
<blockquote><pre>
1965-
y = <strong>integer</strong>( <strong>floor</strong>( u + 0.5 ) ) for u &gt; 0;
1966-
y = <strong>integer</strong>( <strong>ceil </strong>( u - 0.5 ) ) for u &lt; 0;
1966+
y = Modelica.Math.<strong>nearestInteger</strong>(u);
19671967
</pre></blockquote>
19681968
</html>"));
19691969
end RealToInteger;

Modelica/Math/nearestInteger.mo

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Math.<strong>nearestInteger</strong>(r);
1717
1818
<h4>Description</h4>
1919
<p>
20-
The input value \"r\" of type Real is converted to the closest Integer value \"i\",
21-
using the <em>round half away from zero</em> rule with the equation:
20+
The input value \"r\" of type Real is converted to the closest Integer value \"i\",
21+
using the <em>round half away from zero</em> rule with the equation:
2222
</p>
2323
<blockquote><pre>
2424
i = <strong>integer</strong>( <strong>floor</strong>( r + 0.5 ) ) for r &gt; 0;
@@ -39,12 +39,12 @@ Math.nearestInteger(1.39999999999999999+0.1); // = 1 (erroneous border case, see
3939
<h4>Note</h4>
4040
4141
<p>
42-
This function does the same conversion as the block
43-
<a href=\"modelica://Modelica.Blocks.Math.RealToInteger\">RealToInteger</a>.
42+
This function does the same conversion as the block
43+
<a href=\"modelica://Modelica.Blocks.Math.RealToInteger\">RealToInteger</a>.
4444
</p>
4545
<p>
46-
The underlying equation is simple, but not always correct. Due to floating point arithmetic some border cases
47-
are not converted correct, like shown in the example above.
46+
The underlying equation is simple, but not always correct. Due to floating point arithmetic some border cases
47+
are not converted correct, like shown in the example above.
4848
</p>
4949
</html>"));
5050
end nearestInteger;

0 commit comments

Comments
 (0)