Browse thread
[Caml-list] failwith, raise and type inference
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Zeno Lee <zeno.lee@e...> |
| Subject: | Re: [Caml-list] weird floating poing behavior on windows |
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