123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946 |
- (function(global) {
- "use strict";
-
- var Long = function(low, high, unsigned) {
-
- this.low = low|0;
-
- this.high = high|0;
-
- this.unsigned = !!unsigned;
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Long.isLong = function(obj) {
- return (obj && obj instanceof Long) === true;
- };
-
- var INT_CACHE = {};
-
- var UINT_CACHE = {};
-
- Long.fromInt = function(value, unsigned) {
- var obj, cachedObj;
- if (!unsigned) {
- value = value | 0;
- if (-128 <= value && value < 128) {
- cachedObj = INT_CACHE[value];
- if (cachedObj)
- return cachedObj;
- }
- obj = new Long(value, value < 0 ? -1 : 0, false);
- if (-128 <= value && value < 128)
- INT_CACHE[value] = obj;
- return obj;
- } else {
- value = value >>> 0;
- if (0 <= value && value < 256) {
- cachedObj = UINT_CACHE[value];
- if (cachedObj)
- return cachedObj;
- }
- obj = new Long(value, (value | 0) < 0 ? -1 : 0, true);
- if (0 <= value && value < 256)
- UINT_CACHE[value] = obj;
- return obj;
- }
- };
-
- Long.fromNumber = function(value, unsigned) {
- unsigned = !!unsigned;
- if (isNaN(value) || !isFinite(value))
- return Long.ZERO;
- if (!unsigned && value <= -TWO_PWR_63_DBL)
- return Long.MIN_VALUE;
- if (!unsigned && value + 1 >= TWO_PWR_63_DBL)
- return Long.MAX_VALUE;
- if (unsigned && value >= TWO_PWR_64_DBL)
- return Long.MAX_UNSIGNED_VALUE;
- if (value < 0)
- return Long.fromNumber(-value, unsigned).negate();
- return new Long((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
- };
-
- Long.fromBits = function(lowBits, highBits, unsigned) {
- return new Long(lowBits, highBits, unsigned);
- };
-
- Long.fromString = function(str, unsigned, radix) {
- if (str.length === 0)
- throw Error('number format error: empty string');
- if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
- return Long.ZERO;
- if (typeof unsigned === 'number')
- radix = unsigned,
- unsigned = false;
- radix = radix || 10;
- if (radix < 2 || 36 < radix)
- throw Error('radix out of range: ' + radix);
- var p;
- if ((p = str.indexOf('-')) > 0)
- throw Error('number format error: interior "-" character: ' + str);
- else if (p === 0)
- return Long.fromString(str.substring(1), unsigned, radix).negate();
-
-
- var radixToPower = Long.fromNumber(Math.pow(radix, 8));
- var result = Long.ZERO;
- for (var i = 0; i < str.length; i += 8) {
- var size = Math.min(8, str.length - i);
- var value = parseInt(str.substring(i, i + size), radix);
- if (size < 8) {
- var power = Long.fromNumber(Math.pow(radix, size));
- result = result.multiply(power).add(Long.fromNumber(value));
- } else {
- result = result.multiply(radixToPower);
- result = result.add(Long.fromNumber(value));
- }
- }
- result.unsigned = unsigned;
- return result;
- };
-
- Long.fromValue = function(val) {
- if (typeof val === 'number')
- return Long.fromNumber(val);
- if (typeof val === 'string')
- return Long.fromString(val);
- if (Long.isLong(val))
- return val;
-
- return new Long(val.low, val.high, val.unsigned);
- };
-
-
-
- var TWO_PWR_16_DBL = 1 << 16;
-
- var TWO_PWR_24_DBL = 1 << 24;
-
- var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
-
- var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
-
- var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
-
- var TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
-
- Long.ZERO = Long.fromInt(0);
-
- Long.UZERO = Long.fromInt(0, true);
-
- Long.ONE = Long.fromInt(1);
-
- Long.UONE = Long.fromInt(1, true);
-
- Long.NEG_ONE = Long.fromInt(-1);
-
- Long.MAX_VALUE = Long.fromBits(0xFFFFFFFF|0, 0x7FFFFFFF|0, false);
-
- Long.MAX_UNSIGNED_VALUE = Long.fromBits(0xFFFFFFFF|0, 0xFFFFFFFF|0, true);
-
- Long.MIN_VALUE = Long.fromBits(0, 0x80000000|0, false);
-
- Long.prototype.toInt = function() {
- return this.unsigned ? this.low >>> 0 : this.low;
- };
-
- Long.prototype.toNumber = function() {
- if (this.unsigned) {
- return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0);
- }
- return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
- };
-
- Long.prototype.toString = function(radix) {
- radix = radix || 10;
- if (radix < 2 || 36 < radix)
- throw RangeError('radix out of range: ' + radix);
- if (this.isZero())
- return '0';
- var rem;
- if (this.isNegative()) {
- if (this.equals(Long.MIN_VALUE)) {
-
-
- var radixLong = Long.fromNumber(radix);
- var div = this.div(radixLong);
- rem = div.multiply(radixLong).subtract(this);
- return div.toString(radix) + rem.toInt().toString(radix);
- } else
- return '-' + this.negate().toString(radix);
- }
-
-
- var radixToPower = Long.fromNumber(Math.pow(radix, 6), this.unsigned);
- rem = this;
- var result = '';
- while (true) {
- var remDiv = rem.div(radixToPower),
- intval = rem.subtract(remDiv.multiply(radixToPower)).toInt() >>> 0,
- digits = intval.toString(radix);
- rem = remDiv;
- if (rem.isZero())
- return digits + result;
- else {
- while (digits.length < 6)
- digits = '0' + digits;
- result = '' + digits + result;
- }
- }
- };
-
- Long.prototype.getHighBits = function() {
- return this.high;
- };
-
- Long.prototype.getHighBitsUnsigned = function() {
- return this.high >>> 0;
- };
-
- Long.prototype.getLowBits = function() {
- return this.low;
- };
-
- Long.prototype.getLowBitsUnsigned = function() {
- return this.low >>> 0;
- };
-
- Long.prototype.getNumBitsAbs = function() {
- if (this.isNegative())
- return this.equals(Long.MIN_VALUE) ? 64 : this.negate().getNumBitsAbs();
- var val = this.high != 0 ? this.high : this.low;
- for (var bit = 31; bit > 0; bit--)
- if ((val & (1 << bit)) != 0)
- break;
- return this.high != 0 ? bit + 33 : bit + 1;
- };
-
- Long.prototype.isZero = function() {
- return this.high === 0 && this.low === 0;
- };
-
- Long.prototype.isNegative = function() {
- return !this.unsigned && this.high < 0;
- };
-
- Long.prototype.isPositive = function() {
- return this.unsigned || this.high >= 0;
- };
-
- Long.prototype.isOdd = function() {
- return (this.low & 1) === 1;
- };
-
- Long.prototype.isEven = function() {
- return (this.low & 1) === 0;
- };
-
- Long.prototype.equals = function(other) {
- if (!Long.isLong(other))
- other = Long.fromValue(other);
- if (this.unsigned !== other.unsigned && (this.high >>> 31) === 1 && (other.high >>> 31) === 1)
- return false;
- return this.high === other.high && this.low === other.low;
- };
-
- Long.prototype.notEquals = function(other) {
- if (!Long.isLong(other))
- other = Long.fromValue(other);
- return !this.equals(other);
- };
-
- Long.prototype.lessThan = function(other) {
- if (!Long.isLong(other))
- other = Long.fromValue(other);
- return this.compare(other) < 0;
- };
-
- Long.prototype.lessThanOrEqual = function(other) {
- if (!Long.isLong(other))
- other = Long.fromValue(other);
- return this.compare(other) <= 0;
- };
-
- Long.prototype.greaterThan = function(other) {
- if (!Long.isLong(other))
- other = Long.fromValue(other);
- return this.compare(other) > 0;
- };
-
- Long.prototype.greaterThanOrEqual = function(other) {
- if (!Long.isLong(other))
- other = Long.fromValue(other);
- return this.compare(other) >= 0;
- };
-
- Long.prototype.compare = function(other) {
- if (this.equals(other))
- return 0;
- var thisNeg = this.isNegative(),
- otherNeg = other.isNegative();
- if (thisNeg && !otherNeg)
- return -1;
- if (!thisNeg && otherNeg)
- return 1;
-
- if (!this.unsigned)
- return this.subtract(other).isNegative() ? -1 : 1;
-
- return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1;
- };
-
- Long.prototype.negate = function() {
- if (!this.unsigned && this.equals(Long.MIN_VALUE))
- return Long.MIN_VALUE;
- return this.not().add(Long.ONE);
- };
-
- Long.prototype.add = function(addend) {
- if (!Long.isLong(addend))
- addend = Long.fromValue(addend);
-
- var a48 = this.high >>> 16;
- var a32 = this.high & 0xFFFF;
- var a16 = this.low >>> 16;
- var a00 = this.low & 0xFFFF;
- var b48 = addend.high >>> 16;
- var b32 = addend.high & 0xFFFF;
- var b16 = addend.low >>> 16;
- var b00 = addend.low & 0xFFFF;
- var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
- c00 += a00 + b00;
- c16 += c00 >>> 16;
- c00 &= 0xFFFF;
- c16 += a16 + b16;
- c32 += c16 >>> 16;
- c16 &= 0xFFFF;
- c32 += a32 + b32;
- c48 += c32 >>> 16;
- c32 &= 0xFFFF;
- c48 += a48 + b48;
- c48 &= 0xFFFF;
- return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
- };
-
- Long.prototype.subtract = function(subtrahend) {
- if (!Long.isLong(subtrahend))
- subtrahend = Long.fromValue(subtrahend);
- return this.add(subtrahend.negate());
- };
-
- Long.prototype.multiply = function(multiplier) {
- if (this.isZero())
- return Long.ZERO;
- if (!Long.isLong(multiplier))
- multiplier = Long.fromValue(multiplier);
- if (multiplier.isZero())
- return Long.ZERO;
- if (this.equals(Long.MIN_VALUE))
- return multiplier.isOdd() ? Long.MIN_VALUE : Long.ZERO;
- if (multiplier.equals(Long.MIN_VALUE))
- return this.isOdd() ? Long.MIN_VALUE : Long.ZERO;
- if (this.isNegative()) {
- if (multiplier.isNegative())
- return this.negate().multiply(multiplier.negate());
- else
- return this.negate().multiply(multiplier).negate();
- } else if (multiplier.isNegative())
- return this.multiply(multiplier.negate()).negate();
-
- if (this.lessThan(TWO_PWR_24) && multiplier.lessThan(TWO_PWR_24))
- return Long.fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
-
-
- var a48 = this.high >>> 16;
- var a32 = this.high & 0xFFFF;
- var a16 = this.low >>> 16;
- var a00 = this.low & 0xFFFF;
- var b48 = multiplier.high >>> 16;
- var b32 = multiplier.high & 0xFFFF;
- var b16 = multiplier.low >>> 16;
- var b00 = multiplier.low & 0xFFFF;
- var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
- c00 += a00 * b00;
- c16 += c00 >>> 16;
- c00 &= 0xFFFF;
- c16 += a16 * b00;
- c32 += c16 >>> 16;
- c16 &= 0xFFFF;
- c16 += a00 * b16;
- c32 += c16 >>> 16;
- c16 &= 0xFFFF;
- c32 += a32 * b00;
- c48 += c32 >>> 16;
- c32 &= 0xFFFF;
- c32 += a16 * b16;
- c48 += c32 >>> 16;
- c32 &= 0xFFFF;
- c32 += a00 * b32;
- c48 += c32 >>> 16;
- c32 &= 0xFFFF;
- c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
- c48 &= 0xFFFF;
- return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
- };
-
- Long.prototype.div = function(divisor) {
- if (!Long.isLong(divisor))
- divisor = Long.fromValue(divisor);
- if (divisor.isZero())
- throw(new Error('division by zero'));
- if (this.isZero())
- return this.unsigned ? Long.UZERO : Long.ZERO;
- var approx, rem, res;
- if (this.equals(Long.MIN_VALUE)) {
- if (divisor.equals(Long.ONE) || divisor.equals(Long.NEG_ONE))
- return Long.MIN_VALUE;
- else if (divisor.equals(Long.MIN_VALUE))
- return Long.ONE;
- else {
-
- var halfThis = this.shiftRight(1);
- approx = halfThis.div(divisor).shiftLeft(1);
- if (approx.equals(Long.ZERO)) {
- return divisor.isNegative() ? Long.ONE : Long.NEG_ONE;
- } else {
- rem = this.subtract(divisor.multiply(approx));
- res = approx.add(rem.div(divisor));
- return res;
- }
- }
- } else if (divisor.equals(Long.MIN_VALUE))
- return this.unsigned ? Long.UZERO : Long.ZERO;
- if (this.isNegative()) {
- if (divisor.isNegative())
- return this.negate().div(divisor.negate());
- return this.negate().div(divisor).negate();
- } else if (divisor.isNegative())
- return this.div(divisor.negate()).negate();
-
-
-
-
-
- res = Long.ZERO;
- rem = this;
- while (rem.greaterThanOrEqual(divisor)) {
-
-
- approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
-
-
- var log2 = Math.ceil(Math.log(approx) / Math.LN2),
- delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48),
-
-
- approxRes = Long.fromNumber(approx),
- approxRem = approxRes.multiply(divisor);
- while (approxRem.isNegative() || approxRem.greaterThan(rem)) {
- approx -= delta;
- approxRes = Long.fromNumber(approx, this.unsigned);
- approxRem = approxRes.multiply(divisor);
- }
-
-
- if (approxRes.isZero())
- approxRes = Long.ONE;
- res = res.add(approxRes);
- rem = rem.subtract(approxRem);
- }
- return res;
- };
-
- Long.prototype.modulo = function(divisor) {
- if (!Long.isLong(divisor))
- divisor = Long.fromValue(divisor);
- return this.subtract(this.div(divisor).multiply(divisor));
- };
-
- Long.prototype.not = function() {
- return Long.fromBits(~this.low, ~this.high, this.unsigned);
- };
-
- Long.prototype.and = function(other) {
- if (!Long.isLong(other))
- other = Long.fromValue(other);
- return Long.fromBits(this.low & other.low, this.high & other.high, this.unsigned);
- };
-
- Long.prototype.or = function(other) {
- if (!Long.isLong(other))
- other = Long.fromValue(other);
- return Long.fromBits(this.low | other.low, this.high | other.high, this.unsigned);
- };
-
- Long.prototype.xor = function(other) {
- if (!Long.isLong(other))
- other = Long.fromValue(other);
- return Long.fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
- };
-
- Long.prototype.shiftLeft = function(numBits) {
- if (Long.isLong(numBits))
- numBits = numBits.toInt();
- if ((numBits &= 63) === 0)
- return this;
- else if (numBits < 32)
- return Long.fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned);
- else
- return Long.fromBits(0, this.low << (numBits - 32), this.unsigned);
- };
-
- Long.prototype.shiftRight = function(numBits) {
- if (Long.isLong(numBits))
- numBits = numBits.toInt();
- if ((numBits &= 63) === 0)
- return this;
- else if (numBits < 32)
- return Long.fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned);
- else
- return Long.fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned);
- };
-
- Long.prototype.shiftRightUnsigned = function(numBits) {
- if (Long.isLong(numBits))
- numBits = numBits.toInt();
- numBits &= 63;
- if (numBits === 0)
- return this;
- else {
- var high = this.high;
- if (numBits < 32) {
- var low = this.low;
- return Long.fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned);
- } else if (numBits === 32)
- return Long.fromBits(high, 0, this.unsigned);
- else
- return Long.fromBits(high >>> (numBits - 32), 0, this.unsigned);
- }
- };
-
- Long.prototype.toSigned = function() {
- if (!this.unsigned)
- return this;
- return new Long(this.low, this.high, false);
- };
-
- Long.prototype.toUnsigned = function() {
- if (this.unsigned)
- return this;
- return new Long(this.low, this.high, true);
- };
- if (typeof require === 'function' && typeof module === 'object' && module && typeof exports === 'object' && exports)
- module["exports"] = Long;
- else if (typeof define === 'function' && define["amd"])
- define(function() { return Long; });
- else
- (global["dcodeIO"] = global["dcodeIO"] || {})["Long"] = Long;
-
- })(this);
|