NaN comparisons were inconsistent

Nan comparisons were inconsistent: !(nan < 0) and !(nan == 0) but nan <= 0. This caused subtle errors.

This patch makes comparisons with NaN behave according to IEEE 754.