Update checked-in dependencies
This commit is contained in:
parent
47d5364431
commit
9dfa165835
185 changed files with 8301 additions and 3605 deletions
552
node_modules/long/index.js
generated
vendored
552
node_modules/long/index.js
generated
vendored
|
|
@ -21,69 +21,84 @@
|
|||
// WebAssembly optimizations to do native i64 multiplication and divide
|
||||
var wasm = null;
|
||||
try {
|
||||
wasm = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([
|
||||
// \0asm
|
||||
0, 97, 115, 109,
|
||||
// version 1
|
||||
1, 0, 0, 0,
|
||||
wasm = new WebAssembly.Instance(
|
||||
new WebAssembly.Module(
|
||||
new Uint8Array([
|
||||
// \0asm
|
||||
0, 97, 115, 109,
|
||||
// version 1
|
||||
1, 0, 0, 0,
|
||||
|
||||
// section "type"
|
||||
1, 13, 2,
|
||||
// 0, () => i32
|
||||
96, 0, 1, 127,
|
||||
// 1, (i32, i32, i32, i32) => i32
|
||||
96, 4, 127, 127, 127, 127, 1, 127,
|
||||
// section "type"
|
||||
1, 13, 2,
|
||||
// 0, () => i32
|
||||
96, 0, 1, 127,
|
||||
// 1, (i32, i32, i32, i32) => i32
|
||||
96, 4, 127, 127, 127, 127, 1, 127,
|
||||
|
||||
// section "function"
|
||||
3, 7, 6,
|
||||
// 0, type 0
|
||||
0,
|
||||
// 1, type 1
|
||||
1,
|
||||
// 2, type 1
|
||||
1,
|
||||
// 3, type 1
|
||||
1,
|
||||
// 4, type 1
|
||||
1,
|
||||
// 5, type 1
|
||||
1,
|
||||
// section "function"
|
||||
3, 7, 6,
|
||||
// 0, type 0
|
||||
0,
|
||||
// 1, type 1
|
||||
1,
|
||||
// 2, type 1
|
||||
1,
|
||||
// 3, type 1
|
||||
1,
|
||||
// 4, type 1
|
||||
1,
|
||||
// 5, type 1
|
||||
1,
|
||||
|
||||
// section "global"
|
||||
6, 6, 1,
|
||||
// 0, "high", mutable i32
|
||||
127, 1, 65, 0, 11,
|
||||
// section "global"
|
||||
6, 6, 1,
|
||||
// 0, "high", mutable i32
|
||||
127, 1, 65, 0, 11,
|
||||
|
||||
// section "export"
|
||||
7, 50, 6,
|
||||
// 0, "mul"
|
||||
3, 109, 117, 108, 0, 1,
|
||||
// 1, "div_s"
|
||||
5, 100, 105, 118, 95, 115, 0, 2,
|
||||
// 2, "div_u"
|
||||
5, 100, 105, 118, 95, 117, 0, 3,
|
||||
// 3, "rem_s"
|
||||
5, 114, 101, 109, 95, 115, 0, 4,
|
||||
// 4, "rem_u"
|
||||
5, 114, 101, 109, 95, 117, 0, 5,
|
||||
// 5, "get_high"
|
||||
8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0,
|
||||
// section "export"
|
||||
7, 50, 6,
|
||||
// 0, "mul"
|
||||
3, 109, 117, 108, 0, 1,
|
||||
// 1, "div_s"
|
||||
5, 100, 105, 118, 95, 115, 0, 2,
|
||||
// 2, "div_u"
|
||||
5, 100, 105, 118, 95, 117, 0, 3,
|
||||
// 3, "rem_s"
|
||||
5, 114, 101, 109, 95, 115, 0, 4,
|
||||
// 4, "rem_u"
|
||||
5, 114, 101, 109, 95, 117, 0, 5,
|
||||
// 5, "get_high"
|
||||
8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0,
|
||||
|
||||
// section "code"
|
||||
10, 191, 1, 6,
|
||||
// 0, "get_high"
|
||||
4, 0, 35, 0, 11,
|
||||
// 1, "mul"
|
||||
36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11,
|
||||
// 2, "div_s"
|
||||
36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11,
|
||||
// 3, "div_u"
|
||||
36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11,
|
||||
// 4, "rem_s"
|
||||
36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11,
|
||||
// 5, "rem_u"
|
||||
36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11
|
||||
])), {}).exports;
|
||||
// section "code"
|
||||
10, 191, 1, 6,
|
||||
// 0, "get_high"
|
||||
4, 0, 35, 0, 11,
|
||||
// 1, "mul"
|
||||
36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32,
|
||||
3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4,
|
||||
167, 11,
|
||||
// 2, "div_s"
|
||||
36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32,
|
||||
3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4,
|
||||
167, 11,
|
||||
// 3, "div_u"
|
||||
36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32,
|
||||
3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4,
|
||||
167, 11,
|
||||
// 4, "rem_s"
|
||||
36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32,
|
||||
3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4,
|
||||
167, 11,
|
||||
// 5, "rem_u"
|
||||
36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32,
|
||||
3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4,
|
||||
167, 11,
|
||||
]),
|
||||
),
|
||||
{},
|
||||
).exports;
|
||||
} catch {
|
||||
// no wasm support :(
|
||||
}
|
||||
|
|
@ -99,7 +114,6 @@ try {
|
|||
* @constructor
|
||||
*/
|
||||
function Long(low, high, unsigned) {
|
||||
|
||||
/**
|
||||
* The low 32 bits as a signed value.
|
||||
* @type {number}
|
||||
|
|
@ -199,25 +213,21 @@ function fromInt(value, unsigned) {
|
|||
var obj, cachedObj, cache;
|
||||
if (unsigned) {
|
||||
value >>>= 0;
|
||||
if (cache = (0 <= value && value < 256)) {
|
||||
if ((cache = 0 <= value && value < 256)) {
|
||||
cachedObj = UINT_CACHE[value];
|
||||
if (cachedObj)
|
||||
return cachedObj;
|
||||
if (cachedObj) return cachedObj;
|
||||
}
|
||||
obj = fromBits(value, 0, true);
|
||||
if (cache)
|
||||
UINT_CACHE[value] = obj;
|
||||
if (cache) UINT_CACHE[value] = obj;
|
||||
return obj;
|
||||
} else {
|
||||
value |= 0;
|
||||
if (cache = (-128 <= value && value < 128)) {
|
||||
if ((cache = -128 <= value && value < 128)) {
|
||||
cachedObj = INT_CACHE[value];
|
||||
if (cachedObj)
|
||||
return cachedObj;
|
||||
if (cachedObj) return cachedObj;
|
||||
}
|
||||
obj = fromBits(value, value < 0 ? -1 : 0, false);
|
||||
if (cache)
|
||||
INT_CACHE[value] = obj;
|
||||
if (cache) INT_CACHE[value] = obj;
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
|
@ -238,22 +248,20 @@ Long.fromInt = fromInt;
|
|||
* @inner
|
||||
*/
|
||||
function fromNumber(value, unsigned) {
|
||||
if (isNaN(value))
|
||||
return unsigned ? UZERO : ZERO;
|
||||
if (isNaN(value)) return unsigned ? UZERO : ZERO;
|
||||
if (unsigned) {
|
||||
if (value < 0)
|
||||
return UZERO;
|
||||
if (value >= TWO_PWR_64_DBL)
|
||||
return MAX_UNSIGNED_VALUE;
|
||||
if (value < 0) return UZERO;
|
||||
if (value >= TWO_PWR_64_DBL) return MAX_UNSIGNED_VALUE;
|
||||
} else {
|
||||
if (value <= -TWO_PWR_63_DBL)
|
||||
return MIN_VALUE;
|
||||
if (value + 1 >= TWO_PWR_63_DBL)
|
||||
return MAX_VALUE;
|
||||
if (value <= -TWO_PWR_63_DBL) return MIN_VALUE;
|
||||
if (value + 1 >= TWO_PWR_63_DBL) return MAX_VALUE;
|
||||
}
|
||||
if (value < 0)
|
||||
return fromNumber(-value, unsigned).neg();
|
||||
return fromBits((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
|
||||
if (value < 0) return fromNumber(-value, unsigned).neg();
|
||||
return fromBits(
|
||||
value % TWO_PWR_32_DBL | 0,
|
||||
(value / TWO_PWR_32_DBL) | 0,
|
||||
unsigned,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -304,24 +312,26 @@ var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4)
|
|||
* @inner
|
||||
*/
|
||||
function fromString(str, unsigned, radix) {
|
||||
if (str.length === 0)
|
||||
throw Error('empty string');
|
||||
if (typeof unsigned === 'number') {
|
||||
if (str.length === 0) throw Error("empty string");
|
||||
if (typeof unsigned === "number") {
|
||||
// For goog.math.long compatibility
|
||||
radix = unsigned;
|
||||
unsigned = false;
|
||||
} else {
|
||||
unsigned = !!unsigned;
|
||||
}
|
||||
if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
|
||||
if (
|
||||
str === "NaN" ||
|
||||
str === "Infinity" ||
|
||||
str === "+Infinity" ||
|
||||
str === "-Infinity"
|
||||
)
|
||||
return unsigned ? UZERO : ZERO;
|
||||
radix = radix || 10;
|
||||
if (radix < 2 || 36 < radix)
|
||||
throw RangeError('radix');
|
||||
if (radix < 2 || 36 < radix) throw RangeError("radix");
|
||||
|
||||
var p;
|
||||
if ((p = str.indexOf('-')) > 0)
|
||||
throw Error('interior hyphen');
|
||||
if ((p = str.indexOf("-")) > 0) throw Error("interior hyphen");
|
||||
else if (p === 0) {
|
||||
return fromString(str.substring(1), unsigned, radix).neg();
|
||||
}
|
||||
|
|
@ -364,12 +374,14 @@ Long.fromString = fromString;
|
|||
* @inner
|
||||
*/
|
||||
function fromValue(val, unsigned) {
|
||||
if (typeof val === 'number')
|
||||
return fromNumber(val, unsigned);
|
||||
if (typeof val === 'string')
|
||||
return fromString(val, unsigned);
|
||||
if (typeof val === "number") return fromNumber(val, unsigned);
|
||||
if (typeof val === "string") return fromString(val, unsigned);
|
||||
// Throws for non-objects, converts non-instanceof Long:
|
||||
return fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned);
|
||||
return fromBits(
|
||||
val.low,
|
||||
val.high,
|
||||
typeof unsigned === "boolean" ? unsigned : val.unsigned,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -490,7 +502,7 @@ Long.NEG_ONE = NEG_ONE;
|
|||
* @type {!Long}
|
||||
* @inner
|
||||
*/
|
||||
var MAX_VALUE = fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0, false);
|
||||
var MAX_VALUE = fromBits(0xffffffff | 0, 0x7fffffff | 0, false);
|
||||
|
||||
/**
|
||||
* Maximum signed value.
|
||||
|
|
@ -502,7 +514,7 @@ Long.MAX_VALUE = MAX_VALUE;
|
|||
* @type {!Long}
|
||||
* @inner
|
||||
*/
|
||||
var MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF | 0, 0xFFFFFFFF | 0, true);
|
||||
var MAX_UNSIGNED_VALUE = fromBits(0xffffffff | 0, 0xffffffff | 0, true);
|
||||
|
||||
/**
|
||||
* Maximum unsigned value.
|
||||
|
|
@ -544,7 +556,7 @@ LongPrototype.toInt = function toInt() {
|
|||
*/
|
||||
LongPrototype.toNumber = function toNumber() {
|
||||
if (this.unsigned)
|
||||
return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0);
|
||||
return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
|
||||
return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
|
||||
};
|
||||
|
||||
|
|
@ -558,11 +570,10 @@ LongPrototype.toNumber = function toNumber() {
|
|||
*/
|
||||
LongPrototype.toString = function toString(radix) {
|
||||
radix = radix || 10;
|
||||
if (radix < 2 || 36 < radix)
|
||||
throw RangeError('radix');
|
||||
if (this.isZero())
|
||||
return '0';
|
||||
if (this.isNegative()) { // Unsigned Longs are never negative
|
||||
if (radix < 2 || 36 < radix) throw RangeError("radix");
|
||||
if (this.isZero()) return "0";
|
||||
if (this.isNegative()) {
|
||||
// Unsigned Longs are never negative
|
||||
if (this.eq(MIN_VALUE)) {
|
||||
// We need to change the Long value before it can be negated, so we remove
|
||||
// the bottom-most digit in this base and then recurse to do the rest.
|
||||
|
|
@ -570,26 +581,23 @@ LongPrototype.toString = function toString(radix) {
|
|||
div = this.div(radixLong),
|
||||
rem1 = div.mul(radixLong).sub(this);
|
||||
return div.toString(radix) + rem1.toInt().toString(radix);
|
||||
} else
|
||||
return '-' + this.neg().toString(radix);
|
||||
} else return "-" + this.neg().toString(radix);
|
||||
}
|
||||
|
||||
// Do several (6) digits each time through the loop, so as to
|
||||
// minimize the calls to the very expensive emulated div.
|
||||
var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned),
|
||||
rem = this;
|
||||
var result = '';
|
||||
var result = "";
|
||||
while (true) {
|
||||
var remDiv = rem.div(radixToPower),
|
||||
intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0,
|
||||
digits = intval.toString(radix);
|
||||
rem = remDiv;
|
||||
if (rem.isZero())
|
||||
return digits + result;
|
||||
if (rem.isZero()) return digits + result;
|
||||
else {
|
||||
while (digits.length < 6)
|
||||
digits = '0' + digits;
|
||||
result = '' + digits + result;
|
||||
while (digits.length < 6) digits = "0" + digits;
|
||||
result = "" + digits + result;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -636,12 +644,11 @@ LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
|
|||
* @returns {number}
|
||||
*/
|
||||
LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
|
||||
if (this.isNegative()) // Unsigned Longs are never negative
|
||||
if (this.isNegative())
|
||||
// Unsigned Longs are never negative
|
||||
return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
|
||||
var val = this.high != 0 ? this.high : this.low;
|
||||
for (var bit = 31; bit > 0; bit--)
|
||||
if ((val & (1 << bit)) != 0)
|
||||
break;
|
||||
for (var bit = 31; bit > 0; bit--) if ((val & (1 << bit)) != 0) break;
|
||||
return this.high != 0 ? bit + 33 : bit + 1;
|
||||
};
|
||||
|
||||
|
|
@ -719,9 +726,12 @@ LongPrototype.isEven = function isEven() {
|
|||
* @returns {boolean}
|
||||
*/
|
||||
LongPrototype.equals = function equals(other) {
|
||||
if (!isLong(other))
|
||||
other = fromValue(other);
|
||||
if (this.unsigned !== other.unsigned && (this.high >>> 31) === 1 && (other.high >>> 31) === 1)
|
||||
if (!isLong(other)) other = 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;
|
||||
};
|
||||
|
|
@ -856,21 +866,19 @@ LongPrototype.ge = LongPrototype.greaterThanOrEqual;
|
|||
* if the given one is greater
|
||||
*/
|
||||
LongPrototype.compare = function compare(other) {
|
||||
if (!isLong(other))
|
||||
other = fromValue(other);
|
||||
if (this.eq(other))
|
||||
return 0;
|
||||
if (!isLong(other)) other = fromValue(other);
|
||||
if (this.eq(other)) return 0;
|
||||
var thisNeg = this.isNegative(),
|
||||
otherNeg = other.isNegative();
|
||||
if (thisNeg && !otherNeg)
|
||||
return -1;
|
||||
if (!thisNeg && otherNeg)
|
||||
return 1;
|
||||
if (thisNeg && !otherNeg) return -1;
|
||||
if (!thisNeg && otherNeg) return 1;
|
||||
// At this point the sign bits are the same
|
||||
if (!this.unsigned)
|
||||
return this.sub(other).isNegative() ? -1 : 1;
|
||||
if (!this.unsigned) return this.sub(other).isNegative() ? -1 : 1;
|
||||
// Both are positive if at least one is unsigned
|
||||
return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1;
|
||||
return other.high >>> 0 > this.high >>> 0 ||
|
||||
(other.high === this.high && other.low >>> 0 > this.low >>> 0)
|
||||
? -1
|
||||
: 1;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -888,8 +896,7 @@ LongPrototype.comp = LongPrototype.compare;
|
|||
* @returns {!Long} Negated Long
|
||||
*/
|
||||
LongPrototype.negate = function negate() {
|
||||
if (!this.unsigned && this.eq(MIN_VALUE))
|
||||
return MIN_VALUE;
|
||||
if (!this.unsigned && this.eq(MIN_VALUE)) return MIN_VALUE;
|
||||
return this.not().add(ONE);
|
||||
};
|
||||
|
||||
|
|
@ -907,33 +914,35 @@ LongPrototype.neg = LongPrototype.negate;
|
|||
* @returns {!Long} Sum
|
||||
*/
|
||||
LongPrototype.add = function add(addend) {
|
||||
if (!isLong(addend))
|
||||
addend = fromValue(addend);
|
||||
if (!isLong(addend)) addend = fromValue(addend);
|
||||
|
||||
// Divide each number into 4 chunks of 16 bits, and then sum the chunks.
|
||||
|
||||
var a48 = this.high >>> 16;
|
||||
var a32 = this.high & 0xFFFF;
|
||||
var a32 = this.high & 0xffff;
|
||||
var a16 = this.low >>> 16;
|
||||
var a00 = this.low & 0xFFFF;
|
||||
var a00 = this.low & 0xffff;
|
||||
|
||||
var b48 = addend.high >>> 16;
|
||||
var b32 = addend.high & 0xFFFF;
|
||||
var b32 = addend.high & 0xffff;
|
||||
var b16 = addend.low >>> 16;
|
||||
var b00 = addend.low & 0xFFFF;
|
||||
var b00 = addend.low & 0xffff;
|
||||
|
||||
var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
|
||||
var c48 = 0,
|
||||
c32 = 0,
|
||||
c16 = 0,
|
||||
c00 = 0;
|
||||
c00 += a00 + b00;
|
||||
c16 += c00 >>> 16;
|
||||
c00 &= 0xFFFF;
|
||||
c00 &= 0xffff;
|
||||
c16 += a16 + b16;
|
||||
c32 += c16 >>> 16;
|
||||
c16 &= 0xFFFF;
|
||||
c16 &= 0xffff;
|
||||
c32 += a32 + b32;
|
||||
c48 += c32 >>> 16;
|
||||
c32 &= 0xFFFF;
|
||||
c32 &= 0xffff;
|
||||
c48 += a48 + b48;
|
||||
c48 &= 0xFFFF;
|
||||
c48 &= 0xffff;
|
||||
return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
|
||||
};
|
||||
|
||||
|
|
@ -944,8 +953,7 @@ LongPrototype.add = function add(addend) {
|
|||
* @returns {!Long} Difference
|
||||
*/
|
||||
LongPrototype.subtract = function subtract(subtrahend) {
|
||||
if (!isLong(subtrahend))
|
||||
subtrahend = fromValue(subtrahend);
|
||||
if (!isLong(subtrahend)) subtrahend = fromValue(subtrahend);
|
||||
return this.add(subtrahend.neg());
|
||||
};
|
||||
|
||||
|
|
@ -964,34 +972,23 @@ LongPrototype.sub = LongPrototype.subtract;
|
|||
* @returns {!Long} Product
|
||||
*/
|
||||
LongPrototype.multiply = function multiply(multiplier) {
|
||||
if (this.isZero())
|
||||
return this;
|
||||
if (!isLong(multiplier))
|
||||
multiplier = fromValue(multiplier);
|
||||
if (this.isZero()) return this;
|
||||
if (!isLong(multiplier)) multiplier = fromValue(multiplier);
|
||||
|
||||
// use wasm support if present
|
||||
if (wasm) {
|
||||
var low = wasm["mul"](this.low,
|
||||
this.high,
|
||||
multiplier.low,
|
||||
multiplier.high);
|
||||
var low = wasm["mul"](this.low, this.high, multiplier.low, multiplier.high);
|
||||
return fromBits(low, wasm["get_high"](), this.unsigned);
|
||||
}
|
||||
|
||||
if (multiplier.isZero())
|
||||
return this.unsigned ? UZERO : ZERO;
|
||||
if (this.eq(MIN_VALUE))
|
||||
return multiplier.isOdd() ? MIN_VALUE : ZERO;
|
||||
if (multiplier.eq(MIN_VALUE))
|
||||
return this.isOdd() ? MIN_VALUE : ZERO;
|
||||
if (multiplier.isZero()) return this.unsigned ? UZERO : ZERO;
|
||||
if (this.eq(MIN_VALUE)) return multiplier.isOdd() ? MIN_VALUE : ZERO;
|
||||
if (multiplier.eq(MIN_VALUE)) return this.isOdd() ? MIN_VALUE : ZERO;
|
||||
|
||||
if (this.isNegative()) {
|
||||
if (multiplier.isNegative())
|
||||
return this.neg().mul(multiplier.neg());
|
||||
else
|
||||
return this.neg().mul(multiplier).neg();
|
||||
} else if (multiplier.isNegative())
|
||||
return this.mul(multiplier.neg()).neg();
|
||||
if (multiplier.isNegative()) return this.neg().mul(multiplier.neg());
|
||||
else return this.neg().mul(multiplier).neg();
|
||||
} else if (multiplier.isNegative()) return this.mul(multiplier.neg()).neg();
|
||||
|
||||
// If both longs are small, use float multiplication
|
||||
if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24))
|
||||
|
|
@ -1001,36 +998,39 @@ LongPrototype.multiply = function multiply(multiplier) {
|
|||
// We can skip products that would overflow.
|
||||
|
||||
var a48 = this.high >>> 16;
|
||||
var a32 = this.high & 0xFFFF;
|
||||
var a32 = this.high & 0xffff;
|
||||
var a16 = this.low >>> 16;
|
||||
var a00 = this.low & 0xFFFF;
|
||||
var a00 = this.low & 0xffff;
|
||||
|
||||
var b48 = multiplier.high >>> 16;
|
||||
var b32 = multiplier.high & 0xFFFF;
|
||||
var b32 = multiplier.high & 0xffff;
|
||||
var b16 = multiplier.low >>> 16;
|
||||
var b00 = multiplier.low & 0xFFFF;
|
||||
var b00 = multiplier.low & 0xffff;
|
||||
|
||||
var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
|
||||
var c48 = 0,
|
||||
c32 = 0,
|
||||
c16 = 0,
|
||||
c00 = 0;
|
||||
c00 += a00 * b00;
|
||||
c16 += c00 >>> 16;
|
||||
c00 &= 0xFFFF;
|
||||
c00 &= 0xffff;
|
||||
c16 += a16 * b00;
|
||||
c32 += c16 >>> 16;
|
||||
c16 &= 0xFFFF;
|
||||
c16 &= 0xffff;
|
||||
c16 += a00 * b16;
|
||||
c32 += c16 >>> 16;
|
||||
c16 &= 0xFFFF;
|
||||
c16 &= 0xffff;
|
||||
c32 += a32 * b00;
|
||||
c48 += c32 >>> 16;
|
||||
c32 &= 0xFFFF;
|
||||
c32 &= 0xffff;
|
||||
c32 += a16 * b16;
|
||||
c48 += c32 >>> 16;
|
||||
c32 &= 0xFFFF;
|
||||
c32 &= 0xffff;
|
||||
c32 += a00 * b32;
|
||||
c48 += c32 >>> 16;
|
||||
c32 &= 0xFFFF;
|
||||
c32 &= 0xffff;
|
||||
c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
|
||||
c48 &= 0xFFFF;
|
||||
c48 &= 0xffff;
|
||||
return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
|
||||
};
|
||||
|
||||
|
|
@ -1050,19 +1050,20 @@ LongPrototype.mul = LongPrototype.multiply;
|
|||
* @returns {!Long} Quotient
|
||||
*/
|
||||
LongPrototype.divide = function divide(divisor) {
|
||||
if (!isLong(divisor))
|
||||
divisor = fromValue(divisor);
|
||||
if (divisor.isZero())
|
||||
throw Error('division by zero');
|
||||
if (!isLong(divisor)) divisor = fromValue(divisor);
|
||||
if (divisor.isZero()) throw Error("division by zero");
|
||||
|
||||
// use wasm support if present
|
||||
if (wasm) {
|
||||
// guard against signed division overflow: the largest
|
||||
// negative number / -1 would be 1 larger than the largest
|
||||
// positive number, due to two's complement.
|
||||
if (!this.unsigned &&
|
||||
if (
|
||||
!this.unsigned &&
|
||||
this.high === -0x80000000 &&
|
||||
divisor.low === -1 && divisor.high === -1) {
|
||||
divisor.low === -1 &&
|
||||
divisor.high === -1
|
||||
) {
|
||||
// be consistent with non-wasm code path
|
||||
return this;
|
||||
}
|
||||
|
|
@ -1070,22 +1071,20 @@ LongPrototype.divide = function divide(divisor) {
|
|||
this.low,
|
||||
this.high,
|
||||
divisor.low,
|
||||
divisor.high
|
||||
divisor.high,
|
||||
);
|
||||
return fromBits(low, wasm["get_high"](), this.unsigned);
|
||||
}
|
||||
|
||||
if (this.isZero())
|
||||
return this.unsigned ? UZERO : ZERO;
|
||||
if (this.isZero()) return this.unsigned ? UZERO : ZERO;
|
||||
var approx, rem, res;
|
||||
if (!this.unsigned) {
|
||||
// This section is only relevant for signed longs and is derived from the
|
||||
// closure library as a whole.
|
||||
if (this.eq(MIN_VALUE)) {
|
||||
if (divisor.eq(ONE) || divisor.eq(NEG_ONE))
|
||||
return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE
|
||||
else if (divisor.eq(MIN_VALUE))
|
||||
return ONE;
|
||||
return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE
|
||||
else if (divisor.eq(MIN_VALUE)) return ONE;
|
||||
else {
|
||||
// At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
|
||||
var halfThis = this.shr(1);
|
||||
|
|
@ -1098,23 +1097,19 @@ LongPrototype.divide = function divide(divisor) {
|
|||
return res;
|
||||
}
|
||||
}
|
||||
} else if (divisor.eq(MIN_VALUE))
|
||||
return this.unsigned ? UZERO : ZERO;
|
||||
} else if (divisor.eq(MIN_VALUE)) return this.unsigned ? UZERO : ZERO;
|
||||
if (this.isNegative()) {
|
||||
if (divisor.isNegative())
|
||||
return this.neg().div(divisor.neg());
|
||||
if (divisor.isNegative()) return this.neg().div(divisor.neg());
|
||||
return this.neg().div(divisor).neg();
|
||||
} else if (divisor.isNegative())
|
||||
return this.div(divisor.neg()).neg();
|
||||
} else if (divisor.isNegative()) return this.div(divisor.neg()).neg();
|
||||
res = ZERO;
|
||||
} else {
|
||||
// The algorithm below has not been made for unsigned longs. It's therefore
|
||||
// required to take special care of the MSB prior to running it.
|
||||
if (!divisor.unsigned)
|
||||
divisor = divisor.toUnsigned();
|
||||
if (divisor.gt(this))
|
||||
return UZERO;
|
||||
if (divisor.gt(this.shru(1))) // 15 >>> 1 = 7 ; with divisor = 8 ; true
|
||||
if (!divisor.unsigned) divisor = divisor.toUnsigned();
|
||||
if (divisor.gt(this)) return UZERO;
|
||||
if (divisor.gt(this.shru(1)))
|
||||
// 15 >>> 1 = 7 ; with divisor = 8 ; true
|
||||
return UONE;
|
||||
res = UZERO;
|
||||
}
|
||||
|
|
@ -1133,8 +1128,7 @@ LongPrototype.divide = function divide(divisor) {
|
|||
// We will tweak the approximate result by changing it in the 48-th digit or
|
||||
// the smallest non-fractional digit, whichever is larger.
|
||||
var log2 = Math.ceil(Math.log(approx) / Math.LN2),
|
||||
delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48),
|
||||
|
||||
delta = log2 <= 48 ? 1 : pow_dbl(2, log2 - 48),
|
||||
// Decrease the approximation until it is smaller than the remainder. Note
|
||||
// that if it is too large, the product overflows and is negative.
|
||||
approxRes = fromNumber(approx),
|
||||
|
|
@ -1147,8 +1141,7 @@ LongPrototype.divide = function divide(divisor) {
|
|||
|
||||
// We know the answer can't be zero... and actually, zero would cause
|
||||
// infinite recursion since we would make no progress.
|
||||
if (approxRes.isZero())
|
||||
approxRes = ONE;
|
||||
if (approxRes.isZero()) approxRes = ONE;
|
||||
|
||||
res = res.add(approxRes);
|
||||
rem = rem.sub(approxRem);
|
||||
|
|
@ -1171,8 +1164,7 @@ LongPrototype.div = LongPrototype.divide;
|
|||
* @returns {!Long} Remainder
|
||||
*/
|
||||
LongPrototype.modulo = function modulo(divisor) {
|
||||
if (!isLong(divisor))
|
||||
divisor = fromValue(divisor);
|
||||
if (!isLong(divisor)) divisor = fromValue(divisor);
|
||||
|
||||
// use wasm support if present
|
||||
if (wasm) {
|
||||
|
|
@ -1180,7 +1172,7 @@ LongPrototype.modulo = function modulo(divisor) {
|
|||
this.low,
|
||||
this.high,
|
||||
divisor.low,
|
||||
divisor.high
|
||||
divisor.high,
|
||||
);
|
||||
return fromBits(low, wasm["get_high"](), this.unsigned);
|
||||
}
|
||||
|
|
@ -1254,8 +1246,7 @@ LongPrototype.ctz = LongPrototype.countTrailingZeros;
|
|||
* @returns {!Long}
|
||||
*/
|
||||
LongPrototype.and = function and(other) {
|
||||
if (!isLong(other))
|
||||
other = fromValue(other);
|
||||
if (!isLong(other)) other = fromValue(other);
|
||||
return fromBits(this.low & other.low, this.high & other.high, this.unsigned);
|
||||
};
|
||||
|
||||
|
|
@ -1266,8 +1257,7 @@ LongPrototype.and = function and(other) {
|
|||
* @returns {!Long}
|
||||
*/
|
||||
LongPrototype.or = function or(other) {
|
||||
if (!isLong(other))
|
||||
other = fromValue(other);
|
||||
if (!isLong(other)) other = fromValue(other);
|
||||
return fromBits(this.low | other.low, this.high | other.high, this.unsigned);
|
||||
};
|
||||
|
||||
|
|
@ -1278,8 +1268,7 @@ LongPrototype.or = function or(other) {
|
|||
* @returns {!Long}
|
||||
*/
|
||||
LongPrototype.xor = function xor(other) {
|
||||
if (!isLong(other))
|
||||
other = fromValue(other);
|
||||
if (!isLong(other)) other = fromValue(other);
|
||||
return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
|
||||
};
|
||||
|
||||
|
|
@ -1290,14 +1279,15 @@ LongPrototype.xor = function xor(other) {
|
|||
* @returns {!Long} Shifted Long
|
||||
*/
|
||||
LongPrototype.shiftLeft = function shiftLeft(numBits) {
|
||||
if (isLong(numBits))
|
||||
numBits = numBits.toInt();
|
||||
if ((numBits &= 63) === 0)
|
||||
return this;
|
||||
if (isLong(numBits)) numBits = numBits.toInt();
|
||||
if ((numBits &= 63) === 0) return this;
|
||||
else if (numBits < 32)
|
||||
return fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned);
|
||||
else
|
||||
return fromBits(0, this.low << (numBits - 32), this.unsigned);
|
||||
return fromBits(
|
||||
this.low << numBits,
|
||||
(this.high << numBits) | (this.low >>> (32 - numBits)),
|
||||
this.unsigned,
|
||||
);
|
||||
else return fromBits(0, this.low << (numBits - 32), this.unsigned);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -1315,14 +1305,20 @@ LongPrototype.shl = LongPrototype.shiftLeft;
|
|||
* @returns {!Long} Shifted Long
|
||||
*/
|
||||
LongPrototype.shiftRight = function shiftRight(numBits) {
|
||||
if (isLong(numBits))
|
||||
numBits = numBits.toInt();
|
||||
if ((numBits &= 63) === 0)
|
||||
return this;
|
||||
if (isLong(numBits)) numBits = numBits.toInt();
|
||||
if ((numBits &= 63) === 0) return this;
|
||||
else if (numBits < 32)
|
||||
return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned);
|
||||
return fromBits(
|
||||
(this.low >>> numBits) | (this.high << (32 - numBits)),
|
||||
this.high >> numBits,
|
||||
this.unsigned,
|
||||
);
|
||||
else
|
||||
return fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned);
|
||||
return fromBits(
|
||||
this.high >> (numBits - 32),
|
||||
this.high >= 0 ? 0 : -1,
|
||||
this.unsigned,
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -1342,7 +1338,12 @@ LongPrototype.shr = LongPrototype.shiftRight;
|
|||
LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
|
||||
if (isLong(numBits)) numBits = numBits.toInt();
|
||||
if ((numBits &= 63) === 0) return this;
|
||||
if (numBits < 32) return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >>> numBits, this.unsigned);
|
||||
if (numBits < 32)
|
||||
return fromBits(
|
||||
(this.low >>> numBits) | (this.high << (32 - numBits)),
|
||||
this.high >>> numBits,
|
||||
this.unsigned,
|
||||
);
|
||||
if (numBits === 32) return fromBits(this.high, 0, this.unsigned);
|
||||
return fromBits(this.high >>> (numBits - 32), 0, this.unsigned);
|
||||
};
|
||||
|
|
@ -1375,13 +1376,21 @@ LongPrototype.rotateLeft = function rotateLeft(numBits) {
|
|||
if ((numBits &= 63) === 0) return this;
|
||||
if (numBits === 32) return fromBits(this.high, this.low, this.unsigned);
|
||||
if (numBits < 32) {
|
||||
b = (32 - numBits);
|
||||
return fromBits(((this.low << numBits) | (this.high >>> b)), ((this.high << numBits) | (this.low >>> b)), this.unsigned);
|
||||
b = 32 - numBits;
|
||||
return fromBits(
|
||||
(this.low << numBits) | (this.high >>> b),
|
||||
(this.high << numBits) | (this.low >>> b),
|
||||
this.unsigned,
|
||||
);
|
||||
}
|
||||
numBits -= 32;
|
||||
b = (32 - numBits);
|
||||
return fromBits(((this.high << numBits) | (this.low >>> b)), ((this.low << numBits) | (this.high >>> b)), this.unsigned);
|
||||
}
|
||||
b = 32 - numBits;
|
||||
return fromBits(
|
||||
(this.high << numBits) | (this.low >>> b),
|
||||
(this.low << numBits) | (this.high >>> b),
|
||||
this.unsigned,
|
||||
);
|
||||
};
|
||||
/**
|
||||
* Returns this Long with bits rotated to the left by the given amount. This is an alias of {@link Long#rotateLeft}.
|
||||
* @function
|
||||
|
|
@ -1402,13 +1411,21 @@ LongPrototype.rotateRight = function rotateRight(numBits) {
|
|||
if ((numBits &= 63) === 0) return this;
|
||||
if (numBits === 32) return fromBits(this.high, this.low, this.unsigned);
|
||||
if (numBits < 32) {
|
||||
b = (32 - numBits);
|
||||
return fromBits(((this.high << b) | (this.low >>> numBits)), ((this.low << b) | (this.high >>> numBits)), this.unsigned);
|
||||
b = 32 - numBits;
|
||||
return fromBits(
|
||||
(this.high << b) | (this.low >>> numBits),
|
||||
(this.low << b) | (this.high >>> numBits),
|
||||
this.unsigned,
|
||||
);
|
||||
}
|
||||
numBits -= 32;
|
||||
b = (32 - numBits);
|
||||
return fromBits(((this.low << b) | (this.high >>> numBits)), ((this.high << b) | (this.low >>> numBits)), this.unsigned);
|
||||
}
|
||||
b = 32 - numBits;
|
||||
return fromBits(
|
||||
(this.low << b) | (this.high >>> numBits),
|
||||
(this.high << b) | (this.low >>> numBits),
|
||||
this.unsigned,
|
||||
);
|
||||
};
|
||||
/**
|
||||
* Returns this Long with bits rotated to the right by the given amount. This is an alias of {@link Long#rotateRight}.
|
||||
* @function
|
||||
|
|
@ -1423,8 +1440,7 @@ LongPrototype.rotr = LongPrototype.rotateRight;
|
|||
* @returns {!Long} Signed long
|
||||
*/
|
||||
LongPrototype.toSigned = function toSigned() {
|
||||
if (!this.unsigned)
|
||||
return this;
|
||||
if (!this.unsigned) return this;
|
||||
return fromBits(this.low, this.high, false);
|
||||
};
|
||||
|
||||
|
|
@ -1434,8 +1450,7 @@ LongPrototype.toSigned = function toSigned() {
|
|||
* @returns {!Long} Unsigned long
|
||||
*/
|
||||
LongPrototype.toUnsigned = function toUnsigned() {
|
||||
if (this.unsigned)
|
||||
return this;
|
||||
if (this.unsigned) return this;
|
||||
return fromBits(this.low, this.high, true);
|
||||
};
|
||||
|
||||
|
|
@ -1459,13 +1474,13 @@ LongPrototype.toBytesLE = function toBytesLE() {
|
|||
lo = this.low;
|
||||
return [
|
||||
lo & 0xff,
|
||||
lo >>> 8 & 0xff,
|
||||
lo >>> 16 & 0xff,
|
||||
(lo >>> 8) & 0xff,
|
||||
(lo >>> 16) & 0xff,
|
||||
lo >>> 24,
|
||||
hi & 0xff,
|
||||
hi >>> 8 & 0xff,
|
||||
hi >>> 16 & 0xff,
|
||||
hi >>> 24
|
||||
(hi >>> 8) & 0xff,
|
||||
(hi >>> 16) & 0xff,
|
||||
hi >>> 24,
|
||||
];
|
||||
};
|
||||
|
||||
|
|
@ -1479,13 +1494,13 @@ LongPrototype.toBytesBE = function toBytesBE() {
|
|||
lo = this.low;
|
||||
return [
|
||||
hi >>> 24,
|
||||
hi >>> 16 & 0xff,
|
||||
hi >>> 8 & 0xff,
|
||||
(hi >>> 16) & 0xff,
|
||||
(hi >>> 8) & 0xff,
|
||||
hi & 0xff,
|
||||
lo >>> 24,
|
||||
lo >>> 16 & 0xff,
|
||||
lo >>> 8 & 0xff,
|
||||
lo & 0xff
|
||||
(lo >>> 16) & 0xff,
|
||||
(lo >>> 8) & 0xff,
|
||||
lo & 0xff,
|
||||
];
|
||||
};
|
||||
|
||||
|
|
@ -1497,7 +1512,9 @@ LongPrototype.toBytesBE = function toBytesBE() {
|
|||
* @returns {Long} The corresponding Long value
|
||||
*/
|
||||
Long.fromBytes = function fromBytes(bytes, unsigned, le) {
|
||||
return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned);
|
||||
return le
|
||||
? Long.fromBytesLE(bytes, unsigned)
|
||||
: Long.fromBytesBE(bytes, unsigned);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -1508,15 +1525,9 @@ Long.fromBytes = function fromBytes(bytes, unsigned, le) {
|
|||
*/
|
||||
Long.fromBytesLE = function fromBytesLE(bytes, unsigned) {
|
||||
return new Long(
|
||||
bytes[0] |
|
||||
bytes[1] << 8 |
|
||||
bytes[2] << 16 |
|
||||
bytes[3] << 24,
|
||||
bytes[4] |
|
||||
bytes[5] << 8 |
|
||||
bytes[6] << 16 |
|
||||
bytes[7] << 24,
|
||||
unsigned
|
||||
bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24),
|
||||
bytes[4] | (bytes[5] << 8) | (bytes[6] << 16) | (bytes[7] << 24),
|
||||
unsigned,
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -1528,21 +1539,14 @@ Long.fromBytesLE = function fromBytesLE(bytes, unsigned) {
|
|||
*/
|
||||
Long.fromBytesBE = function fromBytesBE(bytes, unsigned) {
|
||||
return new Long(
|
||||
bytes[4] << 24 |
|
||||
bytes[5] << 16 |
|
||||
bytes[6] << 8 |
|
||||
bytes[7],
|
||||
bytes[0] << 24 |
|
||||
bytes[1] << 16 |
|
||||
bytes[2] << 8 |
|
||||
bytes[3],
|
||||
unsigned
|
||||
(bytes[4] << 24) | (bytes[5] << 16) | (bytes[6] << 8) | bytes[7],
|
||||
(bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3],
|
||||
unsigned,
|
||||
);
|
||||
};
|
||||
|
||||
// Support conversion to/from BigInt where available
|
||||
if (typeof BigInt === "function") {
|
||||
|
||||
/**
|
||||
* Returns a Long representing the given big integer.
|
||||
* @function
|
||||
|
|
@ -1558,10 +1562,9 @@ if (typeof BigInt === "function") {
|
|||
|
||||
// Override
|
||||
Long.fromValue = function fromValueWithBigInt(value, unsigned) {
|
||||
if (typeof value === "bigint")
|
||||
return fromBigInt(value, unsigned);
|
||||
if (typeof value === "bigint") return fromBigInt(value, unsigned);
|
||||
return fromValue(value, unsigned);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts the Long to its big integer representation.
|
||||
|
|
@ -1571,9 +1574,8 @@ if (typeof BigInt === "function") {
|
|||
LongPrototype.toBigInt = function toBigInt() {
|
||||
var lowBigInt = BigInt(this.low >>> 0);
|
||||
var highBigInt = BigInt(this.unsigned ? this.high >>> 0 : this.high);
|
||||
return highBigInt << BigInt(32) | lowBigInt;
|
||||
return (highBigInt << BigInt(32)) | lowBigInt;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
export default Long;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue