0 votes
1 view
in Java by (3.4k points)

I have a double in Java and I want to check if it is NaN. What is the best way to do this?

1 Answer

0 votes
by (46.1k points)

Try the static Double.isNaN(double) way, or your Double's .isNaN() method.

// 1. static method

if (Double.isNaN(doubleValue)) {

...

}

// 2. object's method

if (doubleObject.isNaN()) {

...

}

By Easily trying:

if (var == Double.NaN) {

...

}

is not sufficient due to how the IEEE standard for NaN and floating-point numbers are defined.

Related questions

0 votes
1 answer
+14 votes
2 answers
asked May 26, 2019 in Java by tommas (1k points)
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...