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 SAA17557; Thu, 30 Sep 2004 18:54:00 +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 SAA17398 for ; Thu, 30 Sep 2004 18:53:59 +0200 (MET DST) Received: from mail-yellow.research.att.com (mail-dark.research.att.com [192.20.225.112]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i8UGrwu8010727 for ; Thu, 30 Sep 2004 18:53:58 +0200 Received: from research.att.com (lt-mff.research.att.com [135.207.20.80]) by bigmail.research.att.com (8.11.6+Sun/8.11.6) with ESMTP id i8UGrv415349; Thu, 30 Sep 2004 12:53:57 -0400 (EDT) Message-ID: <415C39EE.7090606@research.att.com> Date: Thu, 30 Sep 2004 12:53:02 -0400 From: mff User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114 X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@inria.fr, mff@research.att.com Subject: [Caml-list] Printing floating point numbers & precision Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 415C3A26.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; mff:99 mff:99 usr:01 3.07:01 printf:01 sprintf:01 printf:01 sprintf:01 bin:01 ocaml:01 caml:01 float:02 float:02 string:03 string:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Greetings, I have a question regarding the printing of floating point numbers. Here's an example: lt-mff: /usr/bin/ocaml Objective Caml version 3.07+2 # max_float;; - : float = 1.79769313486231571e+30 # Printf.sprintf "%e" max_float;; - : string = "1.797693e+308" So using the default %e format to print a floating point number loses 11 digits of precision. I could be more precise about the number of fractional digits: # Printf.sprintf "%.17e" max_float;; - : string = "1.79769313486231571e+308" But this does not seem to work in general: # Printf.sprintf "%.17e" 12345.1;; - : string = "1.23451000000000004e+04" I've combed the documentation to try to understand the relationship between printing and precision (and accuracy!) but have come up empty handed. Help is appreciated! Thanks, Mary ------------------- 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