From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL,HTML_MESSAGE autolearn=disabled version=3.1.3 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 22C48BC0B for ; Thu, 7 Dec 2006 21:02:30 +0100 (CET) Received: from janestcapital.com (www.janestcapital.com [66.155.124.107]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id kB7K2SlI004091 for ; Thu, 7 Dec 2006 21:02:29 +0100 Received: from [192.168.250.117] [209.213.205.130] by janestcapital.com with ESMTP (SMTPD-9.10) id A3530C98; Thu, 07 Dec 2006 15:02:27 -0500 Message-ID: <45787353.2040302@janestcapital.com> Date: Thu, 07 Dec 2006 15:02:27 -0500 From: Brian Hurt User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: =?ISO-8859-1?Q?Mattias_Engdeg=E5rd?= Cc: caml-list@inria.fr Subject: Re: [Caml-list] if (n:int) < 0 then (-n) > 0 is FALSE References: <45785E27.8050804@naughtydog.com> <200612071943.kB7JhC522308@virtutech.se> In-Reply-To: <200612071943.kB7JhC522308@virtutech.se> Content-Type: multipart/alternative; boundary="------------010602090306040402090202" X-j-chkmail-Score: MSGID : 45787354.002 on concorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at concorde with ID 45787354.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; mattias:01 bug:01 ocaml:01 compiler:01 statically:01 bug:01 integers:01 trade-offs:01 unboxed:01 bignum:01 integers:01 ocaml:01 mattias:01 compiler:01 statically:01 This is a multi-part message in MIME format. --------------010602090306040402090202 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Mattias Engdegård wrote: >>It's not a bug -- you're relying on 32bit ints when OCaml has only >>31bit ints (on 32-bit arch). In C (for example), if you use a plain >>int (I believe it'll default to signed), you get the exact same >>behaviour when the number overflows 2^31. >> >> > >(Signed overflow is not legal in C (undefined behaviour), and a decent >compiler will warn this can be detected statically.) > >Of course it is a bug - a design bug, since the behaviour is intended >and documented, but still a bug. But getting numbers, even integers, >right in every respect is hard, and involves trade-offs between >performance, correctness and convenience. > >I would love to have a fast unboxed integer type that automatically >overflows to bignum, but it would be a tad slower than the current "int". > > I find it interesting that the languages I know use fixed-size integers (Ocaml, C, C++, Java, C#, Fortran, Pascal) are at or near the top of the great computer language shootout, while the languages I know don't (Perl, Python) are near the bottom. Not that I'm saying that this is the case, it's just an interesting dichotomy. Brian --------------010602090306040402090202 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Mattias Engdegård wrote:
It's not a bug -- you're relying on 32bit ints when OCaml has only
31bit ints (on 32-bit arch). In C (for example), if you use a plain
int (I believe it'll default to signed), you get the exact same
behaviour when the number overflows 2^31.
    

(Signed overflow is not legal in C (undefined behaviour), and a decent
compiler will warn this can be detected statically.)

Of course it is a bug - a design bug, since the behaviour is intended
and documented, but still a bug. But getting numbers, even integers,
right in every respect is hard, and involves trade-offs between
performance, correctness and convenience.

I would love to have a fast unboxed integer type that automatically
overflows to bignum, but it would be a tad slower than the current "int".
  

I find it interesting that the languages I know use fixed-size integers (Ocaml, C, C++, Java, C#, Fortran, Pascal) are at or near the top of the great computer language shootout, while the languages I know don't (Perl, Python) are near the bottom.  Not that I'm saying that this is the case, it's just an interesting dichotomy.

Brian

--------------010602090306040402090202--