[Numpy-discussion] making the distinction between -0.0 and 0.0..
Tue Sep 29 15:34:16 CDT 2009
Joe Kington wrote:
> I just realized that what I'm doing won't work on older versions of
> python, anyway...
What I was looking for was which actual bit the sign bit is, as
expressed as a native integer, so I can do a bitwise_and.
But now that I think about it, I only need to test zero, not all
numbers, so I should be able to do:
if x < 0.0:
elif x == 0.0:
if struct.pack('d',x) == struct.pack('d',-0.0):
Fortunately, this isn't performance critical.
> Of course, you could always do x.__repr__().startswith('-'), but it's
> slow, ugly, and you already said you wanted to avoid it.
well, that's not what I wanted to avoid -- what I wanted to avoid was
parsing the original input string. This would be fine! I wonder if it's
better or worse than using struct as above?
Christopher Barker, Ph.D.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
More information about the NumPy-Discussion