caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "François Pottier" <francois.pottier@inria.fr>
To: Andreas Rossberg <rossberg@mpi-sws.org>,
	Kenichi Asai <asai@is.ocha.ac.jp>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] string_of_float (0.1 +. 0.2)
Date: Wed, 15 Jun 2022 09:00:38 +0200	[thread overview]
Message-ID: <1c2d63bb-877c-f40a-d228-f4b877e61b54@inria.fr> (raw)
In-Reply-To: <43238522-BFA7-4F89-8F91-9D95893A9D74@mpi-sws.org>


Hi,

Le 15/06/2022 à 08:22, Andreas Rossberg a écrit :
 > The OCaml manual does not say what the default is, but it appears to 
be .6 for printf (like in C), while string_of_float is equivalent to 
(sprintf "%.12g”) and the REPL uses .18 (which is the maximum meaningful 
decimal precision for 64 bit floats):

Indeed, the implementation of string_of_float uses "%.12g".

The manual says that string_of_float returns "the" string representation 
of a
floating-point number. I would claim that there is a problem here -- either
the manual should warn that there is a potential loss of information, or the
code should be fixed so as to lose no information.

--
François Pottier
francois.pottier@inria.fr
http://cambium.inria.fr/~fpottier/

  reply	other threads:[~2022-06-15  7:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-15  1:59 Kenichi Asai
2022-06-15  6:22 ` Andreas Rossberg
2022-06-15  7:00   ` François Pottier [this message]
2022-06-15 14:07 ` Gabriel Scherer
2022-06-15 14:25   ` Daniel Bünzli
2022-06-16  1:45     ` Kenichi Asai
2022-06-16  6:24       ` Oleg
2022-06-16  9:01         ` Andreas Rossberg
2022-06-16  9:14           ` [Caml-list] unsubscribe Jean-Denis EIDEN JEAN-DENIS

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=1c2d63bb-877c-f40a-d228-f4b877e61b54@inria.fr \
    --to=francois.pottier@inria.fr \
    --cc=asai@is.ocha.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=rossberg@mpi-sws.org \
    /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).