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
float printing
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-03-24 (20:20)
From: Christophe Raffalli <christophe.raffalli@u...>
Subject: float printing

I have a small problem to read and write float in a file. I use the
format library and there is no way to write/read a float in hexadecimal
to be sure you read exactly the same float back from the file (a n bits
mantisse float may need n decimals to have an exact representation.
Just compute 1/2^n and count decimals).

The only way is to convert the float to string via Printf and then print
the string with Format.print_string.

Don't you think Pervasives and format should have a write/print_hexfloat
and Pervasives should have an input_hexfloat function ?

Christophe Raffalli
Université de Savoie
Batiment Le Chablais, bureau 21
73376 Le Bourget-du-Lac Cedex

tél: (33) 4 79 75 81 03
fax: (33) 4 79 75 87 42
IMPORTANT: this mail is signed using PGP/MIME
At least Enigmail/Mozilla, mutt or evolution
can check this signature. The public key is
stored on