Improve handling of NaN.