Integer Division

From Jonathan Gardner's Tech Wiki
Jump to: navigation, search

Integer division is not division!

Languages typically represent both division and integer division with /. The language infers what you mean based on the types of the operands. Integers means to do integer division, while floats means to do floating-point division.

What happens to the fraction? It is typically dropped. In some languages it is rounded down. So sometimes -3/5 is 0 and -3/5 is -1. Check your language if you need to know.

Most languages have the property that a/b*b + a%b = a. Some do not.