define(["require", "exports", "../../utils"], function (require, exports, utils_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _PdfBigInt = (function () {
function _PdfBigInt(decimalStr) {
if (decimalStr === void 0) { decimalStr = '0'; }
this.digits = this._parseDecimalString(decimalStr);
}
_PdfBigInt.prototype._parseDecimalString = function (str) {
return str.split('').reverse().map(function (d) { return parseInt(d, 10); });
};
_PdfBigInt.prototype._toString = function () {
return this.digits.slice().reverse().join('').replace(/^0+/, '') || '0';
};
_PdfBigInt.prototype._toBigInt = function () {
var str = this.digits.slice().reverse().join('').replace(/^0+/, '') || '0';
var bigIntConstructor = utils_1._getBigInt();
return bigIntConstructor(str);
};
_PdfBigInt.prototype._add = function (n) {
var carry = n;
for (var i = 0; i < this.digits.length || carry > 0; i++) {
var sum = (this.digits[i] || 0) + carry;
this.digits[i] = sum % 10;
carry = Math.floor(sum / 10);
}
};
_PdfBigInt.prototype._multiply = function () {
var carry = 0;
for (var i = 0; i < this.digits.length; i++) {
var product = this.digits[i] * 256 + carry;
this.digits[i] = product % 10;
carry = Math.floor(product / 10);
}
while (carry > 0) {
this.digits.push(carry % 10);
carry = Math.floor(carry / 10);
}
};
_PdfBigInt.prototype._bitLength = function () {
var digits = this.digits.slice();
var bits = 0;
while (digits.length > 1 || digits[0] !== 0) {
var carry = 0;
for (var i = digits.length - 1; i >= 0; i--) {
var current = carry * 10 + digits[i];
digits[i] = Math.floor(current / 2);
carry = current % 2;
}
while (digits.length > 1 && digits[digits.length - 1] === 0) {
digits.pop();
}
bits++;
}
return bits;
};
return _PdfBigInt;
}());
exports._PdfBigInt = _PdfBigInt;
});
|