From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.0 required=5.0 tests=DNS_FROM_RFC_ABUSE, HTML_MESSAGE,MISSING_HEADERS,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id D8C95BC68 for ; Tue, 17 Oct 2006 16:02:47 +0200 (CEST) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.232]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id k9HE2k9f005188 for ; Tue, 17 Oct 2006 16:02:47 +0200 Received: by wr-out-0506.google.com with SMTP id 58so318718wri for ; Tue, 17 Oct 2006 07:02:44 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:subject:cc:in-reply-to:mime-version:content-type:references; b=Y/1swoJ44MetJQJkTdpoK569xeyXJ2okFMd3vxoF2/kD36qxXiCfY0fLqBwgF3Kjvd0IOfFE1GydEZoQaXEHfg/asjSjGCP1KeEEdYIJ2WuGIiJnESIYhijtehb3kys/JPi1X2JpU0eh2WMsk52wMIO5mCRtC2625YH4iRz/UTU= Received: by 10.90.105.20 with SMTP id d20mr4803161agc; Tue, 17 Oct 2006 07:02:44 -0700 (PDT) Received: by 10.90.92.6 with HTTP; Tue, 17 Oct 2006 07:02:43 -0700 (PDT) Message-ID: Date: Tue, 17 Oct 2006 16:02:43 +0200 From: "Maurizio Colucci" Subject: Re: [Caml-list] Re: Reading 16 bit floats from stream? Cc: tom.primozic@gmail.com, caml-list@yquem.inria.fr In-Reply-To: <20061017.082528.59485463.garrigue@math.nagoya-u.ac.jp> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_48634_10334953.1161093763487" References: <20061017.082528.59485463.garrigue@math.nagoya-u.ac.jp> X-j-chkmail-Score: MSGID : 4534E286.003 on discorde : j-chkmail score : X : 0/20 1 X-Miltered: at discorde with ID 4534E286.003 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; val:01 pervasives:01 ocaml:01 int's:01 integers:01 val:01 pervasives:01 ocaml:01 int's:01 integers:01 binary:01 binary:01 wrote:01 wrote:01 marshal:01 ------=_Part_48634_10334953.1161093763487 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 10/17/06, Jacques Garrigue wrote: > > From: Tom > > > 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 ------=_Part_48634_10334953.1161093763487 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline

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
------=_Part_48634_10334953.1161093763487--