Unfortunately, isNaN
is a method on java.lang.Double
, and it is essential to have an implicit conversion to java.lang.Double
, so the Scala RichDouble
value class cannot reimplement isNaN
to be fast, and when you use isNaN
you box to java.lang.Double
.
Since this leaves only slow or awkward ways to test for NaN
, I define
implicit class RicherDouble(val d: Double) extends AnyVal {
def nan = java.lang.Double.isNaN(d)
}
and then I can just use .nan
to check.