Modulus

If p and q are two numbers (of any storage type), and p = n * q + r, where p and r have the same sign, n is an integer, and |r| < |q|, then p % q = r. For example
>> 5 % 3
   2
>> 5 % (-3)
   2
.> (-5) % 3
   -2
>> (-5) % (-3)
   -2
>> r = 10 % pi
   0.5752220392
>> (10 - r) / pi
   3

If one of p and q is a matrix and the other is a scalar, or both are matrices of the same storage type, then p % q is defined as a matrix, whose entries are the element-wise modulus of the entries of p and q.



oz 2009-12-22