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=none 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 71FF2BC0B for ; Thu, 7 Dec 2006 19:34:47 +0100 (CET) Received: from sdmx1.scea.com (sdmx1.scea.com [160.33.44.36]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id kB7IYjU8012556 for ; Thu, 7 Dec 2006 19:34:46 +0100 Received: from edenfox.989studios.com (edenfox.989studios.com [160.33.45.60]) by sdmx1.scea.com (8.13.6/8.13.1) with ESMTP id kB7IYg6x018154 for ; Thu, 7 Dec 2006 10:34:42 -0800 X-Envelope-From: X-Envelope-To: Received: from postal1-dog.naughtydog.com (testmail.naughtydog.com [10.15.0.5]) by edenfox.989studios.com (8.13.7/8.13.7/SCEAint-1.0) with ESMTP id kB7IYagE010398 for ; Thu, 7 Dec 2006 10:34:38 -0800 Received: from [127.0.0.1] ([150.0.5.1]) by postal1-dog.naughtydog.com with Microsoft SMTPSVC(6.0.3790.1830); Thu, 7 Dec 2006 10:33:40 -0800 Message-ID: <45785E27.8050804@naughtydog.com> Date: Thu, 07 Dec 2006 10:32:07 -0800 From: Pal-Kristian Engstad User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) MIME-Version: 1.0 To: caml-list@inria.fr Subject: if (n:int) < 0 then (-n) > 0 is FALSE Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-OriginalArrivalTime: 07 Dec 2006 18:33:40.0649 (UTC) FILETIME=[37922190:01C71A2E] X-Scanned-By: MIMEDefang 2.48 on 160.33.44.36 X-Scanned-By: MIMEDefang 2.48 on 160.33.45.59 X-BorderEnvelope-To: X-Miltered: at concorde with ID 45785EC5.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 3.08.3:01 bug:01 pke:01 1.0:98 1.0:98 dog:98 rec:01 int:01 loops:02 loops:02 represented:02 silently:02 pal-kristian:03 let:03 Using OCaml 3.08.3 on the following function: let pow x n = let rec aux x n acc = if n == 0 then acc else if n == 1 then acc *. x else if n land 1 == 0 then aux (x*.x) (n/2) acc else aux (x*.x) ((n-1)/2) (x*.acc) in if n >= 0 then aux x n 1.0 else 1.0 /. (aux x (-n) 1.0) ;; I tested this function with # pow 1.0 (1024 * 1024 * 1024) To find that it loops forever. The reason is that 1024*1024*1024=2^30 cannot be represented as a positive number on 32-bit platforms, hence it silently converts it to -1073741824, or -2^30. The reason this loops again is that -n = -(-20^30) = -20^30......, still negative! This is obviously a bug - has it since been fixed? But more alarmingly - why is there no warning? Thanks, PKE. -- Pål-Kristian Engstad (engstad@naughtydog.com), Lead Programmer, ICE team, Naughty Dog, Inc., 1601 Cloverfield Blvd, 6000 North, Santa Monica, CA 90404, USA. Ph.: (310) 633-9112. "Most of us would do well to remember that there is a reason Carmack is Carmack, and we are not Carmack.", Jonathan Blow, 2/1/2006, GD Algo Mailing List