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
RE: Re: [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: 2002-05-06 (05:10)
From: artboreb@n...
Subject: RE: Re: [Caml-list] string_of_float less accurate than sprintf "%f" ?
John Max Skaller <> wrote:

Hi all,

>Francois Thomasset wrote:
>>>Beck01, Wolfgang wrote:
>>>There's another problem too:
>>># string_of_float 42.0;;
>>>- : string = "42"
>>>The result isn't an ocaml float literal.
>>Is it not?
>># float_of_string (string_of_float 42.0);;
>>- : float = 42
>>So if you know that there is a float in the string, it is a float isn't it?
>It isn't a floating point literal, in ocaml, C, or any other language.
>Floating point literals always have either a decimal indicator
>or an exponent. It should return "42.0", in my opinion:
>"42" is an integer.

In fact "42" is only a string. Strictly it cannot be infered nothing else
without a radix indicator and an explicit type of internal representation
"42.0" should be interpreted as a decimal floating point value
"42.00" another decimal floating point value with better accuracy 
"42o" would be interpreted as an octal value, integer, character or other?
"42h" same, an hexadecimal value 
So the meaning of "42" only would be infered within the context on where
"42" occurs. if "42" appear on the cash report of my credit card most
probably it means a decimal currency value (or perhaps a code?)
We do this all the time (infering), it is part of our culture, but 
sometimes the context imposes full strict information of "42" such as
"42.0 +/- 1e-9" = "42.00000000" or "0x0042" or "+0x00000042" or "US$42.0"
or "42 KSLOC" .......... or wathever
My oppinion is that this stuff has nothing to do with Caml it is only
related to code the correct printf in the correct place.


Arturo Borquez

Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape!

Get your own FREE, personal Netscape Mail account today at

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