Socket
Socket
Sign inDemoInstall

big-integer

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

big-integer - npm Package Compare versions

Comparing version 1.3.14 to 1.3.15

8

BigInteger.js

@@ -1,2 +0,2 @@

"use strict";
"use strict";
var bigInt = (function () {

@@ -119,3 +119,3 @@ var base = 10000000, logBase = 7;

n = parseInput(n);
var sign = this.sign !== n.sign;
var quotientSign = this.sign !== n.sign;
if (this.equals(0)) return {

@@ -136,3 +136,3 @@ quotient: new BigInteger([0], sign.positive),

return {
quotient: new BigInteger(trim(result), sign),
quotient: new BigInteger(trim(result), quotientSign),
remainder: new BigInteger(trim(remainder), this.sign)

@@ -455,2 +455,2 @@ };

module.exports = bigInt;
}
}

@@ -1,1 +0,1 @@

"use strict";var bigInt=function(){function r(e,t){this.value=e,this.sign=t}function i(e){var t=[],n=0;for(var r=e.length-1;r>=0;r--){if(r>n&&e[r]===0)continue;n=r,t[r]=e[r]}return t}function s(e,t){return e=d(e).abs(),t=d(t).abs(),e.equals(t)?e:e.equals(c)?t:t.equals(c)?e:e.isEven()?t.isOdd()?s(e.divide(2),t):s(e.divide(2),t.divide(2)).multiply(2):t.isEven()?s(e,t.divide(2)):e.greater(t)?s(e.subtract(t).divide(2),t):s(t.subtract(e).divide(2),e)}function o(e,t){return e=d(e).abs(),t=d(t).abs(),e.multiply(t).divide(s(e,t))}function u(e,t){return e=d(e),t=d(t),e.greater(t)?e:t}function a(e,t){return e=d(e),t=d(t),e.lesser(t)?e:t}function f(t,n){t=d(t),n=d(n);var i=a(t,n),s=u(t,n),o=s.subtract(i),f=o.value.length-1,l=[],c=!0;for(var h=f;h>=0;h--){var p=c?o.value[h]:e,v=Math.floor(Math.random()*p);l.unshift(v),v<p&&(c=!1)}return i.add(new r(l,!1))}function d(i){if(i instanceof r)return i;if(Math.abs(+i)<e&&+i===(+i|0)){var s=+i;return new r([Math.abs(s)],s<0||1/s===-Infinity)}i+="";var o=n.positive,s=[];i[0]==="-"&&(o=n.negative,i=i.slice(1));var i=i.split(/e/i);if(i.length>2)throw new Error("Invalid integer: "+i.join("e"));if(i[1]){var u=i[1];u[0]==="+"&&(u=u.slice(1)),u=d(u);if(u.lesser(0))throw new Error("Cannot include negative exponent part for integers");while(u.notEquals(0))i[0]+="0",u=u.prev()}i=i[0],i==="-0"&&(i="0");var a=/^([0-9][0-9]*)$/.test(i);if(!a)throw new Error("Invalid integer: "+i);while(i.length){var f=i.length>t?i.length-t:0;s.push(+i.slice(f)),i=i.slice(0,f)}return new r(s,o)}var e=1e7,t=7,n={positive:!1,negative:!0};r.prototype.negate=function(){return new r(this.value,!this.sign)},r.prototype.abs=function(){return new r(this.value,n.positive)},r.prototype.add=function(t){t=d(t);if(this.sign!==t.sign)return this.sign===n.positive?this.abs().subtract(t.abs()):t.abs().subtract(this.abs());var s=this.value,o=t.value,u=[],a=0,f=Math.max(s.length,o.length);for(var l=0;l<f||a>0;l++){var c=(s[l]||0)+(o[l]||0)+a;a=c>=e?1:0,c-=a*e,u.push(c)}return new r(i(u),this.sign)},r.prototype.plus=function(e){return this.add(e)},r.prototype.subtract=function(t){t=d(t);if(this.sign!==t.sign)return this.add(t.negate());if(this.sign===n.negative)return t.negate().subtract(this.negate());if(this.compare(t)<0)return t.subtract(this).negate();var s=this.value,o=t.value,u=[],a=0,f=Math.max(s.length,o.length);for(var l=0;l<f;l++){var c=s[l]||0,h=o[l]||0,p=c-a;a=p<h?1:0;var v=a*e+p-h;u.push(v)}return new r(i(u),n.positive)},r.prototype.minus=function(e){return this.subtract(e)},r.prototype.multiply=function(t){t=d(t);var n=this.sign!==t.sign,s=this.value,o=t.value,u=Math.max(s.length,o.length),a=[];for(var f=0;f<u;f++){a[f]=[];var l=f;while(l--)a[f].push(0)}var c=0;for(var f=0;f<s.length;f++){var h=s[f];for(var l=0;l<o.length||c>0;l++){var p=o[l],v=p?h*p+c:c;c=v>e?Math.floor(v/e):0,v-=c*e,a[f].push(v)}}var m=-1;for(var f=0;f<a.length;f++){var g=a[f].length;g>m&&(m=g)}var y=[],c=0;for(var f=0;f<m||c>0;f++){var b=c;for(var l=0;l<a.length;l++)b+=a[l][f]||0;c=b>e?Math.floor(b/e):0,b-=c*e,y.push(b)}return new r(i(y),n)},r.prototype.times=function(e){return this.multiply(e)},r.prototype.divmod=function(e){e=d(e);var t=this.sign!==e.sign;if(this.equals(0))return{quotient:new r([0],t.positive),remainder:new r([0],t.positive)};if(e.equals(0))throw new Error("Cannot divide by zero");var n=this.value,s=e.value,o=[],u=[];for(var a=n.length-1;a>=0;a--){var f=[n[a]].concat(u),c=l(s,f);o.push(c.result),u=c.remainder}return o.reverse(),{quotient:new r(i(o),t),remainder:new r(i(u),this.sign)}},r.prototype.divide=function(e){return this.divmod(e).quotient},r.prototype.over=function(e){return this.divide(e)},r.prototype.mod=function(e){return this.divmod(e).remainder},r.prototype.remainder=function(e){return this.mod(e)},r.prototype.pow=function(e){e=d(e);var t=this,n=e,r=h;if(n.equals(c))return r;if(t.equals(c)||n.lesser(c))return c;for(;;){n.isOdd()&&(r=r.times(t)),n=n.divide(2);if(n.equals(c))break;t=t.times(t)}return r},r.prototype.modPow=function(e,t){e=d(e),t=d(t);if(t.equals(c))throw new Error("Cannot take modPow with modulus 0");var n=h,r=this.mod(t);if(r.equals(c))return c;while(e.greater(0))e.isOdd()&&(n=n.multiply(r).mod(t)),e=e.divide(2),r=r.square().mod(t);return n},r.prototype.square=function(){return this.multiply(this)},r.prototype.next=function(){return this.add(1)},r.prototype.prev=function(){return this.subtract(1)},r.prototype.compare=function(e){var t=this,r=d(e);if(t.value.length===1&&r.value.length===1&&t.value[0]===0&&r.value[0]===0)return 0;if(r.sign!==t.sign)return t.sign===n.positive?1:-1;var i=t.sign===n.positive?1:-1,s=t.value,o=r.value,u=Math.max(s.length,o.length)-1;for(var a=u;a>=0;a--){var f=s[a]||0,l=o[a]||0;if(f>l)return 1*i;if(l>f)return-1*i}return 0},r.prototype.compareTo=function(e){return this.compare(e)},r.prototype.compareAbs=function(e){return this.abs().compare(e.abs())},r.prototype.equals=function(e){return this.compare(e)===0},r.prototype.notEquals=function(e){return!this.equals(e)},r.prototype.lesser=function(e){return this.compare(e)<0},r.prototype.greater=function(e){return this.compare(e)>0},r.prototype.greaterOrEquals=function(e){return this.compare(e)>=0},r.prototype.lesserOrEquals=function(e){return this.compare(e)<=0},r.prototype.isPositive=function(){return this.sign===n.positive},r.prototype.isNegative=function(){return this.sign===n.negative},r.prototype.isEven=function(){return this.value[0]%2===0},r.prototype.isOdd=function(){return this.value[0]%2===1},r.prototype.isUnit=function(){return this.value.length===1&&this.value[0]===1},r.prototype.isDivisibleBy=function(e){return this.mod(e).equals(c)},r.prototype.isPrime=function(){var e=this.abs(),t=e.prev();if(e.isUnit())return!1;if(e.equals(2)||e.equals(3)||e.equals(5))return!0;if(e.isEven()||e.isDivisibleBy(3)||e.isDivisibleBy(5))return!1;if(e.lesser(25))return!0;var n=[2,3,5,7,11,13,17,19],r=t,i,s,o,u;while(r.isEven())r=r.divide(2);for(o=0;o<n.length;o++){u=bigInt(n[o]).modPow(r,e);if(u.equals(h)||u.equals(t))continue;for(s=!0,i=r;s&&i.lesser(t);i=i.multiply(2))u=u.square().mod(e),u.equals(t)&&(s=!1);if(s)return!1}return!0},r.prototype.toString=function(r){var i=this,s="",o=i.value.length;while(o--)i.value[o].toString().length===8?s+=i.value[o]:s+=(e.toString()+i.value[o]).slice(-t);while(s[0]==="0")s=s.slice(1);s.length||(s="0");if(s==="0")return s;var u=i.sign===n.positive?"":"-";return u+s},r.prototype.toJSNumber=function(){return+this.toString()},r.prototype.valueOf=function(){return this.toJSNumber()};var l=function(e,t){var e=new r(e,n.positive),t=new r(t,n.positive);if(e.equals(0))throw new Error("Cannot divide by 0");var i=0;do{var s=1,o=e,u=o.times(10);while(u.lesser(t))o=u,s*=10,u=u.times(10);while(o.lesserOrEquals(t))t=t.minus(o),i+=s}while(e.lesserOrEquals(t));return{remainder:t.value,result:i}},c=new r([0],n.positive),h=new r([1],n.positive),p=new r([1],n.negative),v=function(e,t){function o(e){var t=e[i].toLowerCase();if(i===0&&e[i]==="-"){s=!0;return}if(/[0-9]/.test(t))r.push(d(t));else if(/[a-z]/.test(t))r.push(d(t.charCodeAt(0)-87));else{if(t!=="<")throw new Error(t+" is not a valid character");var n=i;do i++;while(e[i]!==">");r.push(d(e.slice(n+1,i)))}}t=d(t);var n=c,r=[],i,s=!1;for(i=0;i<e.length;i++)o(e);r.reverse();for(i=0;i<r.length;i++)n=n.add(r[i].times(t.pow(i)));return s?n.negate():n},m=function(e,t){return typeof e=="undefined"?c:typeof t!="undefined"?v(e,t):d(e)};return m.zero=c,m.one=h,m.minusOne=p,m.randBetween=f,m.min=a,m.max=u,m.gcd=s,m.lcm=o,m}();typeof module!="undefined"&&(module.exports=bigInt);
"use strict";var bigInt=function(){function r(e,t){this.value=e,this.sign=t}function i(e){var t=[],n=0;for(var r=e.length-1;r>=0;r--){if(r>n&&e[r]===0)continue;n=r,t[r]=e[r]}return t}function s(e,t){return e=d(e).abs(),t=d(t).abs(),e.equals(t)?e:e.equals(c)?t:t.equals(c)?e:e.isEven()?t.isOdd()?s(e.divide(2),t):s(e.divide(2),t.divide(2)).multiply(2):t.isEven()?s(e,t.divide(2)):e.greater(t)?s(e.subtract(t).divide(2),t):s(t.subtract(e).divide(2),e)}function o(e,t){return e=d(e).abs(),t=d(t).abs(),e.multiply(t).divide(s(e,t))}function u(e,t){return e=d(e),t=d(t),e.greater(t)?e:t}function a(e,t){return e=d(e),t=d(t),e.lesser(t)?e:t}function f(t,n){t=d(t),n=d(n);var i=a(t,n),s=u(t,n),o=s.subtract(i),f=o.value.length-1,l=[],c=!0;for(var h=f;h>=0;h--){var p=c?o.value[h]:e,v=Math.floor(Math.random()*p);l.unshift(v),v<p&&(c=!1)}return i.add(new r(l,!1))}function d(i){if(i instanceof r)return i;if(Math.abs(+i)<e&&+i===(+i|0)){var s=+i;return new r([Math.abs(s)],s<0||1/s===-Infinity)}i+="";var o=n.positive,s=[];i[0]==="-"&&(o=n.negative,i=i.slice(1));var i=i.split(/e/i);if(i.length>2)throw new Error("Invalid integer: "+i.join("e"));if(i[1]){var u=i[1];u[0]==="+"&&(u=u.slice(1)),u=d(u);if(u.lesser(0))throw new Error("Cannot include negative exponent part for integers");while(u.notEquals(0))i[0]+="0",u=u.prev()}i=i[0],i==="-0"&&(i="0");var a=/^([0-9][0-9]*)$/.test(i);if(!a)throw new Error("Invalid integer: "+i);while(i.length){var f=i.length>t?i.length-t:0;s.push(+i.slice(f)),i=i.slice(0,f)}return new r(s,o)}var e=1e7,t=7,n={positive:!1,negative:!0};r.prototype.negate=function(){return new r(this.value,!this.sign)},r.prototype.abs=function(){return new r(this.value,n.positive)},r.prototype.add=function(t){t=d(t);if(this.sign!==t.sign)return this.sign===n.positive?this.abs().subtract(t.abs()):t.abs().subtract(this.abs());var s=this.value,o=t.value,u=[],a=0,f=Math.max(s.length,o.length);for(var l=0;l<f||a>0;l++){var c=(s[l]||0)+(o[l]||0)+a;a=c>=e?1:0,c-=a*e,u.push(c)}return new r(i(u),this.sign)},r.prototype.plus=function(e){return this.add(e)},r.prototype.subtract=function(t){t=d(t);if(this.sign!==t.sign)return this.add(t.negate());if(this.sign===n.negative)return t.negate().subtract(this.negate());if(this.compare(t)<0)return t.subtract(this).negate();var s=this.value,o=t.value,u=[],a=0,f=Math.max(s.length,o.length);for(var l=0;l<f;l++){var c=s[l]||0,h=o[l]||0,p=c-a;a=p<h?1:0;var v=a*e+p-h;u.push(v)}return new r(i(u),n.positive)},r.prototype.minus=function(e){return this.subtract(e)},r.prototype.multiply=function(t){t=d(t);var n=this.sign!==t.sign,s=this.value,o=t.value,u=Math.max(s.length,o.length),a=[];for(var f=0;f<u;f++){a[f]=[];var l=f;while(l--)a[f].push(0)}var c=0;for(var f=0;f<s.length;f++){var h=s[f];for(var l=0;l<o.length||c>0;l++){var p=o[l],v=p?h*p+c:c;c=v>e?Math.floor(v/e):0,v-=c*e,a[f].push(v)}}var m=-1;for(var f=0;f<a.length;f++){var g=a[f].length;g>m&&(m=g)}var y=[],c=0;for(var f=0;f<m||c>0;f++){var b=c;for(var l=0;l<a.length;l++)b+=a[l][f]||0;c=b>e?Math.floor(b/e):0,b-=c*e,y.push(b)}return new r(i(y),n)},r.prototype.times=function(e){return this.multiply(e)},r.prototype.divmod=function(e){e=d(e);var t=this.sign!==e.sign;if(this.equals(0))return{quotient:new r([0],n.positive),remainder:new r([0],n.positive)};if(e.equals(0))throw new Error("Cannot divide by zero");var s=this.value,o=e.value,u=[],a=[];for(var f=s.length-1;f>=0;f--){var c=[s[f]].concat(a),h=l(o,c);u.push(h.result),a=h.remainder}return u.reverse(),{quotient:new r(i(u),t),remainder:new r(i(a),this.sign)}},r.prototype.divide=function(e){return this.divmod(e).quotient},r.prototype.over=function(e){return this.divide(e)},r.prototype.mod=function(e){return this.divmod(e).remainder},r.prototype.remainder=function(e){return this.mod(e)},r.prototype.pow=function(e){e=d(e);var t=this,n=e,r=h;if(n.equals(c))return r;if(t.equals(c)||n.lesser(c))return c;for(;;){n.isOdd()&&(r=r.times(t)),n=n.divide(2);if(n.equals(c))break;t=t.times(t)}return r},r.prototype.modPow=function(e,t){e=d(e),t=d(t);if(t.equals(c))throw new Error("Cannot take modPow with modulus 0");var n=h,r=this.mod(t);if(r.equals(c))return c;while(e.greater(0))e.isOdd()&&(n=n.multiply(r).mod(t)),e=e.divide(2),r=r.square().mod(t);return n},r.prototype.square=function(){return this.multiply(this)},r.prototype.next=function(){return this.add(1)},r.prototype.prev=function(){return this.subtract(1)},r.prototype.compare=function(e){var t=this,r=d(e);if(t.value.length===1&&r.value.length===1&&t.value[0]===0&&r.value[0]===0)return 0;if(r.sign!==t.sign)return t.sign===n.positive?1:-1;var i=t.sign===n.positive?1:-1,s=t.value,o=r.value,u=Math.max(s.length,o.length)-1;for(var a=u;a>=0;a--){var f=s[a]||0,l=o[a]||0;if(f>l)return 1*i;if(l>f)return-1*i}return 0},r.prototype.compareTo=function(e){return this.compare(e)},r.prototype.compareAbs=function(e){return this.abs().compare(e.abs())},r.prototype.equals=function(e){return this.compare(e)===0},r.prototype.notEquals=function(e){return!this.equals(e)},r.prototype.lesser=function(e){return this.compare(e)<0},r.prototype.greater=function(e){return this.compare(e)>0},r.prototype.greaterOrEquals=function(e){return this.compare(e)>=0},r.prototype.lesserOrEquals=function(e){return this.compare(e)<=0},r.prototype.isPositive=function(){return this.sign===n.positive},r.prototype.isNegative=function(){return this.sign===n.negative},r.prototype.isEven=function(){return this.value[0]%2===0},r.prototype.isOdd=function(){return this.value[0]%2===1},r.prototype.isUnit=function(){return this.value.length===1&&this.value[0]===1},r.prototype.isDivisibleBy=function(e){return this.mod(e).equals(c)},r.prototype.isPrime=function(){var e=this.abs(),t=e.prev();if(e.isUnit())return!1;if(e.equals(2)||e.equals(3)||e.equals(5))return!0;if(e.isEven()||e.isDivisibleBy(3)||e.isDivisibleBy(5))return!1;if(e.lesser(25))return!0;var n=[2,3,5,7,11,13,17,19],r=t,i,s,o,u;while(r.isEven())r=r.divide(2);for(o=0;o<n.length;o++){u=bigInt(n[o]).modPow(r,e);if(u.equals(h)||u.equals(t))continue;for(s=!0,i=r;s&&i.lesser(t);i=i.multiply(2))u=u.square().mod(e),u.equals(t)&&(s=!1);if(s)return!1}return!0},r.prototype.toString=function(r){var i=this,s="",o=i.value.length;while(o--)i.value[o].toString().length===8?s+=i.value[o]:s+=(e.toString()+i.value[o]).slice(-t);while(s[0]==="0")s=s.slice(1);s.length||(s="0");if(s==="0")return s;var u=i.sign===n.positive?"":"-";return u+s},r.prototype.toJSNumber=function(){return+this.toString()},r.prototype.valueOf=function(){return this.toJSNumber()};var l=function(e,t){var e=new r(e,n.positive),t=new r(t,n.positive);if(e.equals(0))throw new Error("Cannot divide by 0");var i=0;do{var s=1,o=e,u=o.times(10);while(u.lesser(t))o=u,s*=10,u=u.times(10);while(o.lesserOrEquals(t))t=t.minus(o),i+=s}while(e.lesserOrEquals(t));return{remainder:t.value,result:i}},c=new r([0],n.positive),h=new r([1],n.positive),p=new r([1],n.negative),v=function(e,t){function o(e){var t=e[i].toLowerCase();if(i===0&&e[i]==="-"){s=!0;return}if(/[0-9]/.test(t))r.push(d(t));else if(/[a-z]/.test(t))r.push(d(t.charCodeAt(0)-87));else{if(t!=="<")throw new Error(t+" is not a valid character");var n=i;do i++;while(e[i]!==">");r.push(d(e.slice(n+1,i)))}}t=d(t);var n=c,r=[],i,s=!1;for(i=0;i<e.length;i++)o(e);r.reverse();for(i=0;i<r.length;i++)n=n.add(r[i].times(t.pow(i)));return s?n.negate():n},m=function(e,t){return typeof e=="undefined"?c:typeof t!="undefined"?v(e,t):d(e)};return m.zero=c,m.one=h,m.minusOne=p,m.randBetween=f,m.min=a,m.max=u,m.gcd=s,m.lcm=o,m}();typeof module!="undefined"&&(module.exports=bigInt);

@@ -145,5 +145,6 @@ /// <reference path="BigInteger.js" />

"7919 is prime": bigInt(7919).isPrime(),
"7917 is not prime": !bigInt(7917).isPrime()
"7917 is not prime": !bigInt(7917).isPrime(),
"(0/1) + -100 = -100": (bigInt("0")).divide(bigInt("1")).add(bigInt("-100")).toString() === "-100" // see pull request 16
});
return assertions.join("<br>");
})(bigInt);
{
"name": "big-integer",
"version": "1.3.14",
"version": "1.3.15",
"author": "Peter Olson <peter.e.c.olson+npm@gmail.com>",

@@ -5,0 +5,0 @@ "description": "An arbitrary length integer library for Javascript",

@@ -287,2 +287,12 @@ BigInteger.js

`randBetween(min, max)`
---
Returns a random number between `min` and `max`.
- `bigInt.randBetween("-1e100", "1e100")` => (for example) `8494907165436643479673097939554427056789510374838494147955756275846226209006506706784609314471378745`
`remainder(number)`
---
Alias for the `mod` method.
`square()`

@@ -300,12 +310,2 @@ ---

`randBetween(min, max)`
---
Returns a random number between `min` and `max`.
- `bigInt.randBetween("-1e100", "1e100")` => (for example) `8494907165436643479673097939554427056789510374838494147955756275846226209006506706784609314471378745`
`remainder(number)`
---
Alias for the `mod` method.
`times(number)`

@@ -312,0 +312,0 @@ ---

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc