Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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) ...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading