mirror of
https://github.com/apache/cordova-android.git
synced 2026-04-23 00:00:09 +08:00
CB-11138 Bump cordova-common to 1.2.0
This commit is contained in:
+49
-43
@@ -7,17 +7,25 @@ var bigInt = (function (undefined) {
|
||||
MAX_INT_ARR = smallToArray(MAX_INT),
|
||||
LOG_MAX_INT = Math.log(MAX_INT);
|
||||
|
||||
function Integer(v, radix) {
|
||||
if (typeof v === "undefined") return Integer[0];
|
||||
if (typeof radix !== "undefined") return +radix === 10 ? parseValue(v) : parseBase(v, radix);
|
||||
return parseValue(v);
|
||||
}
|
||||
|
||||
function BigInteger(value, sign) {
|
||||
this.value = value;
|
||||
this.sign = sign;
|
||||
this.isSmall = false;
|
||||
}
|
||||
BigInteger.prototype = Object.create(Integer.prototype);
|
||||
|
||||
function SmallInteger(value) {
|
||||
this.value = value;
|
||||
this.sign = value < 0;
|
||||
this.isSmall = true;
|
||||
}
|
||||
SmallInteger.prototype = Object.create(Integer.prototype);
|
||||
|
||||
function isPrecise(n) {
|
||||
return -MAX_INT < n && n < MAX_INT;
|
||||
@@ -323,7 +331,7 @@ var bigInt = (function (undefined) {
|
||||
sign = this.sign !== n.sign,
|
||||
abs;
|
||||
if (n.isSmall) {
|
||||
if (b === 0) return CACHE[0];
|
||||
if (b === 0) return Integer[0];
|
||||
if (b === 1) return this;
|
||||
if (b === -1) return this.negate();
|
||||
abs = Math.abs(b);
|
||||
@@ -345,20 +353,20 @@ var bigInt = (function (undefined) {
|
||||
}
|
||||
return new BigInteger(multiplyLong(b, smallToArray(a)), sign);
|
||||
}
|
||||
SmallInteger.prototype["_multiplyBySmall"] = function (a) {
|
||||
SmallInteger.prototype._multiplyBySmall = function (a) {
|
||||
if (isPrecise(a.value * this.value)) {
|
||||
return new SmallInteger(a.value * this.value);
|
||||
}
|
||||
return multiplySmallAndArray(Math.abs(a.value), smallToArray(Math.abs(this.value)), this.sign !== a.sign);
|
||||
};
|
||||
BigInteger.prototype["_multiplyBySmall"] = function (a) {
|
||||
if (a.value === 0) return CACHE[0];
|
||||
BigInteger.prototype._multiplyBySmall = function (a) {
|
||||
if (a.value === 0) return Integer[0];
|
||||
if (a.value === 1) return this;
|
||||
if (a.value === -1) return this.negate();
|
||||
return multiplySmallAndArray(Math.abs(a.value), this.value, this.sign !== a.sign);
|
||||
};
|
||||
SmallInteger.prototype.multiply = function (v) {
|
||||
return parseValue(v)["_multiplyBySmall"](this);
|
||||
return parseValue(v)._multiplyBySmall(this);
|
||||
};
|
||||
SmallInteger.prototype.times = SmallInteger.prototype.multiply;
|
||||
|
||||
@@ -506,11 +514,11 @@ var bigInt = (function (undefined) {
|
||||
if (n.isSmall) {
|
||||
return [new SmallInteger(truncate(a / b)), new SmallInteger(a % b)];
|
||||
}
|
||||
return [CACHE[0], self];
|
||||
return [Integer[0], self];
|
||||
}
|
||||
if (n.isSmall) {
|
||||
if (b === 1) return [self, CACHE[0]];
|
||||
if (b == -1) return [self.negate(), CACHE[0]];
|
||||
if (b === 1) return [self, Integer[0]];
|
||||
if (b == -1) return [self.negate(), Integer[0]];
|
||||
var abs = Math.abs(b);
|
||||
if (abs < BASE) {
|
||||
value = divModSmall(a, abs);
|
||||
@@ -526,8 +534,8 @@ var bigInt = (function (undefined) {
|
||||
b = smallToArray(abs);
|
||||
}
|
||||
var comparison = compareAbs(a, b);
|
||||
if (comparison === -1) return [CACHE[0], self];
|
||||
if (comparison === 0) return [CACHE[self.sign === n.sign ? 1 : -1], CACHE[0]];
|
||||
if (comparison === -1) return [Integer[0], self];
|
||||
if (comparison === 0) return [Integer[self.sign === n.sign ? 1 : -1], Integer[0]];
|
||||
|
||||
// divMod1 is faster on smaller input sizes
|
||||
if (a.length + b.length <= 200)
|
||||
@@ -573,12 +581,12 @@ var bigInt = (function (undefined) {
|
||||
a = this.value,
|
||||
b = n.value,
|
||||
value, x, y;
|
||||
if (b === 0) return CACHE[1];
|
||||
if (a === 0) return CACHE[0];
|
||||
if (a === 1) return CACHE[1];
|
||||
if (a === -1) return n.isEven() ? CACHE[1] : CACHE[-1];
|
||||
if (b === 0) return Integer[1];
|
||||
if (a === 0) return Integer[0];
|
||||
if (a === 1) return Integer[1];
|
||||
if (a === -1) return n.isEven() ? Integer[1] : Integer[-1];
|
||||
if (n.sign) {
|
||||
return CACHE[0];
|
||||
return Integer[0];
|
||||
}
|
||||
if (!n.isSmall) throw new Error("The exponent " + n.toString() + " is too large.");
|
||||
if (this.isSmall) {
|
||||
@@ -586,7 +594,7 @@ var bigInt = (function (undefined) {
|
||||
return new SmallInteger(truncate(value));
|
||||
}
|
||||
x = this;
|
||||
y = CACHE[1];
|
||||
y = Integer[1];
|
||||
while (true) {
|
||||
if (b & 1 === 1) {
|
||||
y = y.times(x);
|
||||
@@ -604,10 +612,10 @@ var bigInt = (function (undefined) {
|
||||
exp = parseValue(exp);
|
||||
mod = parseValue(mod);
|
||||
if (mod.isZero()) throw new Error("Cannot take modPow with modulus 0");
|
||||
var r = CACHE[1],
|
||||
var r = Integer[1],
|
||||
base = this.mod(mod);
|
||||
while (exp.isPositive()) {
|
||||
if (base.isZero()) return CACHE[0];
|
||||
if (base.isZero()) return Integer[0];
|
||||
if (exp.isOdd()) r = r.multiply(base).mod(mod);
|
||||
exp = exp.divide(2);
|
||||
base = base.square().mod(mod);
|
||||
@@ -765,7 +773,7 @@ var bigInt = (function (undefined) {
|
||||
if (value === 0) return false;
|
||||
if (value === 1) return true;
|
||||
if (value === 2) return this.isEven();
|
||||
return this.mod(n).equals(CACHE[0]);
|
||||
return this.mod(n).equals(Integer[0]);
|
||||
};
|
||||
SmallInteger.prototype.isDivisibleBy = BigInteger.prototype.isDivisibleBy;
|
||||
|
||||
@@ -776,7 +784,7 @@ var bigInt = (function (undefined) {
|
||||
if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5)) return false;
|
||||
if (n.lesser(25)) return true;
|
||||
// we don't know if it's prime: let the other functions figure it out
|
||||
};
|
||||
}
|
||||
|
||||
BigInteger.prototype.isPrime = function () {
|
||||
var isPrime = isBasicPrime(this);
|
||||
@@ -789,7 +797,7 @@ var bigInt = (function (undefined) {
|
||||
while (b.isEven()) b = b.divide(2);
|
||||
for (i = 0; i < a.length; i++) {
|
||||
x = bigInt(a[i]).modPow(b, n);
|
||||
if (x.equals(CACHE[1]) || x.equals(nPrev)) continue;
|
||||
if (x.equals(Integer[1]) || x.equals(nPrev)) continue;
|
||||
for (t = true, d = b; t && d.lesser(nPrev) ; d = d.multiply(2)) {
|
||||
x = x.square().mod(n);
|
||||
if (x.equals(nPrev)) t = false;
|
||||
@@ -961,7 +969,7 @@ var bigInt = (function (undefined) {
|
||||
if (a.equals(b)) return a;
|
||||
if (a.isZero()) return b;
|
||||
if (b.isZero()) return a;
|
||||
var c = CACHE[1], d, t;
|
||||
var c = Integer[1], d, t;
|
||||
while (a.isEven() && b.isEven()) {
|
||||
d = Math.min(roughLOB(a), roughLOB(b));
|
||||
a = a.divide(d);
|
||||
@@ -1005,7 +1013,7 @@ var bigInt = (function (undefined) {
|
||||
return low.add(typeof result === "number" ? new SmallInteger(result) : new BigInteger(result, false));
|
||||
}
|
||||
var parseBase = function (text, base) {
|
||||
var val = CACHE[0], pow = CACHE[1],
|
||||
var val = Integer[0], pow = Integer[1],
|
||||
length = text.length;
|
||||
if (2 <= base && base <= 36) {
|
||||
if (length <= LOG_MAX_INT / Math.log(base)) {
|
||||
@@ -1117,7 +1125,7 @@ var bigInt = (function (undefined) {
|
||||
var sign = v[0] === "-";
|
||||
if (sign) v = v.slice(1);
|
||||
var split = v.split(/e/i);
|
||||
if (split.length > 2) throw new Error("Invalid integer: " + text.join("e"));
|
||||
if (split.length > 2) throw new Error("Invalid integer: " + split.join("e"));
|
||||
if (split.length === 2) {
|
||||
var exp = split[1];
|
||||
if (exp[0] === "+") exp = exp.slice(1);
|
||||
@@ -1147,8 +1155,11 @@ var bigInt = (function (undefined) {
|
||||
}
|
||||
|
||||
function parseNumberValue(v) {
|
||||
if (isPrecise(v)) return new SmallInteger(v);
|
||||
return parseStringValue(v.toString());
|
||||
if (isPrecise(v)) {
|
||||
if (v !== truncate(v)) throw new Error(v + " is not an integer.");
|
||||
return new SmallInteger(v);
|
||||
}
|
||||
return parseStringValue(v.toString());
|
||||
}
|
||||
|
||||
function parseValue(v) {
|
||||
@@ -1161,26 +1172,21 @@ var bigInt = (function (undefined) {
|
||||
return v;
|
||||
}
|
||||
// Pre-define numbers in range [-999,999]
|
||||
var CACHE = function (v, radix) {
|
||||
if (typeof v === "undefined") return CACHE[0];
|
||||
if (typeof radix !== "undefined") return +radix === 10 ? parseValue(v) : parseBase(v, radix);
|
||||
return parseValue(v);
|
||||
};
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
CACHE[i] = new SmallInteger(i);
|
||||
if (i > 0) CACHE[-i] = new SmallInteger(-i);
|
||||
Integer[i] = new SmallInteger(i);
|
||||
if (i > 0) Integer[-i] = new SmallInteger(-i);
|
||||
}
|
||||
// Backwards compatibility
|
||||
CACHE.one = CACHE[1];
|
||||
CACHE.zero = CACHE[0];
|
||||
CACHE.minusOne = CACHE[-1];
|
||||
CACHE.max = max;
|
||||
CACHE.min = min;
|
||||
CACHE.gcd = gcd;
|
||||
CACHE.lcm = lcm;
|
||||
CACHE.isInstance = function (x) { return x instanceof BigInteger || x instanceof SmallInteger; };
|
||||
CACHE.randBetween = randBetween;
|
||||
return CACHE;
|
||||
Integer.one = Integer[1];
|
||||
Integer.zero = Integer[0];
|
||||
Integer.minusOne = Integer[-1];
|
||||
Integer.max = max;
|
||||
Integer.min = min;
|
||||
Integer.gcd = gcd;
|
||||
Integer.lcm = lcm;
|
||||
Integer.isInstance = function (x) { return x instanceof BigInteger || x instanceof SmallInteger; };
|
||||
Integer.randBetween = randBetween;
|
||||
return Integer;
|
||||
})();
|
||||
|
||||
// Node.js check
|
||||
|
||||
Reference in New Issue
Block a user