3 ms·
Haskell supports both. The documentation explains the two pretty clearly, IMO: quot :: a -> a -> a integer division truncated toward zero rem
by kccqzy 8y ago
Haskell supports both. The documentation explains the two pretty clearly, IMO:
quot :: a -> a -> a
integer division truncated toward zero
rem :: a -> a -> a
integer remainder, satisfying
(x `quot` y)*y + (x `rem` y) == x
div :: a -> a -> a
integer division truncated toward negative infinity
mod :: a -> a -> a
integer modulus, satisfying
(x `div` y)*y + (x `mod` y) == x
Here's an example
ghci> (-340) `divMod` 60
(-6,20)
ghci> (-340) `quotRem` 60
(-5,-40)
- thaumasiotes 8y ago> integer division truncated toward negative infinity Truncated?