From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA09100; Mon, 19 Nov 2001 16:49:23 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA09136 for ; Mon, 19 Nov 2001 16:49:22 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id fAJFnCb28216; Mon, 19 Nov 2001 16:49:12 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA09181; Mon, 19 Nov 2001 16:49:11 +0100 (MET) Date: Mon, 19 Nov 2001 16:49:11 +0100 From: Xavier Leroy To: Edmund GRIMLEY EVANS Cc: caml-list@inria.fr Subject: Re: [Caml-list] Integer arithmetic: mod Message-ID: <20011119164911.B8623@pauillac.inria.fr> References: <20011109103008.GA22605@rano.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20011109103008.GA22605@rano.org>; from edmundo@rano.org on Fri, Nov 09, 2001 at 10:30:08AM +0000 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > I strongly advise against leaving the meaning of any built-in or > library function or operator as implementation-defined. If you do this > you will get unportable programs and inefficient programs (because > people who want their programs to be portable will be forced to define > their own versions of the functions). I can agree with this argument. > In my opinion and in most people's opinion, as far as I can tell, if > you're starting afresh, the best way to define integer division is as > rounding downwards. Integer remainder, to be consistent with this, has > the sign of the divisor. There are lots of arguments that support this > type of division, both mathematical and practical, and the only > arguments against it seem to involve compatibility: the other sort of > division is faster on some widely used hardware, is required by some > widely used programming languages and assumed by some existing > software. Well, all hardware today implements round-towards-zero for division, and this is unlikely to change in the future since ISO C9x requires this behavior, so this will remain the behavior of "/" in OCaml. We certainly do not want to penalize the existing programs that use "/" and "mod" correctly, i.e. on positive arguments. I'm favorable to providing proper Euclidean division and modulus as library functions. But: I disagree with your statement that > the best way to define integer division is as > rounding downwards. Integer remainder, to be consistent with this, has > the sign of the divisor. The way I learned Euclidean division in college is that the quotient q and the modulus r of a divided by b are defined by a = b * q + r with 0 <= r < |b| e.g. the modulus is never negative, and division does not necessarily rounds downwards. I believe what mathematically-oriented minds really want is a modulus that is always positive. Any mathematician on this list who could look it up in Bourbaki? - Xavier Leroy ------------------- 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