function J = modulus(I,P)
%
% This function calculates the integer I modulus P and returns this
% value in the integer J.
%
if I < 0
  K = I;
  while K < 0
    K = K + P;
  end
end
if I >= 0
  K = I;
  while K >= P
    K = K - P;
  end
end
J = K;
return  
