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 VAA22461; Sat, 4 Aug 2001 21:03:36 +0200 (MET DST) 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 VAA22457 for ; Sat, 4 Aug 2001 21:03:35 +0200 (MET DST) Received: from pltn13.pbi.net (mta7.pltn13.pbi.net [64.164.98.8]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f74J3Yn28603 for ; Sat, 4 Aug 2001 21:03:35 +0200 (MET DST) Received: from checkerlap.d6.com ([64.160.54.87]) by mta7.pltn13.pbi.net (iPlanet Messaging Server 5.1 (built May 7 2001)) with ESMTP id <0GHK007B64XX6J@mta7.pltn13.pbi.net> for caml-list@inria.fr; Sat, 04 Aug 2001 12:03:33 -0700 (PDT) Date: Sat, 04 Aug 2001 11:48:07 -0700 From: Chris Hecker Subject: Re: [Caml-list] Integer arithmetic: mod In-reply-to: <20010804124945.A354@alpha2.tabu.stw-bonn.de> X-Sender: def6@shell16.ba.best.com To: Kai Kaminski , caml-list@inria.fr Message-id: <4.3.2.7.2.20010804112143.02842100@shell16.ba.best.com> MIME-version: 1.0 X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Now, I could live with -1 mod 10 = -1, but why is it platform-dependent? There are two ways to define mod for negative numbers. They're both mathematically valid (meaning you can write equations with them both). Most computer languages (and chips) simply say "(a/b)*b + a mod b = a" and leave it at that. Unfortunately, people (and language and chip designers) assume (-4)/3 = -1 (truncate towards zero) rather than -2 (floor), and that seals the fate of (-4) mod 3 to be -1 instead of 2. Here's a good discussion: http://forum.swarthmore.edu/dr.math/problems/anne.4.28.99.html >The reason is that whenever such a behaviour is platform-dependent, you >can't use it at all, as long as you want to have your programs portable. >Beside that the speed penalty (are there other problems with this >approach?) would probably be not too bad, would it? I think caml did the right thing (just let the cpu do it) with a bad situation (inconsistencies). You're free to define your own versions if the built in ones don't work for you, and this doesn't penalize everybody (some people like the "remainder" result rather than the "floor" result). 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