I just ran into a nasty bug as a result of the following behavior:
scala> List(1.0, 2.0, 3.0, Double.NaN).min
res1: Double = NaN
scala> List(1.0, 2.0, 3.0
For
val a = List(1.0, 2.0, 3.0, Double.NaN)
sort it,
a.sortWith {_ >_ }
res: List[Double] = List(3.0, 2.0, 1.0, NaN)
and so NaN
values are relegated, thus for max,
a.sortWith {_ >_ }.head
res: Double = 3.0
Likewise
a.sortWith {_ < _ }
res: List[Double] = List(1.0, 2.0, 3.0, NaN)
and so for min,
a.sortWith {_ < _ }.head
res: Double = 1.0