How can “while (i == i) ;” be a non-infinite loop in a single threaded application?

前端 未结 12 1110
甜味超标
甜味超标 2020-12-04 09:41

I just got a question that I can\'t answer.

Suppose you have this loop definition in Java:

while (i == i) ;

What is the type of

12条回答
  •  春和景丽
    2020-12-04 10:19

    Since others said it's NaN I got curious about the official (JDK 6) implementation of Double.isNaN, and behold:

    /**
     * Returns true if the specified number is a
     * Not-a-Number (NaN) value, false otherwise.
     *
     * @param   v   the value to be tested.
     * @return  true if the value of the argument is NaN;
     *          false otherwise.
     */
    static public boolean isNaN(double v) {
        return (v != v);
    }
    

提交回复
热议问题