You can easily create user-defined functions my_modand my_remwithout the use of modand rem, and you can use them as you would use the modand rem.
function modulus = my_mod(X, Y)
if isequal(Y, 0)
modulus = X;
elseif isequal(X, Y)
modulus = 0;
elseif (isequal(abs(X), Inf) || isequal(abs(Y), Inf))
modulus = NaN;
else
modulus = X - floor(X./Y) .* Y;
end
return
function remainder = my_rem(X, Y)
if isequal(Y, 0)
remainder = NaN;
elseif isequal(X, Y)
remainder = 0;
elseif (isequal(abs(X), Inf) || isequal(abs(Y), Inf))
remainder = NaN;
else
remainder = X - fix(X./Y) .* Y;
end
return
source
share