%% Forced Rounding in rem
% If Y is not an integer and X./Y is within roundoff error of an integer, then rem rounds to that integer for its calculation. The size of the roundoff error is very small.

X = 2;
Y = 2 - eps(2)

%
% It looks like Y is trivially equal to 2, but in fact there is an infinitesimal difference.

2 - Y

%
% This difference is forced to zero by rem if it is small enough.

R = rem(X,Y)

%
% Make the difference a little larger and the forced rounding disappears.

Y = 2 - eps(4);
R = rem(X,Y)

% Copyright 2012 The MathWorks, Inc.