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 RAA10533; Mon, 19 Nov 2001 17:45:04 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA10297 for ; Mon, 19 Nov 2001 17:45:03 +0100 (MET) Received: from penguin.housemarque.fi (www.housemarque.fi [212.213.160.98]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id fAJGj1123205 for ; Mon, 19 Nov 2001 17:45:01 +0100 (MET) Received: from [192.168.42.66] (helo=frodo) by penguin.housemarque.fi with smtp (Exim 3.00 #1) id 165rMe-0004qD-00 for caml-list@inria.fr; Mon, 19 Nov 2001 18:33:44 +0200 Message-ID: <00b601c1711a$01eb97f0$422aa8c0@housemarque.fi> From: "Vesa Karvonen" To: References: <20011109103008.GA22605@rano.org> <20011119164911.B8623@pauillac.inria.fr> Subject: Re: [Caml-list] Integer arithmetic: mod Date: Mon, 19 Nov 2001 18:48:25 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk IIRC, the appendix on arithmetic in Computer Architecture: A Quantitative Approach by Hennessy and Patterson (ISBN: 1558603298) has some rather convincing arguments on the superior definition of integer div and mod. Well worth reading. Regards, Vesa Karvonen ----- Original Message ----- From: "Xavier Leroy" To: "Edmund GRIMLEY EVANS" Cc: Sent: Monday, November 19, 2001 17:49 Subject: Re: [Caml-list] Integer arithmetic: mod > > 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 > ------------------- 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