More on integer division

Dylan Thurston dpt at lotus.bostoncoop.net
Mon Jul 1 15:21:49 EDT 2002


On Mon, Jul 01, 2002 at 12:51:52PM +0100, Simon Marlow wrote:
> 
> > > I'm shocked that non of the three Haskell implementations had a test
> > > suite that caught this problem.
> > 
> > Take a look at
> > fptools/testsuite/tests/ghc-regress/numeric/should_run/arith0011.hs.
> > There may be one or two wrong answers lurking in there, but 
> > that's a lot
> > of results to check by hand!

However, it's easy to write a program to verify such results, assuming
you trust your addition and multiplication and comparisons:

> verifyDivMod :: Integer -> Integer -> Bool
> verifyDivMod x y = case x `divMod` y of
>    (d,m) -> d*y+m==x && (m == 0 || signum m == signum y)

> verifyQuotRem :: Integer -> Integer -> Bool
> verifyQuotRem x y = case x `divMod` y of
>    (d,m) -> d*y+m==x && (m == 0 || signum m == signum x)

But maybe that doesn't fit in too well with your framework.

Also, looking at arith003, there are a few more test cases I might
include, with quotient/remainder, say, 3/4 or 1/2 of maxInt.  You also
don't seem to test arithmetic with large negative operands in the
cases I saw.
 
Best,
	Dylan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20020701/402fc8b9/attachment.bin


More information about the Glasgow-haskell-bugs mailing list