Other minor dependencies updates in 7.1.x patch

This commit is contained in:
Christopher J. Brody
2018-11-22 09:57:22 -05:00
parent d918c7a83c
commit 5a5f544a48
18 changed files with 401 additions and 237 deletions
+31 -18
View File
@@ -785,29 +785,44 @@ var bigInt = (function (undefined) {
if (n.isUnit()) return false;
if (n.equals(2) || n.equals(3) || n.equals(5)) return true;
if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5)) return false;
if (n.lesser(25)) return true;
if (n.lesser(49)) 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);
if (isPrime !== undefined) return isPrime;
var n = this.abs(),
nPrev = n.prev();
var a = [2, 3, 5, 7, 11, 13, 17, 19],
function millerRabinTest(n, a) {
var nPrev = n.prev(),
b = nPrev,
r = 0,
d, t, i, x;
while (b.isEven()) b = b.divide(2);
for (i = 0; i < a.length; i++) {
while (b.isEven()) b = b.divide(2), r++;
next : for (i = 0; i < a.length; i++) {
if (n.lesser(a[i])) continue;
x = bigInt(a[i]).modPow(b, n);
if (x.equals(Integer[1]) || x.equals(nPrev)) continue;
for (t = true, d = b; t && d.lesser(nPrev); d = d.multiply(2)) {
for (d = r - 1; d != 0; d--) {
x = x.square().mod(n);
if (x.equals(nPrev)) t = false;
if (x.isUnit()) return false;
if (x.equals(nPrev)) continue next;
}
if (t) return false;
return false;
}
return true;
}
// Set "strict" to true to force GRH-supported lower bound of 2*log(N)^2
BigInteger.prototype.isPrime = function (strict) {
var isPrime = isBasicPrime(this);
if (isPrime !== undefined) return isPrime;
var n = this.abs();
var bits = n.bitLength();
if(bits <= 64)
return millerRabinTest(n, [2, 325, 9375, 28178, 450775, 9780504, 1795265022]);
var logN = Math.log(2) * bits;
var t = Math.ceil((strict === true) ? (2 * Math.pow(logN, 2)) : logN);
for (var a = [], i = 0; i < t; i++) {
a.push(bigInt(i + 2));
}
return millerRabinTest(n, a);
};
SmallInteger.prototype.isPrime = BigInteger.prototype.isPrime;
@@ -816,12 +831,10 @@ var bigInt = (function (undefined) {
if (isPrime !== undefined) return isPrime;
var n = this.abs();
var t = iterations === undefined ? 5 : iterations;
// use the Fermat primality test
for (var i = 0; i < t; i++) {
var a = bigInt.randBetween(2, n.minus(2));
if (!a.modPow(n.prev(), n).isUnit()) return false; // definitely composite
for (var a = [], i = 0; i < t; i++) {
a.push(bigInt.randBetween(2, n.minus(2)));
}
return true; // large chance of being prime
return millerRabinTest(n, a);
};
SmallInteger.prototype.isProbablePrime = BigInteger.prototype.isProbablePrime;
+1 -1
View File
File diff suppressed because one or more lines are too long
+5 -5
View File
@@ -219,15 +219,15 @@ Returns `true` if the number is prime, `false` otherwise.
Returns `true` if the number is very likely to be prime, `false` otherwise.
Argument is optional and determines the amount of iterations of the test (default: `5`). The more iterations, the lower chance of getting a false positive.
This uses the [Fermat primality test](https://en.wikipedia.org/wiki/Fermat_primality_test).
This uses the [Miller Rabin test](https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test).
- `bigInt(5).isProbablePrime()` => `true`
- `bigInt(49).isProbablePrime()` => `false`
- `bigInt(1729).isProbablePrime(50)` => `false`
- `bigInt(1729).isProbablePrime()` => `false`
Note that this function is not deterministic, since it relies on random sampling of factors, so the result for some numbers is not always the same. [Carmichael numbers](https://en.wikipedia.org/wiki/Carmichael_number) are particularly prone to give unreliable results.
For example, `bigInt(1729).isProbablePrime()` returns `false` about 76% of the time and `true` about 24% of the time. The correct result is `false`.
Note that this function is not deterministic, since it relies on random sampling of factors, so the result for some numbers is not always the same.
If the number is composite then the MillerRabin primality test declares the number probably prime with a probability at most `4` to the power `iterations`.
If the number is prime, this function always returns `true`.
#### `isUnit()`
+13 -11
View File
@@ -1,27 +1,29 @@
{
"_from": "big-integer@^1.6.7",
"_id": "big-integer@1.6.32",
"_from": "big-integer@1",
"_id": "big-integer@1.6.36",
"_inBundle": false,
"_integrity": "sha512-ljKJdR3wk9thHfLj4DtrNiOSTxvGFaMjWrG4pW75juXC4j7+XuKJVFdg4kgFMYp85PVkO05dFMj2dk2xVsH4xw==",
"_integrity": "sha512-t70bfa7HYEA1D9idDbmuv7YbsbVkQ+Hp+8KFSul4aE5e/i1bjCNIRYJZlA8Q8p0r9T8cF/RVvwUgRA//FydEyg==",
"_location": "/big-integer",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "big-integer@^1.6.7",
"raw": "big-integer@1",
"name": "big-integer",
"escapedName": "big-integer",
"rawSpec": "^1.6.7",
"rawSpec": "1",
"saveSpec": null,
"fetchSpec": "^1.6.7"
"fetchSpec": "1"
},
"_requiredBy": [
"#USER",
"/",
"/bplist-parser"
],
"_resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.32.tgz",
"_shasum": "5867458b25ecd5bcb36b627c30bb501a13c07e89",
"_spec": "big-integer@^1.6.7",
"_where": "/Users/brodybits/Documents/cordova/cordova-android/node_modules/bplist-parser",
"_resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.36.tgz",
"_shasum": "78631076265d4ae3555c04f85e7d9d2f3a071a36",
"_spec": "big-integer@1",
"_where": "/Users/brodybits/Documents/cordova/cordova-android",
"author": {
"name": "Peter Olson",
"email": "peter.e.c.olson+npm@gmail.com"
@@ -76,5 +78,5 @@
"test": "tsc && karma start my.conf.js && node spec/tsDefinitions.js"
},
"typings": "./BigInteger.d.ts",
"version": "1.6.32"
"version": "1.6.36"
}