Version française
Home     About     Download     Resources     Contact us    
Browse thread
Reading 16 bit floats from stream?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Maurizio Colucci <maurizio.colucci@g...>
Subject: Re: [Caml-list] Re: Reading 16 bit floats from stream?
On 10/17/06, Jacques Garrigue <garrigue@math.nagoya-u.ac.jp> wrote:
>
> From: Tom <tom.primozic@gmail.com>
>
> > val Pervasives.input_binary_int : in_channel -> int
>
> This will indeed read a 32-bit integer, but on a 32-bit architecture
> ocaml int's are 31-bit, so you loose the highest bit.
> Note that on a 64-bit architecture this is sufficient for 32-bit
> integers!
>
> > val Pervasives.read_int : unit -> int
>
> This one reads a string...
>
> > val Marshal.from_channel : in_channel -> 'a
>
> And this one reads a marshalled value, which must include a special
> header indicating its ocaml representation.
>
> So if you really need to read a full 32-bit integer, none of these
> will work, and you must do the job by hand.
>
> Jacques Garrigue


Thanks to everybody. I found a library called extlib which provides a module
called IO. I solved the problem with

let l =  Int32.float_of_bits (IO.read_real_i32 input)

BTW, I am a bit surprised the standard library does not offer a way to do
that. A simple task can become frustrating.

Bye

Maurizio