Home Ask Login Register

Developers Planet

Your answer is one click away!

Arrofi Reza Satria 2 weeks ago

The devide of NaN plus number does not result the NaN value

Im using Double.isNaN() to detect NaN value. `

    Double nan  = Double.NaN;
    Double num  = 1.5;
    Double num2 = 4.5;

    Double result = (nan+num)/num2;

    System.out.println(result);// the result is NaN

    if(Double.isNaN(result))
        System.out.println("not NaN");//true`

Is there any other way to detect NaN value?

Answers


Mureinik 2 weeks ago

Your condition doesn't correspond to your output - you check if the result is in fact a NaN, but then print that it isn't. Either check that it isn't:

if (!Double.isNaN(result))
    System.out.println("not NaN"); // This won't be reached in your case

Or print that it is:

if (Double.isNaN(result))
    System.out.println("NaN");

Post Status

Asked in 2 weeks ago
Viewed 2,133 times
Voted 7
Answered 1 times

Search




Leave an answer


Quote of the day: live life