From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA19340; Fri, 2 Apr 2004 22:08:03 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA19411 for ; Fri, 2 Apr 2004 22:08:01 +0200 (MET DST) Received: from mail.davidb.org (adsl-64-172-240-129.dsl.sndg02.pacbell.net [64.172.240.129]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i32K80YM026109 for ; Fri, 2 Apr 2004 22:08:01 +0200 Received: from davidb by mail.davidb.org with local (Exim 3.36 #1 (Debian)) id 1B9UxL-0003CK-00; Fri, 02 Apr 2004 12:07:59 -0800 Date: Fri, 2 Apr 2004 12:07:59 -0800 From: David Brown To: Zeno Lee Cc: caml-list@inria.fr Subject: Re: [Caml-list] weird floating poing behavior on windows Message-ID: <20040402200759.GA12200@davidb.org> References: <20040402160514.A29362@beaune.inria.fr> <008101c418ea$3ff43780$6401a8c0@xp> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <008101c418ea$3ff43780$6401a8c0@xp> User-Agent: Mutt/1.5.4i X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 caml-list:01 2004:99 zeno:01 3.07:01 0.26:99 floats:01 floats:01 stdio:01 argc:01 char:01 argv:01 printf:01 0.26:99 printf:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 34 On Fri, Apr 02, 2004 at 02:39:43PM -0500, Zeno Lee wrote: > Can anyone tell me what's going on here? Is this a known issue on windows? > > C:\>ocaml > Objective Caml version 3.07+2 > # 0.2 *. 0.26;; > - : float = 0.052000000000000005 > # 0.8 *. 0.7 *. 0.8;; > - : float = 0.44799999999999995 Nothing unusual. Floats only have a certain amount of precision. The toplevel prints floats out with more precision than they contain. It does the same thing on Linux. For example, in C: #include int main (int argc, char **argv) { printf ("%.17g\n", 0.2 * 0.26); printf ("%.17g\n", 0.8 * 0.7 * 0.8); return 0; } prints: 0.052000000000000005 0.44799999999999995 Now the real question is why does the toplevel do this (and where, in the code is it coming from). string_of_float only uses 12 digits. Dave Brown ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners