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 BAA03241; Mon, 6 Aug 2001 01:35:32 +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 BAA03225 for ; Mon, 6 Aug 2001 01:35:31 +0200 (MET DST) Received: from localhost.localdomain (ppp100.dyn146.pacific.net.au [210.23.146.100]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f75NZSb25030 for ; Mon, 6 Aug 2001 01:35:29 +0200 (MET DST) Received: from maxtal.com.au (IDENT:root@localhost [127.0.0.1]) by localhost.localdomain (8.9.3/8.8.7) with ESMTP id JAA04232; Mon, 6 Aug 2001 09:35:15 +1000 Message-ID: <3B6DD833.6030765E@maxtal.com.au> Date: Mon, 06 Aug 2001 09:35:15 +1000 From: John Max Skaller X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.12-20 i686) X-Accept-Language: en MIME-Version: 1.0 To: Kai Kaminski CC: caml-list@inria.fr Subject: Re: [Caml-list] Integer arithmetic: mod References: <20010804124945.A354@alpha2.tabu.stw-bonn.de> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Kai Kaminski wrote: > > Hi, > > I have a question regarding the 'mod' operator in OCaml. While playing > around with the toplevel, I found that > > -1 mod 10 = -1 instead of -1 mod 10 = 9. > 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. Yes you can: it works for non-negative arguments. And you can always roll your own function that works as you desire for negative ones: let mymod x y = if ((x mod y) as r) < 0 then r + y else r which works for negative x provided the result is in the range y .. -1 This way, YOU choose whether you want a deterministic result for non-negative values (use mod, its fast), or are willing to pay extra for determinism for negative values. But I agree with you anyhow. :-) -- John (Max) Skaller, mailto:skaller@maxtal.com.au 10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850 New generation programming language Felix http://felix.sourceforge.net Literate Programming tool Interscript http://Interscript.sourceforge.net ------------------- 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