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: | David Brown <caml-list@d...> |
| 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
> # 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