Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] floating point input/conversion
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Olivier Andrieu <andrieu@i...>
Subject: Re: [Caml-list] floating point input/conversion
 > 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.


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: