Check your power source is stable. (change it) That's how I got rid of this NaN issue. Nasty little serial port FTDI device that had 3.3v must have been spiking or similar.