From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA21598 for caml-red; Fri, 21 Jul 2000 09:26:06 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA21141 for ; Wed, 19 Jul 2000 22:13:44 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.10.0/8.10.0) with ESMTP id e6JKDan24448; Wed, 19 Jul 2000 22:13:36 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA26875; Wed, 19 Jul 2000 22:13:36 +0200 (MET DST) Message-ID: <20000719221336.34904@pauillac.inria.fr> Date: Wed, 19 Jul 2000 22:13:36 +0200 From: Xavier Leroy To: Caml Mailing List , lindig@eecs.harvard.edu Subject: Re: IEEE floating point emulation library? References: <20000711213139.A339@eecs.harvard.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89.1 In-Reply-To: <20000711213139.A339@eecs.harvard.edu>; from Christian Lindig on Tue, Jul 11, 2000 at 09:31:39PM -0400 Sender: weis@pauillac.inria.fr > For a compiler project I am looking for an IEEE floating point > emulation. I have already checked http://caml.inria.fr/hump.html and > the OCaml link database for such a libray. Does anybody has written > something like this for OCaml? This sounds hard. IEEE floating-point arithmetic is quite intricate. However: > To answer the obvious question, why not use the built in float data > type: I need access to the representation at the bit level. Some > code that decodes a float value into a bit vector (int32/int64) and > back would be also helpful. You can do this easily using the following piece of C code: #include #include value unpack_float(value f) { union { double d; int64 i; } buffer; buffer.d = Double_val(f); return copy_int64(buffer.i); } value pack_float(value i) { union { double d; int64 i; } buffer; buffer.i = Int64_val(i); return copy_double(buffer.d); } and the following external declarations: external unpack_float: float -> int64 = "unpack_float" external pack_float: int64 -> float = "pack_float" >>From the int64 representation, you can easily access every bit of the float representation. For single-precision floats and int32, substitute "double" by "float" and "int64" by "int32" in the code above. Hope this helps. - Xavier Leroy