From: "Zeno Lee" <zeno.lee@earthlink.net>
To: "David Brown" <caml-list@davidb.org>
Cc: <caml-list@inria.fr>
Subject: Re: [Caml-list] weird floating poing behavior on windows
Date: Fri, 2 Apr 2004 15:31:11 -0500 [thread overview]
Message-ID: <00a301c418f1$70053170$6401a8c0@xp> (raw)
In-Reply-To: <20040402200759.GA12200@davidb.org>
This does not happen to me on Solaris from which I do all my ocaml work, but
I happened to be using the toplevel on windows as a quick and dirty
calculator when I noticed the different behavior.
solaris$ ocaml
Objective Caml version 3.06
# 0.8 *. 0.7 *. 0.8;;
- : float = 0.448
however, when I use your example c program on the same solaris machine it
prints out
0.44799999999999995
----- Original Message -----
From: "David Brown" <caml-list@davidb.org>
To: "Zeno Lee" <zeno.lee@earthlink.net>
Cc: <caml-list@inria.fr>
Sent: Friday, April 02, 2004 3:07 PM
Subject: Re: [Caml-list] weird floating poing behavior on windows
> On Fri, Apr 02, 2004 at 02:39:43PM -0500, Zeno Lee wrote:
> > Can anyone tell me what's going on here? Is this a known issue on
windows?
> >
> > C:\>ocaml
> > Objective Caml version 3.07+2
> > # 0.2 *. 0.26;;
> > - : float = 0.052000000000000005
052000000000000005
> > # 0.8 *. 0.7 *. 0.8;;
> > - : float = 0.44799999999999995
>
> Nothing unusual. Floats only have a certain amount of precision. The
> toplevel prints floats out with more precision than they contain. It
> does the same thing on Linux.
>
> For example, in C:
>
> #include <stdio.h>
>
> int
> main (int argc, char **argv)
> {
> printf ("%.17g\n", 0.2 * 0.26);
> printf ("%.17g\n", 0.8 * 0.7 * 0.8);
> return 0;
> }
>
> prints:
> 0.052000000000000005
> 0.44799999999999995
>
> Now the real question is why does the toplevel do this (and where, in
> the code is it coming from). string_of_float only uses 12 digits.
>
> Dave Brown
-------------------
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:[~2004-04-02 20:32 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-02 13:41 [Caml-list] failwith, raise and type inference Paul Guyot
2004-04-02 13:49 ` Frederic van der Plancke
2004-04-02 13:56 ` Paul Guyot
2004-04-02 13:51 ` Nicolas Cannasse
2004-04-02 13:59 ` Correnson Loïc
2004-04-02 14:09 ` Luc Maranget
2004-04-02 19:39 ` [Caml-list] weird floating poing behavior on windows Zeno Lee
2004-04-02 20:03 ` Greg Bacon
2004-04-02 20:07 ` David Brown
2004-04-02 20:31 ` Zeno Lee [this message]
2004-04-02 20:50 ` Pierre Weis
2004-04-02 22:01 ` Brian Hurt
2004-04-02 21:58 ` Brian Hurt
2004-04-02 20:28 ` [Caml-list] failwith, raise and type inference Pierre Weis
2004-04-05 22:52 ` Ker Lutyn
2004-04-06 1:07 ` Jacques Garrigue
2004-04-06 5:23 ` Issac Trotts
2004-04-06 15:15 ` skaller
2004-04-06 1:15 ` Christophe TROESTLER
2004-04-06 7:05 ` skaller
2004-04-06 11:29 ` Eric C. Cooper
2004-04-09 7:18 ` Christophe TROESTLER
2004-04-09 7:32 ` Xavier Leroy
2004-04-09 8:03 ` skaller
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='00a301c418f1$70053170$6401a8c0@xp' \
--to=zeno.lee@earthlink.net \
--cc=caml-list@davidb.org \
--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