检查数字是否等于另一个数字的平方根c#

check if number is equal to the square root of another number c#

我想看看一个数是否等于另一个数的平方根。我写了一个方法来实现这一点,但它会搜索到最大 Int32 值(这会花费很长时间)。我真的很想搜索大于 100(我设置的当前限制)以外的数字,但我不确定最大值应该是多少。

public static string IsSqrtOfNum(double num, int counter = 1)
{
    while (true)
    {
        if (Math.Sqrt(counter) == num)
        {
            return "√" + counter.ToString();
        }
        if (counter >= 100) break;
        counter++;
    }
    return num.ToString();
}

感谢@Mike McCaughan:

public static string GetSqrOfNum(double num)
{
    return "√" + (num*num).ToString();
}