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] string_of_float less accurate than sprintf "%f" ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Beck01, Wolfgang <BeckW@t...>
Subject: [Caml-list] string_of_float less accurate than sprintf "%f" ?

while doing some time measurements with Unix.gettimeofday() I
discovered a problem with string_of_float:

# string_of_float 123456789.123456789;;
- : string = "123456789.123"

OK, just it may by just an inaccuracy of the float type. However,
sprintf returns a different result:

# sprintf "%f" 123456789.123456789;;
- : string = "123456789.1234567"

I am using ocaml 3.02 under FreeBSD 4.5. However, the 'Changes' file
did not mention string_of_float in more recent ocaml versions.

My application needs to be fast (that's why I am using OCaml :-) and
sprintf is of course slower than string_of_float.

Did I miss a 'double' type in the manual?

Wolfgang Beck
T-Systems Nova GmbH 
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: