2 ms·
That's an inherent property of both the modulus interpretation and the remainder interpretation. Haskell does it right. Instead of having operators like %, it
by kccqzy 4y ago
That's an inherent property of both the modulus interpretation and the remainder interpretation.
Haskell does it right. Instead of having operators like %, it gives the programmer choice to choose either the modulus or the remainder. Using GP's example:
ghci> 2 `div` (-5)
-1
ghci> 2 `mod` (-5)
-3
ghci> 2 `quot` (-5)
0
ghci> 2 `rem` (-5)
2
And we have both (x `quot` y)*y + (x `rem` y) == x and (x `div` y)*y + (x `mod` y) == x