My method is as follows
def myMethod(myDouble: Double): Double = myDouble match {
case Double.NaN => ...
case _ => ...
}
The IntelliJ debugger is showing NaN but this is not being picked up in my pattern matching. Are there possible cases I am omitting
It is a general rule how 64-bit floating point numbers are compared according to IEEE 754 (not Scala or even Java related, see NaN):
The idea is that
NaNis a marker value for unknown or indeterminate. Comparing two unknown values should always yieldsfalseas they are well… unknown.If you want to use pattern matching with
NaN, try this:But I think pattern matching will use strict double comparison so be careful with this construct.