div error

Mark P Jones mpj@cse.ogi.edu
Thu, 6 Jun 2002 07:54:19 -0700


Hi Jerzy,

|  > div 1 (-2)
|  -1
|  > div (-1) 2
|  -1
|  
|  but
|  > div (-1) (-2)
|  0
|  > div 1 2
|  0
|  > div 0 (-2)
|  0

No errors here.  Check the Haskell report for properties of div:

  "The quot, rem, div, and mod class methods satisfy these laws: 

      (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."

Perhaps you were expecting div to be like quot?

All the best,
Mark