handle NaN, -Infinity and +Infinity