fix potential floating point exception when converting NaN to int. Thanks to @bkuhls