BigInteger.Equals C# (CSharp) Method

Equals() public method

public Equals ( object o ) : bool
o object
return bool
        public override bool Equals(object o)
        {
                BigInteger bi = (BigInteger)o;

                if(this.dataLength != bi.dataLength)
                        return false;

                for(int i = 0; i < this.dataLength; i++)
                {
                        if(this.data[i] != bi.data[i])
                                return false;
                }
                return true;
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Runs the EEA on two BigIntegers
        /// </summary>
        /// <param name="A">Quotient A</param>
        /// <param name="B">Quotient B</param>
        /// <returns>Return a BigIntEuclidean object that contains the result in the variables X, Y, and GCD</returns>
        /// 
        /// <remarks>
        /// Implemented from pseudocode on <a href="http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm"/>Wikipedia
        /// </remarks>
        public static BigIntEuclidean Calculate(BigInteger A, BigInteger B)
        {
            BigInteger x = BigInteger.Zero;
            BigInteger lastX = BigInteger.One;
            BigInteger y = BigInteger.One;
            BigInteger lastY = BigInteger.Zero;

            while (!B.Equals(BigInteger.Zero))
            {
                BigInteger[] quotientAndRemainder = A.DivideAndRemainder(B);
                BigInteger quotient = quotientAndRemainder[0];
                BigInteger temp = A;

                A = B;
                B = quotientAndRemainder[1];

                temp = x;
                x = lastX.Subtract(quotient.Multiply(x));
                lastX = temp;

                temp = y;
                y = lastY.Subtract(quotient.Multiply(y));
                lastY = temp;
            }

            BigIntEuclidean result = new BigIntEuclidean();
            result.X = lastX;
            result.Y = lastY;
            result.GCD = A;

            return result;
        }
All Usage Examples Of BigInteger::Equals