From: Oliver Bandel <oliver@first.in-berlin.de>
To: John Max Skaller <skaller@ozemail.com.au>
Cc: "Beck01, Wolfgang" <BeckW@t-systems.com>, caml-list@inria.fr
Subject: Re: [Caml-list] string_of_float less accurate than sprintf "%f" ?
Date: Fri, 3 May 2002 16:41:25 +0200 (MET DST) [thread overview]
Message-ID: <Pine.LNX.3.95.1020503162341.541E-100000@first.in-berlin.de> (raw)
In-Reply-To: <3CD134B0.8050100@ozemail.com.au>
On Thu, 2 May 2002, John Max Skaller wrote:
> Beck01, Wolfgang wrote:
>
> >Hello,
> >
> >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.
Well... but the type is not necessarily an int though.
The type is a float, even if the representation looks like
an int.
The only problem here is that it's confusing for human readers.
But is it necessary that a type can have only one possible
representation?
A problem only occurs with type inference... you can not
say that 42 is a float-value: the type inference always
says, that 42 is an int:
# 42;;
will not yield a float.
This is confusing. I had problems with it too.
But when you look at the following example, you see, that
the type will be used correct and is not derived from it's
representation:
##################################################
oliver@first:/home/oliver > ocaml
Objective Caml version 3.04
# type mytype = Nothing | Value of float;;
type mytype = Nothing | Value of float
# let x = Nothing;;
val x : mytype = Nothing
# let y = Value 42;;
This expression has type int but is here used with type float
# let y = Value (float_of_string "42");;
val y : mytype = Value 42
# let z = Value (float_of_string (string_of_float 24.0));;
val z : mytype = Value 24
# let zz = Value (float_of_string (string_of_float 33));;
This expression has type int but is here used with type float
#
##################################################
Value is of type float and Ocaml works correctly with it.
So this is not really a problem.
It seems to be only a problem, when type inference is
used - so it's a problem in human-machine-interfacing.
But a problem can occur too, when the type is not known
from within the program: When writing the string-representation
of a float to a file and read it back from the file,
then the non-float representation of the float yields
in parsing-/type-problems.
So that is a problem within the program and it's data
(I/O)... So this seems to be actually a problem.
If (string_of_float 42.0) yields "42.0" (instead of "42"),
this maybe is not the right value, because it maybe is only
correct as "42.0000000000000"?
Well.... philosophical question?
Ciao,
Oliver
-------------------
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-03 14:45 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
2002-05-05 18:19 ` John Max Skaller
2002-05-02 13:46 ` jeanmarc.eber
2002-05-03 14:41 ` Oliver Bandel [this message]
[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=Pine.LNX.3.95.1020503162341.541E-100000@first.in-berlin.de \
--to=oliver@first.in-berlin.de \
--cc=BeckW@t-systems.com \
--cc=caml-list@inria.fr \
--cc=skaller@ozemail.com.au \
/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