'How to check if double is NEGATIVE_INFINITY in Java
How do I check if double is NEGATIVE_INFINITY and not POSITIVE_INFINITY?
There is only one method in Double class isInfinite() which checks whether the double is infinite or not but it returns true in both cases if it's positive and if it's negative. So is there another way to check the specific infinity (negative or positive)?
Solution 1:[1]
Here are two possible ways to check if a double x specifically holds negative infinity:
if (Double.isInfinite(x) && x < 0) ...
or simply
if (x==Double.NEGATIVE_INFINITY) ...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | khelwood |
