Negative Zero
Zero is zero, right? Can’t have positive and negative zero? Wouldn’t make any sense!! right?
Well, as I learned, IEEE does actually define a negative zero. It doesn’t make sense conceptually but it’s used when one wants to round off small negative values to zero but still indicate that the original value was negative. In python, this results in this weird example:
In [1]: x = -0.0 In [2]: x Out[2]: -0.0 In [3]: x < 0 Out[3]: False
This is what I was stuck with today as I tried to figure out how to detect negative eigenvalues… which is tricky when -0.0 < 0 is False. Fortunately, Numpy has a function that specifically checks the signbit of numbers.
It’s problems like this that take so long to discover and fix that makes programming frustrating at times.
3 Comments