MATLAB: Does the ‘ %%’ operator used in Stateflow chart results in incorrect results in Stateflow

stateflow

The model attached has a Stateflow chart which has a function roundPto1 for rounding off a fractional part (i.e., if fractional part of a number P is >= 1/2, result should be rounded to higher integer, otherwise the integer below P).
When I use the '%%' operator (Ex_roundANumberToOne.mdl) I do not get the expected results. When I use ml.mod (Ex_roundANumberToOne_1.mdl) instead of the '%%' operator the results are as expected.

Best Answer

Stateflow's %% operator uses C-languages rules which only do round-to-floor and not round-to-nearest.
To work around the issue, use ml.mod, which honors MATLAB semantics.