<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/12/167a6c6cd1366f96e94bab06a3535858"
  from="Brian Hurt &lt;brian.hurt@q...&gt;"
  author="Brian Hurt"
  date="2002-12-10T00:00:02"
  subject="Re: [Caml-list] float pretty-printing precision, once more."
  prev="2002/12/dccc53828aa05cb7b933659d7f8e9852"
  next="2002/12/bda14d3a04f2eedf91905a4eb42a9207"
  prev-in-thread="2002/12/3cb94c391a4d8d5c79e7a099c28800da"
  next-in-thread="2002/12/a35e9a667edfd52c36feaaab51a66de6"
  prev-thread="2002/12/4f26c91200b871153ac571f4e71c7d1f"
  next-thread="2002/12/b842fa0bde343ece5699d91c444d6e07"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] float pretty-printing precision, once more.">
<msg 
  url="2002/12/303524700573103127c46d2209d89f49"
  from="jeanmarc.eber@l..."
  author="jeanmarc.eber@l..."
  date="2002-12-09T23:24:23"
  subject="[Caml-list] float pretty-printing precision, once more.">
<msg 
  url="2002/12/3cb94c391a4d8d5c79e7a099c28800da"
  from="Yaron M. Minsky &lt;yminsky@C...&gt;"
  author="Yaron M. Minsky"
  date="2002-12-09T23:48:55"
  subject="Re: [Caml-list] float pretty-printing precision, once more.">
</msg>
<msg 
  url="2002/12/167a6c6cd1366f96e94bab06a3535858"
  from="Brian Hurt &lt;brian.hurt@q...&gt;"
  author="Brian Hurt"
  date="2002-12-10T00:00:02"
  subject="Re: [Caml-list] float pretty-printing precision, once more.">
</msg>
<msg 
  url="2002/12/a35e9a667edfd52c36feaaab51a66de6"
  from="David Chase &lt;chase@w...&gt;"
  author="David Chase"
  date="2002-12-10T02:14:16"
  subject="Re: [Caml-list] float pretty-printing precision, once more.">
</msg>
<msg 
  url="2002/12/197abbf7c374b28868a0af7fcee97f38"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2002-12-10T09:49:32"
  subject="Re: [Caml-list] float pretty-printing precision, once more.">
</msg>
<msg 
  url="2002/12/560c45075f7edea334c281d5649ef2ac"
  from="Damien Doligez &lt;damien.doligez@i...&gt;"
  author="Damien Doligez"
  date="2002-12-10T13:09:40"
  subject="Re: [Caml-list] float pretty-printing precision, once more.">
<msg 
  url="2002/12/df3aadefe9a8021d30aa32f5dcc94da0"
  from="Jacques Carette &lt;carette@m...&gt;"
  author="Jacques Carette"
  date="2002-12-10T15:37:20"
  subject="RE: [Caml-list] float pretty-printing precision, once more.">
</msg>
<msg 
  url="2002/12/2740972965db19b54afe531bdddfb74d"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2002-12-10T15:47:23"
  subject="Re: [Caml-list] float pretty-printing precision, once more.">
<msg 
  url="2002/12/2813f8e8be115b0bad1bc16b1e41b744"
  from="David Chase &lt;chase@w...&gt;"
  author="David Chase"
  date="2002-12-11T04:04:00"
  subject="Re: [Caml-list] float pretty-printing precision, once more.">
<msg 
  url="2002/12/4148c2e4e503a36460efef0369cc042f"
  from="David Chase &lt;chase@w...&gt;"
  author="David Chase"
  date="2002-12-12T01:41:48"
  subject="Re: [Caml-list] float pretty-printing precision, once more.">
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>

This looks just like rounding error to me.  I note that the string output 
has only 12 signifigant digits- and the error is, coincidentally enough, 
right about f * 10e-12.

But then, I'm not an expert in IEEE FP either...

Brian

On Tue, 10 Dec 2002 jeanmarc.eber@lexifi.com wrote:

&gt; caml 3.06+1:  
&gt;    
&gt; # let f = 1. /. 86400.;;   
&gt; val f : float = 1.15740740741e-05   
&gt; # let s = string_of_float f;;   
&gt; val s : string = "1.15740740741e-05"   
&gt; # let f1 = float_of_string s;;   
&gt; val f1 : float = 1.15740740741e-05   
&gt; # f1 = f;;   
&gt; - : bool = false   
&gt; # f1 -. f;;   
&gt; - : float = 2.59259844496e-17   
&gt;   
&gt; This situation may be understandable, but is unfortunate.  
&gt;   
&gt; Disclaimer: I'm not a specialist of the IEEE float format.  
&gt;   
&gt; Do I have at hand, at least on an architecture supporting the IEEE format, a  
&gt; function that pretty-prints any valid float value (by valid I mean that I  
&gt; exclude the "special" values like NaN, infinity, etc.) so that  
&gt; float_of_string applied to the resulting string returns my initial value,  
&gt; or, at least, a value that, if substracted from my initial one, returns  
&gt; zero ?  
&gt;   
&gt; Background:  
&gt;   
&gt; In fact, my question goes a little bit further, as it concerns indeed the  
&gt; parsing of floats in the caml compiler (that uses internally float_of_string  
&gt; if I'm correct).  
&gt;   
&gt; Suppose you calculate somewhere (with an caml program, say) a float  
&gt; constant (such a calculation may last for hours!), and you want after  
&gt; obtaining the result to *generate* a caml source using this calculated  
&gt; value. You will probably generate something like  
&gt;   
&gt; let my_const = &lt;a float text representation&gt;  
&gt;   
&gt; But my example shows that you are loosing precision and accuracy if you  
&gt; just use string_of_float. 
&gt;   
&gt; Of course the goal is to incorporate this value in a caml source, not  
&gt; to read it in binary form from a file (that would be easy!).  
&gt;   
&gt; Do anybody know a solution to my problem ?  
&gt;   
&gt; Jean-Marc Eber  
&gt;   
&gt; -------------------
&gt; To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
&gt; Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
&gt; Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
&gt; 

-------------------
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

</contents>

</message>

