Use isnan() to check for NaN values

isnan() is specified by POSIX.1, so even though it's not part of C++98, this will still work pretty much everywhere except Windows.

It's also a bit less confusing to read than what I pushed yesterday.