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 WAA20506; Fri, 2 Apr 2004 22:32:08 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA22739 for ; Fri, 2 Apr 2004 22:32:07 +0200 (MET DST) Received: from cardinal.mail.pas.earthlink.net (cardinal.mail.pas.earthlink.net [207.217.121.226]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i32KWqjq032352 for ; Fri, 2 Apr 2004 22:32:53 +0200 Received: from user-0cdfqeb.cable.mindspring.com ([24.215.233.203] helo=xp) by cardinal.mail.pas.earthlink.net with smtp (Exim 3.33 #1) id 1B9VKY-0005NK-00; Fri, 02 Apr 2004 12:31:59 -0800 Message-ID: <00a301c418f1$70053170$6401a8c0@xp> From: "Zeno Lee" To: "David Brown" Cc: References: <20040402160514.A29362@beaune.inria.fr> <008101c418ea$3ff43780$6401a8c0@xp> <20040402200759.GA12200@davidb.org> Subject: Re: [Caml-list] weird floating poing behavior on windows Date: Fri, 2 Apr 2004 15:31:11 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; zeno:01 zeno:01 caml-list:01 3.06:01 caml-list:01 2004:99 2004:99 3.07:01 0.26:99 floats:01 floats:01 stdio:01 argc:01 char:01 argv:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 36 This does not happen to me on Solaris from which I do all my ocaml work, but I happened to be using the toplevel on windows as a quick and dirty calculator when I noticed the different behavior. solaris$ ocaml Objective Caml version 3.06 # 0.8 *. 0.7 *. 0.8;; - : float = 0.448 however, when I use your example c program on the same solaris machine it prints out 0.44799999999999995 ----- Original Message ----- From: "David Brown" To: "Zeno Lee" Cc: Sent: Friday, April 02, 2004 3:07 PM Subject: Re: [Caml-list] weird floating poing behavior on windows > 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 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