Integral operators quot vs. div

To quote section 6.4.2 from the Haskell report:

The quot, rem, div, and mod class methods satisfy these laws if y is non-zero:

(x `quot` y)*y + (x `rem` y) == x  
(x `div`  y)*y + (x `mod` y) == x

quot is integer division truncated toward zero, while the result of div is truncated toward negative infinity.

The div function is often the more natural one to use, whereas the quot function corresponds to the machine instruction on modern machines, so it’s somewhat more efficient.

Leave a Comment