concept rem in category clojure

appears as: rem
Clojure: The Essential Reference

This is an excerpt from Manning's book Clojure: The Essential Reference.

In the Euclidean division (the process of division of two integers [108]) the "quotient" is the result of the division while the "remainder" is anything that is left when the two numbers are not multiple of each other. In Clojure quot returns the result of dividing the numbers while rem returns the rest of the integer division, if any. The quotient can also be defined as the number of times the divisor divides "num", excluding any fractional part which is equivalent in turn to take the result of the division and truncate the decimals. Finally, the "modulus" operation mod is very similar to rem but with slightly different rules regarding how to return results in the presence of negative numbers [109]. So for example:

(quot 38 4)
;; 9

(rem 38 4)
;; 2

The above means that the number "4" (the divisor) sums up 9 times before being larger than the dividend "38". The remainder of the operation would be 2. This description is not very rigorous because things get hairy when negatives numbers are involved. This is where mod and rem differs:

(rem -38 4)
;; -2

(mod -38 4)
;; 2

We won’t go into the glory details of rem and mod for negative numbers since the most common uses for real-world applications are around positive quantities.