From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 03177BC84 for ; Thu, 24 Mar 2005 21:38:25 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j2OKcOI8017958 for ; Thu, 24 Mar 2005 21:38:24 +0100 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 VAA17226 for ; Thu, 24 Mar 2005 21:38:24 +0100 (MET) Received: from smtp815.mail.sc5.yahoo.com (smtp815.mail.sc5.yahoo.com [66.163.170.1]) by concorde.inria.fr (8.13.0/8.13.0) with SMTP id j2OKcMb9030769 for ; Thu, 24 Mar 2005 21:38:23 +0100 Received: from unknown (HELO ?192.168.1.100?) (rftp@pacbell.net@63.194.18.166 with plain) by smtp815.mail.sc5.yahoo.com with SMTP; 24 Mar 2005 20:38:21 -0000 Message-ID: <42432589.2020306@rftp.com> Date: Thu, 24 Mar 2005 12:39:37 -0800 From: Robert Roessler Organization: Robert's High-performance Software User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050319 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Christophe Raffalli Cc: caml-list Subject: Re: [Caml-list] float printing References: <42432108.2040801@univ-savoie.fr> In-Reply-To: <42432108.2040801@univ-savoie.fr> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 42432540.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4243253E.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 christophe:01 raffalli:01 printf:01 pervasives:01 pervasives:01 val:01 val:01 rounding:01 wrote:01 integer:01 int:01 int:01 string:03 string:03 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: Christophe Raffalli wrote: > I have a small problem to read and write float in a file. I use the > format library and there is no way to write/read a float in hexadecimal > to be sure you read exactly the same float back from the file (a n bits > mantisse float may need n decimals to have an exact representation. > Just compute 1/2^n and count decimals). > > The only way is to convert the float to string via Printf and then print > the string with Format.print_string. > > Don't you think Pervasives and format should have a write/print_hexfloat > and Pervasives should have an input_hexfloat function ? How about the Int64 module? val bits_of_float : float -> int64 This gives the exact "bits" for the IEEE double-precision float. val float_of_bits : int64 -> float This "reconstitutes" the float from the supplied 64-bit "integer". There are also Int32-based versions of these, but with obviously lower precision - and the rounding method used to obtain Int32.bits_of_float is not specified. Robert Roessler roessler@rftp.com http://www.rftp.com