Why does this function return NaN? - C#