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)
More Related Contents:
- Why do floating-point numbers have signed zeros?
- Floating point arithmetic not producing exact results [duplicate]
- How to nicely format floating numbers to string without unnecessary decimal 0’s
- Double vs. BigDecimal?
- Why does the division of two integers return 0.0 in Java? [duplicate]
- Why does integer division code give the wrong answer? [duplicate]
- Float and double datatype in Java
- Format Float to n decimal places
- Why does Math.round(0.49999999999999994) return 1?
- How to convert float to int with Java
- Why does Double.NaN==Double.NaN return false?
- How to check that a string is parseable to a double? [duplicate]
- Why does (360 / 24) / 60 = 0 … in Java
- Why is Double.MIN_VALUE in not negative
- Java:Why should we use BigDecimal instead of Double in the real world? [duplicate]
- Java floating point high precision library [closed]
- Meaning of delta or epsilon argument of assertEquals for double values
- Why does this subtraction not equal zero?
- What do F and D mean at the end of numeric literals?
- How to get the decimal part of a float?
- What is the inclusive range of float and double in Java?
- Why does adding 0.1 multiple times remain lossless?
- Why is Java’s Double.compare(double, double) implemented the way it is?
- Loss of precision – int -> float or double
- Long float-number output shows letters
- Java: Inaccuracy using double [duplicate]
- What’s wrong with this division? [duplicate]
- How to convert pcm samples in byte array as floating point numbers in the range -1.0 to 1.0 and back?
- Is checking a double for equality ever safe?
- What is float in Java?