Reduce undefined behaviour of casting NaN to an integer type

This fixes noise/popping issues when compiled with Cygwin 32-bit. casting a non-finite number to an integer type is undefined in C.

isnan() is a C99/C++11 function. I'm not sure whether this will break anywhere; apparently Windows has an _isnan() function that does the same thing but I haven't tested this.

Also, is there a possibility the mbelib output produces inf values; isinf() would have to be used to check that.