Posted at

KotlinでNaN判定

More than 3 years have passed since last update.

JavaのDouble.isNan()はないので、KotlinのDoubleの拡張メソッドを使う。Floatも同様。

if (num == Double.NaN || num === Double.NaN) {

// never
}
if (num.isNaN()) {
// num is not-a-number
}