How do I check if a zero is positive or negative?

Yes, divide by it. 1 / +0.0f is +Infinity, but 1 / -0.0f is -Infinity. It’s easy to find out which one it is with a simple comparison, so you get:

if (1 / x > 0)
    // +0 here
else
    // -0 here

(this assumes that x can only be one of the two zeroes)

Leave a Comment