Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #26219
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Subject | Extracting bit fields from an IEEE-784 float |
| Newsgroups | comp.lang.python |
| Date | 2012-07-30 00:44 +0000 |
| Message-ID | <5015d8d4$0$11120$c3e8da3@news.astraweb.com> (permalink) |
| Organization | Unlimited download news at news.astraweb.com |
I wish to extract the bit fields from a Python float, call it x. First I
cast the float to 8-bytes:
s = struct.pack('=d', x)
i = struct.unpack('=q', s)[0]
Then I extract the bit fields from the int, e.g. to grab the sign bit:
(i & 0x8000000000000000) >> 63
Questions:
1) Are there any known implementations or platforms where Python floats
are not C doubles? If so, what are they?
2) If the platform byte-order is reversed, do I need to take any special
action? I don't think I do, because even though the float is reversed, so
will be the bit mask. Is this correct?
3) Any other problems with the way I am doing this?
Thanks in advance,
Steven
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Extracting bit fields from an IEEE-784 float Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-30 00:44 +0000
PyPI question, or, maybe I'm just stupid Chris Gonnerman <chris@gonnerman.org> - 2012-07-29 20:26 -0500
Re: PyPI question, or, maybe I'm just stupid Ben Finney <ben+python@benfinney.id.au> - 2012-07-30 14:00 +1000
Re: [Python] Re: PyPI question, or, maybe I'm just stupid Chris Gonnerman <chris@gonnerman.org> - 2012-07-30 07:46 -0500
Re: Extracting bit fields from an IEEE-784 float Dan Sommers <dan@tombstonezero.net> - 2012-07-29 18:08 -0700
Re: Extracting bit fields from an IEEE-784 float Terry Reedy <tjreedy@udel.edu> - 2012-07-30 01:17 -0400
Re: Extracting bit fields from an IEEE-784 float Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-07-30 08:42 +0200
Re: Extracting bit fields from an IEEE-784 float Mark Dickinson <dickinsm@gmail.com> - 2012-07-30 00:57 -0700
Re: PyPI question, or, maybe I'm just stupid Dieter Maurer <dieter@handshake.de> - 2012-07-30 11:20 +0200
Re: Extracting bit fields from an IEEE-784 float Grant Edwards <invalid@invalid.invalid> - 2012-07-30 14:16 +0000
Re: Extracting bit fields from an IEEE-784 float Roy Smith <roy@panix.com> - 2012-07-30 10:28 -0400
Re: Extracting bit fields from an IEEE-784 float Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-07-30 15:50 +0100
Re: Extracting bit fields from an IEEE-784 float Grant Edwards <invalid@invalid.invalid> - 2012-07-30 15:47 +0000
Re: Extracting bit fields from an IEEE-784 float Roy Smith <roy@panix.com> - 2012-07-30 16:50 -0400
Re: Extracting bit fields from an IEEE-784 float Mark Dickinson <dickinsm@gmail.com> - 2012-07-30 09:14 -0700
csiph-web