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 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 C96BFBC0B for ; Fri, 8 Dec 2006 03:37:54 +0100 (CET) Received: from ipmail02.adl2.internode.on.net (ipmail02.adl2.internode.on.net [203.16.214.141]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id kB82bpBl022011 for ; Fri, 8 Dec 2006 03:37:53 +0100 Received: from ppp14-213.lns2.syd7.internode.on.net (HELO rosella) ([59.167.14.213]) by ipmail02.adl2.internode.on.net with ESMTP; 08 Dec 2006 13:07:49 +1030 X-IronPort-AV: i="4.09,511,1157293800"; d="scan'208"; a="57193704:sNHT49611072" Subject: Re: [Caml-list] if (n:int) < 0 then (-n) > 0 is FALSE From: skaller To: Mattias =?ISO-8859-1?Q?Engdeg=E5rd?= Cc: jonathan.roewen@gmail.com, pal_engstad@naughtydog.com, caml-list@inria.fr In-Reply-To: <200612071943.kB7JhC522308@virtutech.se> References: <45785E27.8050804@naughtydog.com> <200612071943.kB7JhC522308@virtutech.se> Content-Type: text/plain; charset=utf-8 Date: Fri, 08 Dec 2006 13:37:46 +1100 Message-Id: <1165545466.6979.20.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Content-Transfer-Encoding: 8bit X-Miltered: at concorde with ID 4578CFFF.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; 0100,:01 mattias:01 bug:01 ocaml:01 compiler:01 statically:01 statically:01 polluting:01 bug:01 integers:01 trade-offs:01 hmmm:01 ocaml:01 slighly:01 31.:98 On Thu, 2006-12-07 at 20:43 +0100, 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.) It can be detected statically? I'd sure like to know how (without polluting the user with hundreds of spurious warnings). > 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. Hmmm. In the usual full word register operations most CPU have an overflow flag which a single conditional branch can detect. Given branch prediction the branch is unlikely to be taken the cost of detection is probably extremely small, provided you have control at the assembler level. Ocaml has slighly messier representation with one less bit, but i guess overflow detection wouldn't be so hard or all that expensive -- but I could be wrong, perhaps someone on Ocaml team has looked at this can can comment? -- John Skaller Felix, successor to C++: http://felix.sf.net