Sharith.MathUtils.XMath.Sqrt C# (CSharp) Method

Sqrt() public static method

Berechnung der groessten Zahl, deren Quadrat n nicht uebersteigt.
public static Sqrt ( int n ) : int
n int
return int
        public static int Sqrt(int n)
        {
            if (n < 0)
            {
                throw new System.ArgumentOutOfRangeException(nameof(n) + " >= 0 required");
            }

            if (n == 0) return 0;

            int unten, oben = BitLength(n);

            do
            {
                unten = n / oben;
                oben += unten;
                oben >>= 1;
            }
            while (oben > unten);

            return oben;
        }