On Thu, 28 Oct 2010 10:13:15 -0400, Dave Angel wrote:
> Inverting the bits of a floating point number wouldn't make much sense,
> so fortunately it gives an error.
>>> from struct import pack, unpack
>>>
>>> def float_as_int(x):
... bits = pack("d", x)
... return unpack("q", bits)[0]
...
>>> def int_as_float(i):
... bits = pack("q", i)
... return unpack("d", bits)[0]
...
>>>
>>> float_as_int(1.123)
4607736361554183979
>>> int_as_float(~4607736361554183979)
-3.7539999999999996
>>>
>>> int_as_float( ~float_as_int(0.0) )
nan
Makes perfect sense to me :)
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list