multiply() private method

Multiplies the specified a with b.
private multiply ( int a, int b ) : int
a int A.
b int The b.
return int
Esempio n. 1
0
        /// <summary>
        /// evaluation of this polynomial at a given point
        /// </summary>
        /// <param name="a">A.</param>
        /// <returns>evaluation of this polynomial at a given point</returns>
        internal int evaluateAt(int a)
        {
            int result = 0;

            if (a == 0)
            {
                // Just return the x^0 coefficient
                return(getCoefficient(0));
            }
            int size = coefficients.Length;

            if (a == 1)
            {
                // Just the sum of the coefficients
                foreach (var coefficient in coefficients)
                {
                    result = GenericGF.addOrSubtract(result, coefficient);
                }
                return(result);
            }
            result = coefficients[0];
            for (int i = 1; i < size; i++)
            {
                result = GenericGF.addOrSubtract(field.multiply(a, result), coefficients[i]);
            }
            return(result);
        }
Esempio n. 2
0
        internal GenericGFPoly multiply(GenericGFPoly other)
        {
            if (!field.Equals(other.field))
            {
                throw new ArgumentException("GenericGFPolys do not have same GenericGF field");
            }
            if (isZero || other.isZero)
            {
                return(field.Zero);
            }
            int[] aCoefficients = this.coefficients;
            int   aLength       = aCoefficients.Length;

            int[] bCoefficients = other.coefficients;
            int   bLength       = bCoefficients.Length;

            int[] product = new int[aLength + bLength - 1];
            for (int i = 0; i < aLength; i++)
            {
                int aCoeff = aCoefficients[i];
                for (int j = 0; j < bLength; j++)
                {
                    product[i + j] = GenericGF.addOrSubtract(product[i + j],
                                                             field.multiply(aCoeff, bCoefficients[j]));
                }
            }
            return(new GenericGFPoly(field, product));
        }