/** * Singleton pattern * * @return QR_Math Singleton */ public static function getInstance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * Return error correction polynom * * @param int $errorCorrectLength * @return QR_Polynominal */ public function getErrorCorrectPolynominal($errorCorrectLength) { $a = new QR_Polynominal(array(1), 0); for ($i = 0; $i < $errorCorrectLength; $i++) { $a = $a->multiply(new QR_Polynominal(array(1, QR_Math::getInstance()->gexp($i)), 0)); } return $a; }
/** * Perform modulus against another polynom * * @param QR_Polynominal $e * * @return QR_Polynominal */ public function mod(QR_Polynominal $e) { if ($this->getLength() - $e->getLength() < 0) { return $this; } $ratio = QR_Math::getInstance()->glog($this->get(0)) - QR_Math::getInstance()->glog($e->get(0)); $num = QR_Util::getInstance()->createEmptyArray($this->getLength()); for ($i = 0; $i < $this->getLength(); $i++) { $num[$i] = $this->get($i); } for ($i = 0; $i < $e->getLength(); $i++) { $num[$i] ^= QR_Math::getInstance()->gexp(QR_Math::getInstance()->glog($e->get($i)) + $ratio); } $result = new QR_Polynominal($num, 0); $result = $result->mod($e); return $result; }