Testing for -0 (negative zero) in JavaScript
wirfs-brock.com
wirfs-brock.com
This is one of those weird points where Javascript seems like a confused mutant combination of a high-level language and a low-level one. It doesn't give you the power to manipulate the bits of a value, but simultaneously exposes you to all the strange, pointy bits of floating point implementation. It would be a lot nicer if it either gave you the power to fully manipulate the bits, or abstracted away the nastiness of the implementation, but no, they chose wrong in both directions.
on the other hand, -0 and +0 are a pretty straightforward result of the normal floating point representation, are sometimes useful, and IEEE 754 defines +0==-0. Hiding them under a single 0 would have been more of a hack than having to deal with the difference very very occasionally.
if(value) behaves differently from if (value == true), behaves differently from if (value === true), which again behaves differently from that check in freeze.
IMHO, that freeze check should have behaved the same as ===, so the proposed solution should not have worked.
Oh well.
x/+0 = +infinity
x/-0 = -infinity
sqrt(+0) = 0
sqrt(-0) = nan
log(+0) = -infinity
log(-0) = nan