Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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.


Bug reports:  FAQ:
To unsubscribe, mail  Archives: