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 DB67BBC84 for ; Thu, 24 Mar 2005 21:31:27 +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 j2OKVRMw017439 for ; Thu, 24 Mar 2005 21:31:27 +0100 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 VAA17362 for ; Thu, 24 Mar 2005 21:31:26 +0100 (MET) Received: from smtp01.isp.itmonitor.net (smtp01.isp.itmonitor.net [207.158.33.182]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j2OKVPUn017431 for ; Thu, 24 Mar 2005 21:31:26 +0100 Received: from tfb.com (host-66-81-192-96.rev.o1.com [66.81.192.96]) by smtp01.isp.itmonitor.net (Postfix) with ESMTP id 71C99A5CBFB; Thu, 24 Mar 2005 12:31:25 -0800 (PST) Message-ID: <4243239B.1050300@tfb.com> Date: Thu, 24 Mar 2005 12:31:23 -0800 From: Ken Rose Reply-To: rose@acm.org User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030703 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 4243239F.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 4243239D.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 wrote:01 int:01 int:01 string:03 string:03 float:03 float:03 library:03 bits:04 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO 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 ? Maybe Int64.bits_of_float and Int64.float_of_bits will do what you need. - ken