/* Ported to JavaScript by Lazar Laszlo 2011 lazarsoft@gmail.com, www.lazarsoft.info */ /* * * Copyright 2007 ZXing authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function GF256Poly(field, coefficients) { if (coefficients == null || coefficients.length == 0) { throw "System.ArgumentException"; } this.field = field; var coefficientsLength = coefficients.length; if (coefficientsLength > 1 && coefficients[0] == 0) { // Leading term must be non-zero for anything except the constant polynomial "0" var firstNonZero = 1; while (firstNonZero < coefficientsLength && coefficients[firstNonZero] == 0) { firstNonZero++; } if (firstNonZero == coefficientsLength) { this.coefficients = field.Zero.coefficients; } else { this.coefficients = new Array(coefficientsLength - firstNonZero); for(var i=0;i largerCoefficients.length) { var temp = smallerCoefficients; smallerCoefficients = largerCoefficients; largerCoefficients = temp; } var sumDiff = new Array(largerCoefficients.length); var lengthDiff = largerCoefficients.length - smallerCoefficients.length; // Copy high-order terms only found in higher-degree polynomial's coefficients //Array.Copy(largerCoefficients, 0, sumDiff, 0, lengthDiff); for(var ci=0;ci= other.Degree && !remainder.Zero) { var degreeDifference = remainder.Degree - other.Degree; var scale = this.field.multiply(remainder.getCoefficient(remainder.Degree), inverseDenominatorLeadingTerm); var term = other.multiplyByMonomial(degreeDifference, scale); var iterationQuotient = this.field.buildMonomial(degreeDifference, scale); quotient = quotient.addOrSubtract(iterationQuotient); remainder = remainder.addOrSubtract(term); } return new Array(quotient, remainder); } }