Is it possible to check if a float
is a positive zero (0.0) or a negative zero (-0.0)?
I've converted the float
to a String
and checked if the first char
is a '-'
, but are there any other ways?
If a number is greater than zero, it is a positive number. If a number is less than zero, it is a negative number. If a number equals to zero, it is zero.
The number zero is neither positive nor negative. Positive and negative numbers are sometimes called signed numbers.
Signed numbers Because zero is neither positive nor negative, the term nonnegative is sometimes used to refer to a number that is either positive or zero, while nonpositive is used to refer to a number that is either negative or zero. Zero is a neutral number.
Actually, zero is neither a negative or a positive number. The whole idea of positive and negative is defined in terms of zero. Negative numbers are numbers that are smaller than zero, and positive numbers are numbers that are bigger than zero.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With