Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Integer arithmetic: mod
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Chris Hecker <checker@d...>
Subject: Re: [Caml-list] Integer arithmetic: mod

> > Unfortunately, people (and language and chip designers) assume
> > (-4)/3 = -1 (truncate towards zero) rather than -2 (floor),
> Not all people: Donald Knuth clearly disagrees. He has written
> something along the lines "beware of programming languages which use
> a different definition than the one which says (-4)/3 = -2".

Yeah, Concrete Mathematics by Knuth, Graham, and Patashnik is the
bible for this sort of thing.

> Haskell has both: div & mod truncate downwards, quot & rem truncate
> towards 0.

Ah, that's a good idea, although I'd assume the div floor behavior is
surprising at first.

Chris


-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr