News for hackers. Stuff that matters.
Re:Testing for -0 (negative zero) in JavaScript by pzxc on Wednesday February 16, 2011 @08:19PM (#2229218)
But what's the point? What is this useful for, or is it only academic?
Re:Testing for -0 (negative zero) in JavaScript by sp332 on Wednesday February 16, 2011 @08:38PM (#2229268)
Negative 0 means that you have a negative value, but the value is too small to be represented with available precision. It's a way of noting the sign of the value even if the magnitude is unavailable. It could be useful if you're testing edge cases, or if you're looking for signs of an infinity (or negative infinity) in your program.
Re:Testing for -0 (negative zero) in JavaScript by jckarter on Wednesday February 16, 2011 @11:56PM (#2229825)
There are lots of edge cases where the sign of zero affects computation. In floating-point, zero values represent not only the exact value zero but the result of an underflowed computation too small to represent as a non-zero floating point value, so retaining the sign is often important to at least keep such computations on the correct side of a branch cut or limit. For example:

x/+0 = +infinity

x/-0 = -infinity

sqrt(+0) = 0

sqrt(-0) = nan

log(+0) = -infinity

log(-0) = nan