From: David Chase <chase@world.std.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] string_of_float less accurate than sprintf "%f" ?
Date: Thu, 02 May 2002 09:28:51 -0400 [thread overview]
Message-ID: <5.1.0.14.0.20020502085732.01f16fd0@pop.theWorld.com> (raw)
In-Reply-To: <3CD134B0.8050100@ozemail.com.au>
At 10:44 PM 5/2/2002 +1000, John Max Skaller wrote:
>Beck01, Wolfgang wrote:
>
>>while doing some time measurements with Unix.gettimeofday() I
>>discovered a problem with string_of_float:
>>
>># string_of_float 123456789.123456789;;
>>- : string = "123456789.123"
>There's another problem too:
>
># string_of_float 42.0;;
>- : string = "42"
>
>The result isn't an ocaml float literal.
I'm new to Caml, but I did manage to slog through the sources
enough to determine that Caml does it "wrong", at least as
measured against what is possible and freely available.
A version of the Java rules would be appropriate
here -- as many digits as necessary to disambiguate from
any other machine double/float, or at least one fractional
digit, whichever is shorter. David Gay wrote some code to
do this (gdtoa) that is available at netlib, and (having
glued this code to a Java VM) I can provide some guidance
in using it, if you would like. You can also use gdtoa to
get other sorts of formatting -- n digits past the point,
that sort of thing.
Similarly, the transcendental functions available in fdlibm
(Freely Distributable libm) are almost as fast as hardware
(on those machines where there is hardware), but avoid the
stupid input limits (e.g., |x| < 2**64) and also use a large
enough value of PI to always deliver a result that is within
1 ulp, usually within 1/2 ulp (I have studied this problem
more than I care to). The results will be fast, portable
across all platforms, and as correct as you are likely to
get, certainly as good as you are likely to get for free.
Note: where available, hardware sqrt and log are usually
usable, though I have not checked carefully in those
portions of domain where their derivative is > 1.
If someone decides to do this, please contact me, I have
a list of fixes necessary for correct compilation of fdlibm
under Microsoft's incorrect C compilers. Some ninny thought
that the distributive law held true for machine FP, and they
don't constant propagate "funny values" (NaN, -0) properly.
yours,
David Chase
-------------------
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
next prev parent reply other threads:[~2002-05-02 13:28 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-30 8:21 Beck01, Wolfgang
2002-05-02 12:44 ` John Max Skaller
2002-05-02 12:54 ` Francois Thomasset
2002-05-05 17:33 ` John Max Skaller
2002-05-02 13:28 ` David Chase [this message]
2002-05-05 18:19 ` John Max Skaller
2002-05-02 13:46 ` jeanmarc.eber
2002-05-03 14:41 ` Oliver Bandel
[not found] ` <Pine.LNX.3.95.1020503162341.541E-100000@first.in-berlin.de >
2002-05-03 18:28 ` David Chase
2002-05-04 8:53 ` Xavier Leroy
2002-05-05 0:31 ` David McClain
2002-05-06 14:19 ` David Chase
2002-05-06 18:21 ` David McClain
2002-05-03 19:25 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=5.1.0.14.0.20020502085732.01f16fd0@pop.theWorld.com \
--to=chase@world.std.com \
--cc=caml-list@inria.fr \
/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