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 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 6A5B0BC69 for ; Sat, 10 Feb 2007 01:58:59 +0100 (CET) Received: from bsd4.nyct.net (mail-out4.nyct.net [216.139.141.4]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1A0wvln020435 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 10 Feb 2007 01:58:59 +0100 Received: from [216.139.138.9] ([216.139.138.9]) by bsd4.nyct.net (8.13.4/8.13.4) with ESMTP id l1A0wl3k039407; Fri, 9 Feb 2007 19:58:53 -0500 (EST) (envelope-from bhurt@spnz.org) Date: Fri, 9 Feb 2007 20:10:26 -0500 (EST) From: Brian Hurt X-X-Sender: bhurt@localhost To: Andrej.Bauer@andrej.com Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Multiplication of matrix in C and OCaml In-Reply-To: <45CCEDD8.3080907@fmf.uni-lj.si> Message-ID: References: <45CAF3E2.7020807@univ-paris12.fr> <45CAFF5A.2020607@inria.fr> <45CB3ED0.9040200@univ-paris12.fr> <20070209.115842.106265091.garrigue@math.nagoya-u.ac.jp> <1171030953.5302.51.camel@rosella.wigram> <9e4ppv6m15.fsf@hod.lan.m-e-leypold.de> <45CCEDD8.3080907@fmf.uni-lj.si> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at discorde with ID 45CD18D1.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 andrej:01 associative:01 bool:01 reordering:01 sqrt:01 2007,:98 1.3:98 2.1:98 1.3:98 2.1:98 suck:98 wrote:01 caml-list:01 binary:01 On Fri, 9 Feb 2007, Andrej Bauer wrote: > I hate to add to this long discussion, but since when is floating point > multiplication associative? > > # 1.3 *. (0.7 *. 2.1) = (1.3 *. 0.7) *. 2.1 ;; > - : bool = false Round off error. You can't represent numbers like 7/10 or 13/10 in binary precisely in a finite number of digits, any more than you can represent the numbers 1/3 or 4/7 precisely in base-10 in a finite number of digits. This is a fundamental problem with floating point numbers, and shows up in every language that has them. But this means reordering the calculations will result in slightly different answers. And no, most of the "obvious" solutions don't work. Using rational arithmetic doesn't help if I ask you to calculate the euclidean length of the vector (1, 1) for example (hint: sqrt (1.*.1. +. 1.*.1.)). Interval arithmetic fails miserably on simple algorithms like Newton's method. And so on. On the other hand, the precision given by double precision floating point numbers is generally more than enough- they're precise enough to hold the distance from here to the moon in microns, for example. My advice: if you're doing much of anything with floating point numbers, get a book on numerical analysis and follow the algorithms and recommendations it gives you (any book except "Numerical Recipies", which suck). And don't use floating point for money. Brian