caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Hurt <brian.hurt@qlogic.com>
To: <jeanmarc.eber@lexifi.com>
Cc: <caml-list@inria.fr>
Subject: Re: [Caml-list] float pretty-printing precision, once more.
Date: Mon, 9 Dec 2002 18:07:25 -0600 (CST)	[thread overview]
Message-ID: <Pine.LNX.4.33.0212091804040.2036-100000@eagle.ancor.com> (raw)
In-Reply-To: <1039475060.3df52174c32a4@imp.pro.proxad.net>


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:

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

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


  parent reply	other threads:[~2002-12-10  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-09 23:04 jeanmarc.eber
2002-12-09 23:46 ` Yaron M. Minsky
2002-12-10  0:07 ` Brian Hurt [this message]
2002-12-10  2:13 ` David Chase
2002-12-10  9:49 ` Xavier Leroy
2002-12-10 13:09 ` Damien Doligez
2002-12-10 15:37   ` Jacques Carette
2002-12-10 15:47   ` Xavier Leroy
2002-12-11  4:03     ` David Chase
2002-12-12  1:41       ` David Chase

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.33.0212091804040.2036-100000@eagle.ancor.com \
    --to=brian.hurt@qlogic.com \
    --cc=caml-list@inria.fr \
    --cc=jeanmarc.eber@lexifi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).