From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id D1BAEBBAF for ; Mon, 23 Jun 2008 10:32:55 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AugEACT8Xkg+FFrDTmdsb2JhbACSYQEBGhwFnQM X-IronPort-AV: E=Sophos;i="4.27,689,1204498800"; d="scan'208";a="12433201" Received: from oden.vtab.com ([62.20.90.195]) by mail2-smtp-roc.national.inria.fr with ESMTP; 23 Jun 2008 10:32:55 +0200 Received: from oden.vtab.com (oden.vtab.com [127.0.0.1]) by oden.vtab.com (Postfix) with ESMTP id 9235126F65B; Mon, 23 Jun 2008 10:32:54 +0200 (CEST) Received: from kicki.hq.vtech (kicki.hq.vtech [10.0.0.211]) by oden.vtab.com (Postfix) with ESMTP id 7F3E526EF84; Mon, 23 Jun 2008 10:32:54 +0200 (CEST) Received: by kicki.hq.vtech (Postfix, from userid 7557) id 7901F82040; Mon, 23 Jun 2008 10:32:54 +0200 (CEST) From: "=?utf-8?b?TWF0dGlhcyBFbmdkZWfDpQ==?= =?utf-8?b?cmQ=?=" To: p.donadeo@gmail.com Cc: caml-list@yquem.inria.fr In-reply-to: <4b5157c30806221345p9be5daeqc65b3f6cfb3219b3@mail.gmail.com> (p.donadeo@gmail.com) Subject: Re: [Caml-list] Strange behaviour of string_of_float References: <4b5157c30806220956p164d8346i3e832bc8b8666306@mail.gmail.com> <20080622195831.GA22384@annexia.org> <4b5157c30806221345p9be5daeqc65b3f6cfb3219b3@mail.gmail.com> Message-Id: <20080623083254.7901F82040@kicki.hq.vtech> Date: Mon, 23 Jun 2008 10:32:54 +0200 (CEST) X-Virus-Scanned: ClamAV using ClamSMTP X-Spam: no; 0.00; mattias:01 mattias:01 ocaml:01 ocaml's:01 printf:01 notation:01 interchange:98 ccs:01 readable:01 caml-list:01 behaviour:01 neu:02 binary:02 binary:02 slower:02 >My intent is to extract an ASCII representation of an OCaml float >value so that it can be used to recreate *exactly* the same value, at >least on the same architecture. A somewhat more portable (and readable, maybe) representation of floating-point numbers is in hex (a la C99). It is independent of the precision and binary format used. Unfortunately, ocaml's Printf has already appropriated %a for a different purpose, but it remains a good option for those willing to do some manual work. I have used it in the past to good effect in text-based interchange formats between applications written in C. Of course the decimal notation can unambiguously represent any (binary) floating-point number, so that representation is fine if you have confidence in the output and reading routines. See, for instance, William Clinger's _How to Read Floating Point Numbers Accurately_ (http://ftp.ccs.neu.edu/pub/people/will/retrospective.pdf). But decimal handling will always be a little slower.