From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id E0403BC84 for ; Thu, 24 Mar 2005 23:15:12 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j2OMFCOJ026520 for ; Thu, 24 Mar 2005 23:15:12 +0100 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 XAA19619 for ; Thu, 24 Mar 2005 23:15:12 +0100 (MET) Received: from qrnik.knm.org.pl (paf87.warszawa.sdi.tpnet.pl [217.96.225.87]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j2OMFARZ008640 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Thu, 24 Mar 2005 23:15:11 +0100 Received: from qrczak by qrnik.knm.org.pl with local (Exim 3.36 #1) id 1DEabe-0002yx-00 for caml-list@inria.fr; Thu, 24 Mar 2005 23:15:10 +0100 To: caml-list@inria.fr Subject: Re: [Caml-list] Re: Pervasives.compare output type X-Face: OW>RV&gN+&b-aiNY|U)f=S%w+/rK!);f>/W9IXg})]&F>ht.1Up8@04+_!gOp(_/l_-+E^. 2\vI)1=D,%HWiq)r(M/V~dr^5T^KF/[w5YZ4<0Sus3+O>l3uA/&W_21m?.s,Po8{pb0@ References: <42430B3B.60408@barettadeit.com> <20050324194115.GB9518@furbychan.cocan.org> <87acosu5c9.fsf@qrnik.zagroda> From: "Marcin 'Qrczak' Kowalczyk" Mail-Followup-To: caml-list@inria.fr Date: Thu, 24 Mar 2005 23:15:10 +0100 In-Reply-To: (Bardur Arantsson's message of "Thu, 24 Mar 2005 22:38:39 +0100") Message-ID: <87d5ton11t.fsf@qrnik.zagroda> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: "Marcin 'Qrczak' Kowalczyk" X-Miltered: at nez-perce with ID 42433BF0.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 42433BEE.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 pervasives:01 pervasives:01 integers:01 subtraction:01 integers:01 ocaml:01 ocaml:01 subtraction:01 recursion:01 enumeration:01 enumeration:01 writes:01 define:01 ints:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.2 X-Spam-Level: Bardur Arantsson writes: >>>Wouldn't it be for speed? You could define Pervasives.compare over >>>integers just as a subtraction. >> >> You can't, because of overflow. > > Actually, since integers in OCaml are limited to (n-1) bits where n=32 > or n=64 depending on architecture, overflow shouldn't be a problem. compare must eventually return an OCaml int. It can use subtraction only in its internal recursion, but when presenting the result to OCaml code it can't just pass the result of subtraction. It can use subtraction internally no matter whether the OCaml interface uses intergers whose sign only matters, or an enumeration. And thus there seems to be no performance advantage in using ints instead of the enumeration. In practice it returns -1,0,1 anyway: # compare 10 20;; - : int = -1 -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/