From: Thorsten Ohl <ohl@hep.tu-darmstadt.de>
To: Caml List <caml-list@pauillac.inria.fr>
Cc: Xavier Leroy <xavier.leroy@inria.fr>
Date: Fri, 9 Nov 2001 14:32:18 +0100 [thread overview]
Message-ID: <15339.56034.169961.457637@heplix4.ikp.physik.tu-darmstadt.de> (raw)
In-Reply-To: <20011109131841.A5769@pauillac.inria.fr>
> Starting with OCaml 3.01, the Int64 module provides two functions
> "bits_of_float" and "float_of_bits" which convert between floats and
> an int64 matching the underlying 64-bit representation of the float.
Thanks. I forgot to look among the Int* modules when I was hunting
for floating point conversions :-(.
> > external float_of_bytes : string -> float = "float_of_bytes"
> > b) on little endian machines one has to swap bytes.
>
> b) is not (big endian representation is enforced).
Now I'm confused. On my Linux box, I have to swap bytes in order
to read binary floating point numbers from a stream (where I can not
mmap Bigarrays).
let unsafe_rev8 s =
let swap i1 i2 =
let tmp = String.unsafe_get s i1 in
String.unsafe_set s i1 (String.unsafe_get s i2);
String.unsafe_set s i2 tmp in
swap 0 7;
swap 1 6;
swap 2 5;
swap 3 4
let little_endian = true
let input_binary_float ic =
let buf = String.create 8 in
really_input ic buf 0 8;
if little_endian then
unsafe_rev8 buf;
float_of_bytes buf
But that's academical, because I will switch to Int64 now. Thanks
again.
--
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
next prev parent reply other threads:[~2001-11-09 13:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-09 3:29 [Caml-list] how to split up a Caml float into its component bytes Rafael 'Dido' Sevilla
2001-11-09 11:05 ` Thorsten Ohl
2001-11-09 12:18 ` Xavier Leroy
2001-11-09 13:32 ` Thorsten Ohl [this message]
2001-11-09 11:28 ` malc
2001-11-09 17:09 ` Ken Rose
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=15339.56034.169961.457637@heplix4.ikp.physik.tu-darmstadt.de \
--to=ohl@hep.tu-darmstadt.de \
--cc=caml-list@pauillac.inria.fr \
--cc=xavier.leroy@inria.fr \
/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