stats: fix handling of NaN in `min` and `max`

The `cmp::min` and `cmp::max` functions are not correct with partially
ordered values. #12712