<br><div class="gmail_quote">On Mon, Jul 30, 2012 at 12:44 AM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve+comp.lang.python@pearwood.info" target="_blank">steve+comp.lang.python@pearwood.info</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I wish to extract the bit fields from a Python float, call it x. First I<br>
cast the float to 8-bytes:<br>
<br>
s = struct.pack('=d', x)<br>
i = struct.unpack('=q', s)[0]<br>
<br>
Then I extract the bit fields from the int, e.g. to grab the sign bit:<br>
<br>
(i & 0x8000000000000000) >> 63<br>
<br>
<br>
Questions:<br>
<br>
1) Are there any known implementations or platforms where Python floats<br>
are not C doubles? If so, what are they?<br></blockquote><div>Last I heard, DEC Alpha chips did not use IEEE floating point.<br> <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

2) If the platform byte-order is reversed, do I need to take any special<br>
action? I don't think I do, because even though the float is reversed, so<br>
will be the bit mask. Is this correct?<br>
<br>
3) Any other problems with the way I am doing this?<br></blockquote><div>It gives me the heebie jeebies.  Why go to all the trouble and incur the lack of portability to esoteric platforms, when you can just use arithmetic expressions?  It's fancy, and it'll probably almost always work, but it's probably not so wise. <br>
<br></div></div>