From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA03732; Thu, 5 Sep 2002 10:00:24 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA03224 for caml-list@pauillac.inria.fr; Thu, 5 Sep 2002 10:00:24 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA18664 for ; Wed, 4 Sep 2002 15:46:50 +0200 (MET DST) Received: from mail.info.univ-angers.fr (nes.info.univ-angers.fr [193.49.146.122]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g84Dkn923020 for ; Wed, 4 Sep 2002 15:46:49 +0200 (MET DST) Received: from orion.info-ua (orion.info-ua [172.20.41.6]) by mail.info.univ-angers.fr (Postfix) with ESMTP id 8ECB394B for ; Wed, 4 Sep 2002 15:46:48 +0200 (CEST) Received: from helios.info-ua (helios.info-ua [172.20.41.5]) by orion.info-ua (Postfix) with ESMTP id 967F9175CE for ; Wed, 4 Sep 2002 15:46:48 +0200 (MEST) Received: by helios.info-ua (Postfix, from userid 759) id D13E81421D; Wed, 4 Sep 2002 13:46:47 +0000 (MET) Received: from localhost (localhost [127.0.0.1]) by helios.info-ua (Postfix) with ESMTP id C61DC1D82 for ; Wed, 4 Sep 2002 15:46:47 +0200 (MEST) Date: Wed, 4 Sep 2002 15:46:47 +0200 (MEST) From: Vincent Barichard X-X-Sender: barichar@helios.info-ua To: CAML-LIST Subject: RE: [Caml-list] float number In-Reply-To: <15734.707.339302.596392@tkb.mpl.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Thank you everyone, I know what I do wrong now. I'll correct the test between float numbers (with another epsilon value). Vincent On Wed, 4 Sep 2002, T. Kurt Bond wrote: > Vincent Barichard writes: > > Hi, > > > > I've observed a strange behaviour of ocaml : > > > > let x =3D asin (-0.587527525714) in (x,x =3D (-0.628));; > > - : float * bool =3D (-0.628, false) > > > > Why x doesn't equal to -0.628 ?? > > > > Thanks > > Because x isn't equal to -0.628, even though it prints as -0.628. The > output routine doesn't print the value of x accurately. The same > thing happens in C. O'Caml uses the C routine sprintf to format > floating point numbers (see the function format_float in > byterun/floats.c), and inherits poor float-printing routines from the > C runtime library.. > > Asking CMU Common Lisp (with *read-default-float-format* set to > DOUBLE-FLOAT, since O'Caml represents floating point numbers as > doubles) for the value of (asin -0.587527525714) gives > -0.6280000000001337, as does MzScheme. > > Here's a short (and non-portable) program that shows the problem > occuring in C: > > #include > #include > > int > main (int argc, char **argv) > { > double x =3D asin (-0.587527525714); > double y =3D -0.628; > > int *xp =3D &x; > int *yp =3D &y; > > printf ("x: %g, x =3D=3D (-0.628): %d\n", x, x =3D=3D (-0.628)); > printf ("*xp: %x *(xp+1): %x\n", *xp, *(xp+1)); > printf ("*yp: %x *(yp+1): %x\n", *yp, *(yp+1)); > > exit (1); > } > > On FreeBSD 4.6 running on a Pentium II I compiled it like this: > > cc -O -pipe x.c -lm -o x > > and the output was: > > x: -0.628, x =3D=3D (-0.628): 0 > *xp: 74bc6f33 *(xp+1): bfe41893 > *yp: 74bc6a7f *(yp+1): bfe41893 > > Notice that *xp and *yp are not equal. > > More information on print floating point numbers can be found in the > paper "Printing Floating-Point Numbers Quickly and Accurately"; see > > http://citeseer.nj.nec.com/28233.html > > -- > T. Kurt Bond, tkb@tkb.mpl.com > > ------------------- > To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inr= ia.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 > Vincent Barichard M=E9taheuristiques et Optimisation Combinatoire Facult=E9 des Sciences d'Angers Tel : 02 41 73 52 06 ------------------- 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