Use isnan() to check for NaN values

isnan() is specified by POSIX.1, so if you don't care about Windows,
this is as portable as can be.