Behaviour of div & mod with negative arguments?

Dr Mark H Phillips mark@austrics.com.au
25 Sep 2002 16:56:35 +0930


Hi,

Does Haskell specify how div and mod should behave when
given one or both arguments negative?

Eg, in hugs we get:

div   1    3  = 0
div (-1)   3  = -1
div   1  (-3) = -1
div (-1) (-3) = 0

and so on.

I've had a bit of a look for where div and mod are
specified exactly, but I can only find a definition of
their type.  Are they defined anywhere?  And what is
the rational behind the negative arguments part of
the definition?

Thanks,

Mark.

P.S.  I notice in hugs if I type "-1 `div` 3" the `div`
binds to the 1 and 3 first, and only applies the "-"
at the end.  Is there a reason why the unary "-" has
weak binding?

-- 
Dr Mark H Phillips
Research Analyst (Mathematician)

AUSTRICS - smarter scheduling solutions - www.austrics.com

Level 2, 50 Pirie Street, Adelaide SA 5000, Australia
Phone +61 8 8226 9850
Fax   +61 8 8231 4821
Email mark@austrics.com.au