Exemple #1
0
 public ModulusPoly(ModulusGF field, int[] coefficients)
 {
    if (coefficients.Length == 0)
    {
       throw new ArgumentException();
    }
    this.field = field;
    int coefficientsLength = coefficients.Length;
    if (coefficientsLength > 1 && coefficients[0] == 0)
    {
       // Leading term must be non-zero for anything except the constant polynomial "0"
       int firstNonZero = 1;
       while (firstNonZero < coefficientsLength && coefficients[firstNonZero] == 0)
       {
          firstNonZero++;
       }
       if (firstNonZero == coefficientsLength)
       {
          this.coefficients = field.getZero().coefficients;
       }
       else
       {
          this.coefficients = new int[coefficientsLength - firstNonZero];
          Array.Copy(coefficients,
              firstNonZero,
              this.coefficients,
              0,
              this.coefficients.Length);
       }
    }
    else
    {
       this.coefficients = coefficients;
    }
 }
Exemple #2
0
        public ModulusPoly(ModulusGF field, int[] coefficients)
        {
            if (coefficients.Length == 0)
            {
                throw new ArgumentException();
            }
            this.field = field;
            int coefficientsLength = coefficients.Length;

            if (coefficientsLength > 1 && coefficients[0] == 0)
            {
                // Leading term must be non-zero for anything except the constant polynomial "0"
                int firstNonZero = 1;
                while (firstNonZero < coefficientsLength && coefficients[firstNonZero] == 0)
                {
                    firstNonZero++;
                }
                if (firstNonZero == coefficientsLength)
                {
                    this.coefficients = field.Zero.coefficients;
                }
                else
                {
                    this.coefficients = new int[coefficientsLength - firstNonZero];
                    Array.Copy(coefficients,
                               firstNonZero,
                               this.coefficients,
                               0,
                               this.coefficients.Length);
                }
            }
            else
            {
                this.coefficients = coefficients;
            }
        }