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 MAA11493; Fri, 22 Oct 2004 12:12:26 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 MAA11344 for ; Fri, 22 Oct 2004 12:12:25 +0200 (MET DST) Received: from kraid.nerim.net (smtp-105-friday.nerim.net [62.4.16.105]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i9MACPaD017485 for ; Fri, 22 Oct 2004 12:12:25 +0200 Received: from localhost (karryall.dnsalias.org [62.4.18.180]) by kraid.nerim.net (Postfix) with ESMTP id 2CFD541BF0; Fri, 22 Oct 2004 12:12:24 +0200 (CEST) Date: Fri, 22 Oct 2004 12:12:23 +0200 (CEST) Message-Id: <20041022.121223.112609556.oandrieu@nerim.net> To: stefan.ratschan@mpi-sb.mpg.de Cc: caml-list@inria.fr Subject: Re: [Caml-list] floating point input/conversion From: Olivier Andrieu In-Reply-To: <1098437140.3079.21.camel@localhost> References: <1098437140.3079.21.camel@localhost> X-Mailer: Mew version 4.0.64 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Miltered: at nez-perce with ID 4178DD09.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 andrieu:01 andrieu:01 2004:99 byterun:01 floats:01 rounding:01 ocaml:01 caml:01 behaviour:01 olivier:02 olivier:02 vague:02 float:02 float:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Stefan Ratschan [Fri, 22 Oct 2004]: > For the functions float_of_string and read_float the OCaml manual is > very vague: "Convert the given string to a float". > > In fact, this sentence is wrong. For example, the number 0.1 does not > have a floating point representation, only approximations to it. > > So what is the exact specification of these functions? Which number is > taken if the given string does not have a floating point representation? > The nearest one? The nearest one up to 2ulps? float_of_string basically just calls strtod() from the C library (see caml_float_of_string in byterun/floats.c). strtod's behaviour is specified in the C standard, which says: « the result is either the nearest representable value, or the larger or smaller representable value immediately adjacent to the nearest representable value, chosen in an implementation-defined manner. » So I guess the answer is 'it depends'. > Is the current rounding mode taken into account? Probably not because strtod() is supposed to give the same result than a float constant in the source code. -- Olivier ------------------- 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