ano.malo.us pretty typical actually..

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

Posted by
Jeremy
Jun 25, 2007 @ 11am

Just wait until IEEE adds nullity to the standards.
http://tinyurl.com/y2hu99


Posted by
abhik
Jun 25, 2007 @ 7pm

Yeah, that nullity guy is an idiot.. but nice try..


Posted by
cjdierkens
May 27, 2010 @ 3pm

How about posting a link to the documentation that shows how to test for negative zero.. just a thought.


Leave a Comment

Academic journals in a networked world Giving Props