From: mff <mff@research.att.com>
To: caml-list@inria.fr, mff@research.att.com
Subject: [Caml-list] Printing floating point numbers & precision
Date: Thu, 30 Sep 2004 12:53:02 -0400 [thread overview]
Message-ID: <415C39EE.7090606@research.att.com> (raw)
Greetings,
I have a question regarding the printing of floating point numbers.
Here's an example:
lt-mff: /usr/bin/ocaml
Objective Caml version 3.07+2
# max_float;;
- : float = 1.79769313486231571e+30
# Printf.sprintf "%e" max_float;;
- : string = "1.797693e+308"
So using the default %e format to print a floating point number loses 11
digits
of precision. I could be more precise about the number of fractional
digits:
# Printf.sprintf "%.17e" max_float;;
- : string = "1.79769313486231571e+308"
But this does not seem to work in general:
# Printf.sprintf "%.17e" 12345.1;;
- : string = "1.23451000000000004e+04"
I've combed the documentation to try to understand the relationship between
printing and precision (and accuracy!) but have come up empty handed.
Help is appreciated!
Thanks, Mary
-------------------
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 reply other threads:[~2004-09-30 16:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-30 16:53 mff [this message]
-- strict thread matches above, loose matches on Subject: below --
2004-09-30 16:52 mff
2004-09-30 19:25 ` Remi Vanicat
2004-10-01 7:56 ` Christian Lindig
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=415C39EE.7090606@research.att.com \
--to=mff@research.att.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