

In devices and software that implement bitwise operations more efficiently than modulo, these alternative forms can result in faster calculations. For example, the modulo of powers of 2 can alternatively be expressed as a bitwise AND operation (assuming x is a positive integer, or using a non-truncating definition): For special cases, on some hardware, faster alternatives exist.

Modulo operations might be implemented such that a division with a remainder is calculated each time. In nearly all computing systems, the quotient q and the remainder r of a divided by n satisfy the following conditions:īool is_odd ( int n ) Performance issues Computers and calculators have various ways of storing and representing numbers thus their definition of the modulo operation depends on the programming language or the underlying hardware. In mathematics, the result of the modulo operation is an equivalence class, and any member of the class may be chosen as representative however, the usual representative is the least positive residue, the smallest non-negative integer that belongs to that class (i.e., the remainder of the Euclidean division).

In computing, the modulo operation returns the remainder or signed remainder of a division, after one number is divided by another (called the modulus of the operation).
