Since isnan() is only available in c++11, I prefer not to backport this so v2.3. At variance with older commit fba71ad4 I here only perform the check at the first step