Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* IEEE floating point emulation library?
@ 2000-07-12  1:31 Christian Lindig
  2000-07-19 20:13 ` Xavier Leroy
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Lindig @ 2000-07-12  1:31 UTC (permalink / raw)
  To: Caml Mailing List


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?

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.

-- Christian

-- 
Christian Lindig          Harvard University - EECS 
lindig@eecs.harvard.edu   33 Oxford St, MD 242, Cambridge MA 02138
phone: (617) 496-7157     http://www.eecs.harvard.edu/~lindig/   
                          



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: IEEE floating point emulation library?
  2000-07-12  1:31 IEEE floating point emulation library? Christian Lindig
@ 2000-07-19 20:13 ` Xavier Leroy
  0 siblings, 0 replies; 3+ messages in thread
From: Xavier Leroy @ 2000-07-19 20:13 UTC (permalink / raw)
  To: Caml Mailing List, lindig

> 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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: IEEE floating point emulation library?
@ 2000-07-17 17:20 ortmann
  0 siblings, 0 replies; 3+ messages in thread
From: ortmann @ 2000-07-17 17:20 UTC (permalink / raw)
  To: Christian Lindig; +Cc: Caml Mailing List, oleg


> 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?

> 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.

> -- Christian

I received some good IEEE related Scheme code from oleg@pobox.com; maybe
he would know the answer?

--
Daniel Ortmann, IBM Circuit Technology, Rochester, MN 55901-7829
ortmann@us.ibm.com / internal 8.553.6795 / external 507.253.6795
ortmann@isl.net home 507.288.7732

"The answers are so simple, and we all know where to look,
but it's easier just to avoid the question." -- Kansas




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-07-21  7:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-07-12  1:31 IEEE floating point emulation library? Christian Lindig
2000-07-19 20:13 ` Xavier Leroy
2000-07-17 17:20 ortmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox