big-integer
Advanced tools
Comparing version 1.3.20 to 1.4.0
@@ -15,5 +15,4 @@ "use strict"; | ||
function trim(value) { | ||
var i = value.length - 1; | ||
while (value[i] === 0 && i > 0) i--; | ||
return value.slice(0, i + 1); | ||
while (value[value.length - 1] === 0 && value.length > 1) value.pop(); | ||
return value; | ||
} | ||
@@ -36,10 +35,15 @@ | ||
} | ||
return new BigInteger(result, a.sign); | ||
return new BigInteger(trim(result), a.sign); | ||
} | ||
function fastSubtract(a, b) { | ||
var value = a.value; | ||
if (value.length === 1) { | ||
value = value[0]; | ||
if (a.sign) value = -value; | ||
return new BigInteger([Math.abs(value - b)], (value - b) < 0); | ||
} | ||
if (a.sign !== (b < 0)) return fastAdd(a, -b); | ||
var sign = false; | ||
if (a.sign) sign = true; | ||
var value = a.value; | ||
if (value.length === 1 && value[0] < b) return new BigInteger([b - value[0]], !sign); | ||
@@ -55,3 +59,3 @@ if (sign) b = -b; | ||
return new BigInteger(result, sign); | ||
return new BigInteger(trim(result), sign); | ||
} | ||
@@ -70,3 +74,3 @@ | ||
} | ||
return new BigInteger(result, sign ? !a.sign : a.sign); | ||
return new BigInteger(trim(result), sign ? !a.sign : a.sign); | ||
} | ||
@@ -93,3 +97,3 @@ | ||
function isSmall(n) { | ||
return ((typeof n === "number" || typeof n === "string") && +n <= base) || | ||
return ((typeof n === "number" || typeof n === "string") && +Math.abs(n) <= base) || | ||
(n instanceof BigInteger && n.value.length <= 1); | ||
@@ -122,5 +126,4 @@ } | ||
}; | ||
BigInteger.prototype.plus = function (n) { | ||
return this.add(n); | ||
}; | ||
BigInteger.prototype.plus = BigInteger.prototype.add; | ||
BigInteger.prototype.subtract = function (n) { | ||
@@ -144,5 +147,4 @@ if (isSmall(n)) return fastSubtract(this, +n); | ||
}; | ||
BigInteger.prototype.minus = function (n) { | ||
return this.subtract(n); | ||
}; | ||
BigInteger.prototype.minus = BigInteger.prototype.subtract; | ||
BigInteger.prototype.multiply = function (n) { | ||
@@ -190,5 +192,4 @@ if (isSmall(n)) return fastMultiply(this, +n); | ||
}; | ||
BigInteger.prototype.times = function (n) { | ||
return this.multiply(n); | ||
}; | ||
BigInteger.prototype.times = BigInteger.prototype.multiply; | ||
BigInteger.prototype.divmod = function (n) { | ||
@@ -220,11 +221,9 @@ if (isSmall(n)) return fastDivMod(this, +n); | ||
}; | ||
BigInteger.prototype.over = function (n) { | ||
return this.divide(n); | ||
}; | ||
BigInteger.prototype.over = BigInteger.prototype.divide; | ||
BigInteger.prototype.mod = function (n) { | ||
return this.divmod(n).remainder; | ||
}; | ||
BigInteger.prototype.remainder = function (n) { | ||
return this.mod(n); | ||
}; | ||
BigInteger.prototype.remainder = BigInteger.prototype.mod; | ||
BigInteger.prototype.pow = function (n) { | ||
@@ -307,5 +306,3 @@ n = parseInput(n); | ||
}; | ||
BigInteger.prototype.compareTo = function (n) { | ||
return this.compare(n); | ||
}; | ||
BigInteger.prototype.compareAbs = function (n) { | ||
@@ -333,2 +330,3 @@ return this.abs().compare(n.abs()); | ||
BigInteger.prototype.compareTo = BigInteger.prototype.compare; | ||
BigInteger.prototype.lt = BigInteger.prototype.lesser; | ||
@@ -352,5 +350,7 @@ BigInteger.prototype.leq = BigInteger.prototype.lesserOrEquals; | ||
BigInteger.prototype.isPositive = function () { | ||
if (this.value.length === 1 && this.value[0] === 0) return false; | ||
return this.sign === sign.positive; | ||
}; | ||
BigInteger.prototype.isNegative = function () { | ||
if (this.value.length === 1 && this.value[0] === 0) return false; | ||
return this.sign === sign.negative; | ||
@@ -367,3 +367,8 @@ }; | ||
}; | ||
BigInteger.prototype.isZero = function () { | ||
return this.value.length === 1 && this.value[0] === 0; | ||
}; | ||
BigInteger.prototype.isDivisibleBy = function (n) { | ||
n = parseInput(n); | ||
if (n.isZero()) return false; | ||
return this.mod(n).equals(ZERO); | ||
@@ -370,0 +375,0 @@ }; |
{ | ||
"name": "big-integer", | ||
"version": "1.3.20", | ||
"version": "1.4.0", | ||
"author": "Peter Olson <peter.e.c.olson+npm@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "An arbitrary length integer library for Javascript", |
@@ -18,3 +18,3 @@ BigInteger.js | ||
The unit tests are contained in the `BigInteger.test.js` file. You can [run them online from GitHub](http://peterolson.github.io/BigInteger.js/Test.htm). | ||
The unit tests are contained in the `BigInteger.test.js` file. You can [run them online from GitHub](http://peterolson.github.io/BigInteger.js/spec/SpecRunner.htm). | ||
@@ -174,3 +174,3 @@ `bigInt(number, [base])` | ||
Returns `true` if the number is negative, `false` otherwise. | ||
Returns `false` for `0` and `true` for `-0`. | ||
Returns `false` for `0` and `-0`. | ||
@@ -197,3 +197,3 @@ - `bigInt(-23).isNegative()` => `true` | ||
Return `true` if the number is positive, `false` otherwise. | ||
Returns `true` for `0` and `false` for `-0`. | ||
Returns `false` for `0` and `-0`. | ||
@@ -205,3 +205,3 @@ - `bigInt(54).isPositive()` => `true` | ||
--- | ||
Return `true` if the number is `1` or `-1`, `false` otherwise. | ||
Returns `true` if the number is `1` or `-1`, `false` otherwise. | ||
@@ -212,2 +212,10 @@ - `bigInt.one.isUnit()` => `true` | ||
`isZero()` | ||
--- | ||
Return `true` if the number is `0` or `-0`, `false` otherwise. | ||
- `bigInt.zero.isZero()` => `true` | ||
- `bigInt("-0").isZero()` => `true` | ||
- `bigInt(50).isZero()` => `false` | ||
`lcm(a,b)` | ||
@@ -214,0 +222,0 @@ --- |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
216276
15
4438
425
1
1