From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA09942; Fri, 9 Nov 2001 12:05:27 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA09822 for ; Fri, 9 Nov 2001 12:05:26 +0100 (MET) Received: from heplix4.ikp.physik.tu-darmstadt.de (heplix4.ikp.physik.tu-darmstadt.de [130.83.210.158]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id fA9B5Pn04754 for ; Fri, 9 Nov 2001 12:05:25 +0100 (MET) Received: (from ohl@localhost) by heplix4.ikp.physik.tu-darmstadt.de (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) id fA9B5OX21124; Fri, 9 Nov 2001 12:05:24 +0100 From: Thorsten Ohl MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15339.47220.792529.380015@heplix4.ikp.physik.tu-darmstadt.de> Date: Fri, 9 Nov 2001 12:05:24 +0100 To: Caml List Cc: "Rafael 'Dido' Sevilla" Subject: [Caml-list] how to split up a Caml float into its component bytes In-Reply-To: <20011109112909.A9417@team.ph.inter.net> References: <20011109112909.A9417@team.ph.inter.net> X-Mailer: VM 6.84 under Emacs 20.7.1 Reply-To: ohl@hep.tu-darmstadt.de Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Rafael 'Dido' Sevilla writes: > I'm wondering how I would convert a floating point > number in OCaml (which I hope I am safe in assuming is IEEE-754) into > its equivalent bytes. AFAIK, you have to write a C function. There is an undocumented primitive external float_of_bytes : string -> float = "float_of_bytes" defined in byterun/floats.c. Unfortunately: a) the inverse is absent b) on little endian machines one has to swap bytes. A pair of primitives val unformatted_float_of_string : string -> float val unformatted_float_to_string : float -> string together with val output_binary_float : out_channel -> float -> unit val input_binary_float : in_channel -> float would be very helpful. I made a version of input_binary_float from input_string and some byte-swapping, but a portable version (that gives me the warm fuzzy feeling that it does not run only on Linux) would be very welcome: there are programs that spend most of their time parsing and formatting floats. -- Thorsten Ohl, Physics Department, TU Darmstadt -- ohl@hep.tu-darmstadt.de http://heplix.ikp.physik.tu-darmstadt.de/~ohl/ [<=== PGP public key here] ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr