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.3 required=5.0 tests=AWL autolearn=disabled
version=3.1.3
Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104])
by yquem.inria.fr (Postfix) with ESMTP id 205ECBBAF
for ; Sun, 22 Jun 2008 18:56:23 +0200 (CEST)
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: AgABAEYhXkjRVYC/d2dsb2JhbACSKkMBDAMEBAkRA5Z2gy8
X-IronPort-AV: E=Sophos;i="4.27,685,1204498800";
d="scan'208";a="14367445"
Received: from fk-out-0910.google.com ([209.85.128.191])
by mail3-smtp-sop.national.inria.fr with ESMTP; 22 Jun 2008 18:56:22 +0200
Received: by fk-out-0910.google.com with SMTP id k31so2021585fkk.11
for ; Sun, 22 Jun 2008 09:56:22 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=domainkey-signature:received:received:message-id:date:from:to
:subject:mime-version:content-type:content-transfer-encoding
:content-disposition;
bh=Mou5tqMF0h3l2dDIZxp/jAqSnGkz5v75jEbjmPTaz/c=;
b=WcYuUMphvmYGW61vqUIfhrmq8eUO0ccLwmbyJstAogjJeFOhstXEIqz4PDa/NcZhGp
kSq2cjCjnMuOx8I2+O/0NGret95YKgdxHJPBqTEmrJ6MJXZn1AildAiF4+/IFfK7xadj
R4g77f0pwmjhE0fKWRe30S02PIxWA68xoHwmU=
DomainKey-Signature: a=rsa-sha1; c=nofws;
d=gmail.com; s=gamma;
h=message-id:date:from:to:subject:mime-version:content-type
:content-transfer-encoding:content-disposition;
b=np2XDITBrqfANisbp5dkbUrD+EVgxXiNRXCaFEttBoJ2Vy6P+Hsa3K8b4b24QXxxUW
23SGFZH5DxD6vXrZS3C73MFojXhM4T6xa93IGd3rmg3+/4BbAW5QXiNq+2wLGaWkBvQi
x2RtW1qXXfql77b+qHc3m401h+rnfuYQi45sM=
Received: by 10.78.184.14 with SMTP id h14mr2349935huf.98.1214153782260;
Sun, 22 Jun 2008 09:56:22 -0700 (PDT)
Received: by 10.78.47.4 with HTTP; Sun, 22 Jun 2008 09:56:22 -0700 (PDT)
Message-ID: <4b5157c30806220956p164d8346i3e832bc8b8666306@mail.gmail.com>
Date: Sun, 22 Jun 2008 18:56:22 +0200
From: "Paolo Donadeo"
To: "caml-list caml-list"
Subject: Strange behaviour of string_of_float
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
X-Spam: no; 0.00; atan:01 val:01 val:01 serialize:01 printf:01 sprintf:01 1.0:98 behaviour:01 behaviour:01 string:02 string:02 workaround:03 float:03 float:03 let:03
Today I noticed this strange behaviour of string_of_float:
Let's start with:
# let pi = 4.0 *. atan 1.0;;
val pi : float = 3.14159265358979312
# let (|>) x f = f x;;
val ( |> ) : 'a -> ('a -> 'b) -> 'b =
Ok, I want to serialize pi:
# (pi |> string_of_float |> float_of_string) -. pi;;
- : float = 2.06945571790129179e-13
string_of_float is not the inverse of float_of_string, at least in this example.
Is this correct? It's not a problem at all, I used this workaround:
# let my_string_of_float = Printf.sprintf "%.1000g";;
val my_string_of_float : float -> string =
# (pi |> my_string_of_float |> float_of_string) -. pi;;
- : float = 0.
--
Paolo
~
~
:wq