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 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 0BB3ABC69 for ; Sat, 10 Feb 2007 15:58:56 +0100 (CET) Received: from pih-relay06.plus.net (pih-relay06.plus.net [212.159.14.133]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1AEwtaM007812 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Sat, 10 Feb 2007 15:58:55 +0100 Received: from [80.229.56.224] (helo=[10.0.0.5]) by pih-relay06.plus.net with esmtp (Exim) id 1HFtgl-0008G6-2C for caml-list@yquem.inria.fr; Sat, 10 Feb 2007 14:58:55 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Multiplication of matrix in C and OCaml Date: Sat, 10 Feb 2007 14:52:02 +0000 User-Agent: KMail/1.9.5 References: <45CAF3E2.7020807@univ-paris12.fr> <200702100224.32450.jon@ffconsultancy.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200702101452.02955.jon@ffconsultancy.com> X-Miltered: at concorde with ID 45CDDDAF.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 compiler:01 reals:01 gcc:01 integers:01 posts:01 ocaml:01 reals:01 intersection:01 lambda:01 intersection:01 compiler:01 optimise:01 frog:98 constants:01 On Saturday 10 February 2007 14:41, ls-ocaml-developer-2006@m-e-leypold.de wrote: > Just to be sure: Would the compiler be wrong to optimize > > c * q > c * k > > to just > > q > k > > (all floats). And why? Consider c=0, q=3 and k=2: 0 * 3 > 0 * 2 --> false 3 > 2 --> true It is just mathematically incorrect. > If not, why, in the case above? Floats are not reals, they are just an approximation that happens to be very useful. Floats do not obey the same laws (e.g. associativity). However, programmers may be relying upon this fact, e.g. when doing exact float arithmetic. > I don't want > letter and verse, but a general hand waving in the right direction > would be nice, since I have the impression, that is exactly what Gcc > 4.1. is currently doing (though for the integer case). Ints are completely different because they are exact (as modulo integers). So they do obey the same laws and they do not have special constants (like infinity, neg_infinity, nan, -0. and so on as floats do). Xavier has written some enlightening posts here in the past, regarding the adoption of strict IEEE compliance in OCaml: http://caml.inria.fr/pub/ml-archives/caml-list/2004/10/ffa452944f4bb9827f2cdca552f4f823.en.html For an example of someone using the float constants that lie outside the set of reals, look no further than my ray tracer: http://www.ffconsultancy.com/free/ray_tracer/languages.html I used an initial intersection parameter of lambda=infinity to represent no intersection (or intersecting with the sky). I would be mortified if a compiler decided to optimise away my necessary and working code just because infinity is not in the set of real numbers. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. OCaml for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists