Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Caml Mailing List <caml-list@inria.fr>, lindig@eecs.harvard.edu
Subject: Re: IEEE floating point emulation library?
Date: Wed, 19 Jul 2000 22:13:36 +0200	[thread overview]
Message-ID: <20000719221336.34904@pauillac.inria.fr> (raw)
In-Reply-To: <20000711213139.A339@eecs.harvard.edu>; from Christian Lindig on Tue, Jul 11, 2000 at 09:31:39PM -0400

> 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 <caml/mlvalues.h>
  #include <caml/alloc.h>

  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



  reply	other threads:[~2000-07-21  7:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-07-12  1:31 Christian Lindig
2000-07-19 20:13 ` Xavier Leroy [this message]
2000-07-17 17:20 ortmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20000719221336.34904@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=lindig@eecs.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox