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: Marcin 'Qrczak' Kowalczyk <qrczak@k...>
Subject: Re: [Caml-list] Integer arithmetic: mod
Sat, 04 Aug 2001 11:48:07 -0700, Chris Hecker <checker@d6.com> pisze:

> Most computer languages (and chips) simply say "(a/b)*b + a mod b =
> a" and leave it at that.

Fortunately not all, e.g. in Python (-123) % 10 == 7. In C89 the
behavior for negative numbers was left implementation-defined but
in C99 it is specified as truncation towards 0.

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

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

-- 
 __("<  Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK

-------------------
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