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 2B179BC48 for ; Mon, 11 Apr 2005 18:15:10 +0200 (CEST) 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 j3BGF9ak006729 for ; Mon, 11 Apr 2005 18:15:09 +0200 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 SAA27658 for ; Mon, 11 Apr 2005 18:15:09 +0200 (MET DST) Received: from ux9.sp.cs.cmu.edu (UX9.SP.CS.CMU.EDU [128.2.220.166]) by concorde.inria.fr (8.13.0/8.13.0) with SMTP id j3BGF8KD023154 for ; Mon, 11 Apr 2005 18:15:09 +0200 Received: from [24.3.154.200] ([24.3.154.200]) by ux9.sp.cs.cmu.edu id aa18638; 11 Apr 2005 12:13 EDT Received: from ecc by stratocaster.home with local (Exim 4.50) id 1DL1Xk-0004Wo-W4 for caml-list@inria.fr; Mon, 11 Apr 2005 12:13:45 -0400 Date: Mon, 11 Apr 2005 12:13:44 -0400 To: caml-list@inria.fr Subject: Re: [Caml-list] ocaml, int32/64, bigarray and unsigned values ... Message-ID: <20050411161344.GB17332@localhost> Mail-Followup-To: caml-list@inria.fr References: <20050411074619.GA26797@pegasos> <20050411125705.GB14415@localhost> <20050411153551.GA10362@pegasos> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050411153551.GA10362@pegasos> User-Agent: Mutt/1.5.6+20040907i From: Eric Cooper X-Miltered: at nez-perce with ID 425AA28D.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 425AA28C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 bigarray:01 sven:01 luther:01 simulate:01 simulate:01 treating:01 silently:01 ...:98 ...:98 wrote:01 integer:01 integer:01 define:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: On Mon, Apr 11, 2005 at 05:35:51PM +0200, Sven Luther wrote: > Now, what about conversion to Int32 or Int64 ? Would an unsigned > Int32 which is represented as a negative signed Int32 not get broken > when used to calculate Int64 values ? You'll have to watch out for sign-extension: when a signed integer is widened, the leading bits get filled with 1s to preserve the sign. That's the wrong behavior if you want to widen an unsigned integer. The Int{32,64} modules don't seem to have of_unsigned_int functions, but you can simulate them by checking if the result is negative and adjusting it (by adding 2^n). > And what about comparisons ? Right, you'll have to define your own, because for example -1 < 0, but you want 0 < 0xFF...FF. You can just test for negative numbers to simulate it yourself (since any negative int is greater than any positive int when treating them as unsigned, otherwise the native int comparison works). > Obviously max_int + 1 > max_int will be wrong since max_int + 1 > would be considered a negative number (-0 maybe ?). Well, max_int + 1 = min_int, but that's what you want when that bit pattern is interpreted as unsigned. The only incorrect results will come from overflow, which silently "wraps around" just like in C. -- Eric Cooper e c c @ c m u . e d u