added NaN test for squared_distance