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 QAA10700; Tue, 10 Dec 2002 16:47:23 +0100 (MET) 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 QAA10652 for ; Tue, 10 Dec 2002 16:47:22 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id gBAFlLX00583; Tue, 10 Dec 2002 16:47:21 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA20665; Tue, 10 Dec 2002 16:47:21 +0100 (MET) Date: Tue, 10 Dec 2002 16:47:21 +0100 From: Xavier Leroy To: Damien Doligez Cc: caml-list@inria.fr Subject: Re: [Caml-list] float pretty-printing precision, once more. Message-ID: <20021210164721.C7440@pauillac.inria.fr> References: <1039475060.3df52174c32a4@imp.pro.proxad.net> <97FCFA94-0C40-11D7-B751-0003930FCE12@inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <97FCFA94-0C40-11D7-B751-0003930FCE12@inria.fr>; from damien.doligez@inria.fr on Tue, Dec 10, 2002 at 02:09:19PM +0100 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > [string_of_float loses precision on floating-point numbers] > In the current working version (3.06+18), the precision used by > string_of_float has been increased to 17 digits. Yes, this was my feeble attempt to work around the precision loss using only what is available, i.e. sprintf. However, as you say: > However, it has the unfortunate side-effect of revealing this > awful truth about FP numbers: many "interesting" numbers are > impossible to represent in floating-point. For example: > > # 0.1;; > - : float = 0.10000000000000001 > > There is no floating-point number equal to 0.1 and the > best approximation you can get is 0.10000000000000001. If that was really the best approximation, there would be nothing to argue. But both 0.10000000000000001 and 0.1 read back as identical floats, so the latter should be printed instead, but sprintf (on Linux at least) is too stupid to realize this. - Xavier Leroy ------------------- 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