Fix bug of endless loop when isNaN

Signed-off-by: Itai Koren <itkoren@gmail.com>