You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
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

Comparing version 1.0.3 to 1.0.4

11

BigInteger.js

@@ -21,2 +21,3 @@ var bigInt = (function () {

}
if (!a.length) a = [0], b = [0];
first.value = a;

@@ -62,2 +63,3 @@ second.value = b;

var a = bigInt(a, sign.positive), b = bigInt(b, sign.positive);
if (a.equals(0)) throw new Error("Cannot divide by 0");
var n = 0;

@@ -128,3 +130,3 @@ do {

subtract: function (n, m) {
var s, first = self, second;
var first = self, second;
if (m) (first = parse(n)) && (second = parse(m));

@@ -199,2 +201,6 @@ else second = parse(n, first);

s = first.sign !== second.sign;
if (bigInt(first.value, first.sign).equals(0)) return {
quotient: 0,
remainder: 0
};
if (second.equals(0)) throw new Error("Cannot divide by zero");

@@ -252,5 +258,6 @@ var a = first.value, b = second.value;

else second = parse(n, first);
normalize(first, second);
if (first.value.length === 1 && second.value.length === 1 && first.value[0] === 0 && second.value[0] === 0) return 0;
if (second.sign !== first.sign) return first.sign === sign.positive ? 1 : -1;
var multiplier = first.sign === sign.positive ? 1 : -1;
normalize(first, second);
var a = first.value, b = second.value;

@@ -257,0 +264,0 @@ for (var i = a.length - 1; i >= 0; i--) {

2

BigInteger.min.js

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

var bigInt=function(){var e=1e7,t=7,n={positive:!1,negative:!0},r=function(e,t){var n=e.value,r=t.value,i=n.length>r.length?n.length:r.length;for(var s=0;s<i;s++)n[s]=n[s]||0,r[s]=r[s]||0;for(var s=i-1;s>=0;s--)n[s]===0&&r[s]===0&&(n.pop(),r.pop());e.value=n,t.value=r},i=function(e,s){if(typeof e=="object")return e;e+="";var u=n.positive,a=[];e[0]==="-"&&(u=n.negative,e=e.slice(1));var e=e.split("e");if(e.length>2)throw new Error("Invalid integer");if(e[1]){var f=e[1];f[0]==="+"&&(f=f.slice(1)),f=i(f);if(f.lesser(0))throw new Error("Cannot include negative exponent part for integers");while(f.notEquals(0))e[0]+="0",f=f.prev()}e=e[0],e==="-0"&&(e="0");var l=/^([1-9][0-9]*)$|^0$/.test(e);if(!l)throw new Error("Invalid integer");while(e.length){var c=e.length>t?e.length-t:0;a.push(+e.slice(c)),e=e.slice(0,c)}var h=o(a,u);return s&&r(s,h),h},s=function(e,t){var e=o(e,n.positive),t=o(t,n.positive),r=0;do{var i=1,s=o(e.value,n.positive),u=s.times(10);while(u.lesser(t))s=u,i*=10,u=u.times(10);while(s.lesserOrEquals(t))t=t.minus(s),r+=i}while(e.lesserOrEquals(t));return{remainder:t.value,result:r}},o=function(f,l){var c={value:f,sign:l},h={value:f,sign:l,negate:function(e){var t=e||c;return o(t.value,!t.sign)},abs:function(e){var t=e||c;return o(t.value,n.positive)},add:function(t,s){var u,a=c,f;s?(a=i(t))&&(f=i(s)):f=i(t,a),u=a.sign;if(a.sign!==f.sign)return a=o(a.value,n.positive),f=o(f.value,n.positive),u===n.positive?h.subtract(a,f):h.subtract(f,a);r(a,f);var l=a.value,p=f.value,d=[],v=0;for(var m=0;m<l.length||v>0;m++){var g=l[m]+p[m]+v;v=g>e?1:0,g-=v*e,d.push(g)}return o(d,u)},plus:function(e,t){return h.add(e,t)},subtract:function(t,r){var s,u=c,a;r?(u=i(t))&&(a=i(r)):a=i(t,u);if(u.sign!==a.sign)return h.add(u,h.negate(a));if(u.sign===n.negative)return h.subtract(h.negate(a),h.negate(u));if(h.compare(u,a)===-1)return h.negate(h.subtract(a,u));var f=u.value,l=a.value,p=[],d=0;for(var v=0;v<f.length;v++){f[v]-=d,d=f[v]<l[v]?1:0;var m=d*e+f[v]-l[v];p.push(m)}return o(p,n.positive)},minus:function(e,t){return h.subtract(e,t)},multiply:function(t,n){var r,s=c,u;n?(s=i(t))&&(u=i(n)):u=i(t,s),r=s.sign!==u.sign;var a=s.value,f=u.value,l=[];for(var h=0;h<a.length;h++){l[h]=[];var p=h;while(p--)l[h].push(0)}var d=0;for(var h=0;h<a.length;h++){var v=a[h];for(var p=0;p<f.length||d>0;p++){var m=f[p],g=m?v*m+d:d;d=g>e?Math.floor(g/e):0,g-=d*e,l[h].push(g)}}var y=-1;for(var h=0;h<l.length;h++){var b=l[h].length;b>y&&(y=b)}var w=[],d=0;for(var h=0;h<y||d>0;h++){var E=d;for(var p=0;p<l.length;p++)E+=l[p][h]||0;d=E>e?Math.floor(E/e):0,E-=d*e,w.push(E)}return o(w,r)},times:function(e,t){return h.multiply(e,t)},divmod:function(e,t){var n,r=c,u;t?(r=i(e))&&(u=i(t)):u=i(e,r),n=r.sign!==u.sign;if(u.equals(0))throw new Error("Cannot divide by zero");var a=r.value,f=u.value,l=[],h=[];for(var p=a.length-1;p>=0;p--){var e=[a[p]].concat(h),d=s(f,e);l.push(d.result),h=d.remainder}return l.reverse(),{quotient:o(l,n),remainder:o(h,r.sign)}},divide:function(e,t){return h.divmod(e,t).quotient},over:function(e,t){return h.divide(e,t)},mod:function(e,t){return h.divmod(e,t).remainder},pow:function(e,t){var n=c,r;t?(n=i(e))&&(r=i(t)):r=i(e,n);var s=n,f=r;if(f.lesser(0))return u;if(f.equals(0))return a;var l=o(s.value,s.sign);if(f.mod(2).equals(0)){var h=l.pow(f.over(2));return h.times(h)}return l.times(l.pow(f.minus(1)))},next:function(e){var t=e||c;return h.add(t,1)},prev:function(e){var t=e||c;return h.subtract(t,1)},compare:function(e,t){var s=c,o;t?(s=i(e))&&(o=i(t,s)):o=i(e,s);if(o.sign!==s.sign)return s.sign===n.positive?1:-1;var u=s.sign===n.positive?1:-1;r(s,o);var a=s.value,f=o.value;for(var l=a.length-1;l>=0;l--){if(a[l]>f[l])return 1*u;if(f[l]>a[l])return-1*u}return 0},compareAbs:function(e,t){var r=c,s;return t?(r=i(e))&&(s=i(t,r)):s=i(e,r),r.sign=s.sign=n.positive,h.compare(r,s)},equals:function(e,t){return h.compare(e,t)===0},notEquals:function(e,t){return!h.equals(e,t)},lesser:function(e,t){return h.compare(e,t)<0},greater:function(e,t){return h.compare(e,t)>0},greaterOrEquals:function(e,t){return h.compare(e,t)>=0},lesserOrEquals:function(e,t){return h.compare(e,t)<=0},toString:function(r){var i=r||c,s="",o=i.value.length;while(o--)s+=(e.toString()+i.value[o]).slice(-t);while(s[0]==="0")s=s.slice(1);s.length||(s="0");var u=i.sign===n.positive?"":"-";return u+s},toJSNumber:function(e){return+h.toString(e)},valueOf:function(e){return h.toJSNumber(e)}};return h},u=o([0],n.positive),a=o([1],n.positive),f=o([-1],n.positive),l=function(e){return typeof e=="undefined"?u:i(e)};return l.zero=u,l.one=a,l.minusOne=f,l}();typeof module!="undefined"&&(module.exports=bigInt);
var bigInt=function(){var e=1e7,t=7,n={positive:!1,negative:!0},r=function(e,t){var n=e.value,r=t.value,i=n.length>r.length?n.length:r.length;for(var s=0;s<i;s++)n[s]=n[s]||0,r[s]=r[s]||0;for(var s=i-1;s>=0;s--)n[s]===0&&r[s]===0&&(n.pop(),r.pop());n.length||(n=[0],r=[0]),e.value=n,t.value=r},i=function(e,s){if(typeof e=="object")return e;e+="";var u=n.positive,a=[];e[0]==="-"&&(u=n.negative,e=e.slice(1));var e=e.split("e");if(e.length>2)throw new Error("Invalid integer");if(e[1]){var f=e[1];f[0]==="+"&&(f=f.slice(1)),f=i(f);if(f.lesser(0))throw new Error("Cannot include negative exponent part for integers");while(f.notEquals(0))e[0]+="0",f=f.prev()}e=e[0],e==="-0"&&(e="0");var l=/^([1-9][0-9]*)$|^0$/.test(e);if(!l)throw new Error("Invalid integer");while(e.length){var c=e.length>t?e.length-t:0;a.push(+e.slice(c)),e=e.slice(0,c)}var h=o(a,u);return s&&r(s,h),h},s=function(e,t){var e=o(e,n.positive),t=o(t,n.positive);if(e.equals(0))throw new Error("Cannot divide by 0");var r=0;do{var i=1,s=o(e.value,n.positive),u=s.times(10);while(u.lesser(t))s=u,i*=10,u=u.times(10);while(s.lesserOrEquals(t))t=t.minus(s),r+=i}while(e.lesserOrEquals(t));return{remainder:t.value,result:r}},o=function(f,l){var c={value:f,sign:l},h={value:f,sign:l,negate:function(e){var t=e||c;return o(t.value,!t.sign)},abs:function(e){var t=e||c;return o(t.value,n.positive)},add:function(t,s){var u,a=c,f;s?(a=i(t))&&(f=i(s)):f=i(t,a),u=a.sign;if(a.sign!==f.sign)return a=o(a.value,n.positive),f=o(f.value,n.positive),u===n.positive?h.subtract(a,f):h.subtract(f,a);r(a,f);var l=a.value,p=f.value,d=[],v=0;for(var m=0;m<l.length||v>0;m++){var g=l[m]+p[m]+v;v=g>e?1:0,g-=v*e,d.push(g)}return o(d,u)},plus:function(e,t){return h.add(e,t)},subtract:function(t,r){var s=c,u;r?(s=i(t))&&(u=i(r)):u=i(t,s);if(s.sign!==u.sign)return h.add(s,h.negate(u));if(s.sign===n.negative)return h.subtract(h.negate(u),h.negate(s));if(h.compare(s,u)===-1)return h.negate(h.subtract(u,s));var a=s.value,f=u.value,l=[],p=0;for(var d=0;d<a.length;d++){a[d]-=p,p=a[d]<f[d]?1:0;var v=p*e+a[d]-f[d];l.push(v)}return o(l,n.positive)},minus:function(e,t){return h.subtract(e,t)},multiply:function(t,n){var r,s=c,u;n?(s=i(t))&&(u=i(n)):u=i(t,s),r=s.sign!==u.sign;var a=s.value,f=u.value,l=[];for(var h=0;h<a.length;h++){l[h]=[];var p=h;while(p--)l[h].push(0)}var d=0;for(var h=0;h<a.length;h++){var v=a[h];for(var p=0;p<f.length||d>0;p++){var m=f[p],g=m?v*m+d:d;d=g>e?Math.floor(g/e):0,g-=d*e,l[h].push(g)}}var y=-1;for(var h=0;h<l.length;h++){var b=l[h].length;b>y&&(y=b)}var w=[],d=0;for(var h=0;h<y||d>0;h++){var E=d;for(var p=0;p<l.length;p++)E+=l[p][h]||0;d=E>e?Math.floor(E/e):0,E-=d*e,w.push(E)}return o(w,r)},times:function(e,t){return h.multiply(e,t)},divmod:function(e,t){var n,r=c,u;t?(r=i(e))&&(u=i(t)):u=i(e,r),n=r.sign!==u.sign;if(o(r.value,r.sign).equals(0))return{quotient:0,remainder:0};if(u.equals(0))throw new Error("Cannot divide by zero");var a=r.value,f=u.value,l=[],h=[];for(var p=a.length-1;p>=0;p--){var e=[a[p]].concat(h),d=s(f,e);l.push(d.result),h=d.remainder}return l.reverse(),{quotient:o(l,n),remainder:o(h,r.sign)}},divide:function(e,t){return h.divmod(e,t).quotient},over:function(e,t){return h.divide(e,t)},mod:function(e,t){return h.divmod(e,t).remainder},pow:function(e,t){var n=c,r;t?(n=i(e))&&(r=i(t)):r=i(e,n);var s=n,f=r;if(f.lesser(0))return u;if(f.equals(0))return a;var l=o(s.value,s.sign);if(f.mod(2).equals(0)){var h=l.pow(f.over(2));return h.times(h)}return l.times(l.pow(f.minus(1)))},next:function(e){var t=e||c;return h.add(t,1)},prev:function(e){var t=e||c;return h.subtract(t,1)},compare:function(e,t){var s=c,o;t?(s=i(e))&&(o=i(t,s)):o=i(e,s),r(s,o);if(s.value.length===1&&o.value.length===1&&s.value[0]===0&&o.value[0]===0)return 0;if(o.sign!==s.sign)return s.sign===n.positive?1:-1;var u=s.sign===n.positive?1:-1,a=s.value,f=o.value;for(var l=a.length-1;l>=0;l--){if(a[l]>f[l])return 1*u;if(f[l]>a[l])return-1*u}return 0},compareAbs:function(e,t){var r=c,s;return t?(r=i(e))&&(s=i(t,r)):s=i(e,r),r.sign=s.sign=n.positive,h.compare(r,s)},equals:function(e,t){return h.compare(e,t)===0},notEquals:function(e,t){return!h.equals(e,t)},lesser:function(e,t){return h.compare(e,t)<0},greater:function(e,t){return h.compare(e,t)>0},greaterOrEquals:function(e,t){return h.compare(e,t)>=0},lesserOrEquals:function(e,t){return h.compare(e,t)<=0},toString:function(r){var i=r||c,s="",o=i.value.length;while(o--)s+=(e.toString()+i.value[o]).slice(-t);while(s[0]==="0")s=s.slice(1);s.length||(s="0");var u=i.sign===n.positive?"":"-";return u+s},toJSNumber:function(e){return+h.toString(e)},valueOf:function(e){return h.toJSNumber(e)}};return h},u=o([0],n.positive),a=o([1],n.positive),f=o([-1],n.positive),l=function(e){return typeof e=="undefined"?u:i(e)};return l.zero=u,l.one=a,l.minusOne=f,l}();typeof module!="undefined"&&(module.exports=bigInt);
/// <reference path="BigInteger.js" />
var testResults = (function (bigInt) {
var assertions = [];
var assert = function (obj) {
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
var test = obj[i], title = i;
var result = test ? "<b>Passed</b>" : "<u>Failed</u>";
assertions.push(title + ": " + result);
}
};
var assertions = [];
var assert = function (obj) {
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
var test = obj[i], title = i;
var result = test ? "<b>Passed</b>" : "<u>Failed</u>";
assertions.push(title + ": " + result);
}
};
function factorial(n) {
if (n.equals(bigInt.zero) || n.equals(bigInt.one)) {
return bigInt.one;
}
return factorial(n.prev()).times(n);
}
function factorial(n) {
if (n.equals(bigInt.zero) || n.equals(bigInt.one)) {
return bigInt.one;
}
return factorial(n.prev()).times(n);
}
assert({
"1 = 1": bigInt("1").equals("1"),
"987 = 987": bigInt("987").equals("987"),
"-123456789 = -123456789": bigInt("-123456789").equals("-123456789"),
"12e5 = 1200000": bigInt("12e5").equals(1200000),
"str.equals(num)": bigInt("1").equals(1),
"bInt.equals(bInt)": bigInt(123).equals(bigInt(123)),
"0 = -0": bigInt("0").greater("-0"),
"54 != -54": bigInt(54).notEquals(-54),
"4 > 2": bigInt(4).greater(2),
"4 >= 2": bigInt(4).greaterOrEquals(2),
"2 >= 2": bigInt(2).greaterOrEquals(2),
"2 > -2": bigInt(2).greater(-2),
"2 < 4": bigInt(2).lesser(4),
"2 <= 4": bigInt(2).lesserOrEquals(4),
"2 <= 2": bigInt(2).lesserOrEquals(2),
"-2 < 2": bigInt(-2).lesser(2),
"0 != 1": bigInt(0).notEquals(1),
"1 + 1 = 2": bigInt(1).plus(1).equals(2),
"1 + -5 = -4": bigInt(1).plus(-5).equals(-4),
"-1 + 5 = 4": bigInt(-1).plus(5).equals(4),
"-1 + -5 = -6": bigInt(-1).plus(-5).equals(-6),
"1234567890987654321 + 9876543210123456789": bigInt("1234567890987654321").plus("9876543210123456789").equals("11111111101111111110"),
"7 - 3 = 4": bigInt(7).minus(3).equals(4),
"7 - -3 = 10": bigInt(7).minus(-3).equals(10),
"-7 - 3 = -10": bigInt(-7).minus(3).equals(-10),
"0 - 5 = -5": bigInt(0).minus(5).equals(-5),
"|-2| = 2": bigInt(-2).abs().equals(2),
"100 * 100 = 10000": bigInt(100).times(100).equals(10000),
"-100 * 100 = -10000": bigInt(-100).times(100).equals(-10000),
"100 * -100 = -10000": bigInt(100).times(-100).equals(-10000),
"-100 * -100 = 10000": bigInt(-100).times(-100).equals(10000),
"1234567890987654321 * 132435465768798 = 163500573666152634716420931676158": bigInt("1234567890987654321").times("132435465768798").equals("163500573666152634716420931676158"),
"15 / 5 = 3": bigInt(15).over(5).equals(3),
"15 / -5 = -3": bigInt(15).over(-5).equals(-3),
"-15 / 5 = -3": bigInt(-15).over(5).equals(-3),
"-15 / -5 = 3": bigInt(-15).over(-5).equals(3),
"786456456335437356436 / 5423424653 = 145011041298": bigInt("786456456335437356436").over("5423424653").equals(145011041298),
"93453764643534523 / 2342 = 39903400787162": bigInt("93453764643534523").over(2342).equals("39903400787162"),
"124234233 % 2 = 1": bigInt(124234233).mod(2).equals(1),
"124234233 % -2 = 1": bigInt(124234233).mod(-2).equals(1),
"-124234233 % 2 = -1": bigInt(-124234233).mod(2).equals(-1),
"-124234233 % -2 = -1": bigInt(-124234233).mod(-2).equals(-1),
"93453764643534523 % 2342 = 1119": bigInt("93453764643534523").mod(2342).equals(1119),
"2 ^ 3 = 8": bigInt(2).pow(3).equals(8),
"-2 ^ 3 = -8": bigInt(-2).pow(3).equals(-8),
"2 ^ -3 = 0": bigInt(2).pow(-3).equals(0),
"0-- = -1": bigInt.zero.prev().equals(-1),
"9007199254740992++ = 9007199254740993": bigInt(9007199254740992).next().equals("9007199254740993"),
"Leading zeroes":bigInt("10000000").toString()=="10000000",
"Leading zeroes 2":bigInt("100001010000000").toString()=="100001010000000",
"10 Factorial" : (function () {
var res = "3628800"; //http://www.wolframalpha.com/input/?i=10%21
return factorial(bigInt(10)).equals(res);
})(),
"100 Factorial" : (function () {
var res = "93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000"; //http://puzzles.nigelcoldwell.co.uk/nineteen.htm
return factorial(bigInt(100)).equals(res);
})(),
"3 ^ 10000": bigInt(3).pow(10000).toString() === "16313501853426258743032567291811547168121324535825379939348203261918257308143190787480155630847848309673252045223235795433405582999177203852381479145368112501453192355166224391025423628843556686559659645012014177448275529990373274425446425751235537341867387607813619937225616872862016504805593174059909520461668500663118926911571773452255850626968526251879139867085080472539640933730243410152186914328917354576854457274195562218013337745628502470673059426999114202540773175988199842487276183685299388927825296786440252999444785694183675323521704432195785806270123388382931770198990841300861506996108944782065015163410344894945809337689156807686673462563038164792190665340124344133980763205594364754963451564072340502606377790585114123814919001637177034457385019939060232925194471114235892978565322415628344142184842892083466227875760501276009801530703037525839157893875741192497705300469691062454369926795975456340236777734354667139072601574969834312769653557184396147587071260443947944862235744459711204473062937764153770030210332183635531818173456618022745975055313212598514429587545547296534609597194836036546870491771927625214352957503454948403635822345728774885175809500158451837389413798095329711993092101417428406774326126450005467888736546254948658602484494535938888656542746977424368385335496083164921318601934977025095780370104307980276356857350349205866078371806065542393536101673402017980951598946980664330391505845803674248348878071010412918667335823849899623486215050304052577789848512410263834811719236949311423411823585316405085306164936671137456985394285677324771775046050970865520893596151687017153855755197348199659070192954771308347627111052471134476325986362838585959552209645382089055182871854866744633737533217524880118401787595094060855717010144087136495532418544241489437080074716158404895914136451802032446707961058757633345691696743293869623745410870051851590672859347061212573446572045088465460616826082579731686004585218284333452396157730036306379421822435818001505905203918209206969662326706952623512427380240468784114535101496733983401240219840048956733689309620321613793757156727562461651933397540266795963865921590913322060572673349849253303397874242381960775337182730037783698708748781738419747698880321601186310506332869704931303076839444790968339306301273371014087248060946851793697973114432706759288546077622831002526800554849696867710280945946603669593797354642136622231192695027321229511912952940320879763123151760555959496961163141455688278842949587288399100273691880018774147568892650186152065335219113072582417699616901995530249937735219099786758954892534365835235843156112799728164123461219817343904782402517111603206575330527850752564642995318064985900815557979945885931124351303252811255254295797082281946658798705979077492469849644183166585950844953164726896146168297808178398470451561320526180542310840744843107469368959707726836608471817060598771730170755446473440774031371227437651048421606224757527085958515947273151027400662948161111284777828103531499488913672800783167888051177155427285103861736658069404797695900758820465238673970882660162285107599221418743657006872537842677883708807515850397691812433880561772652364847297019508025848964833883225165668986935081274596293983121864046277268590401580209059988500511262470167150495261908136688693861324081559046336288963037090312033522400722360882494928182809075406914319957044927504420797278117837677431446979085756432990753582588102440240611039084516401089948868433353748444104639734074519165067632941419347985624435567342072815910754484123812917487312938280670403228188813003978384081332242484646571417574404852962675165616101527367425654869508712001788393846171780457455963045764943565964887518396481296159902471996735508854292964536796779404377230965723361625182030798297734785854606060323419091646711138678490928840107449923456834763763114226000770316931243666699425694828181155048843161380832067845480569758457751090640996007242018255400627276908188082601795520167054701327802366989747082835481105543878446889896230696091881643547476154998574015907396059478684978574180486798918438643164618541351689258379042326487669479733384712996754251703808037828636599654447727795924596382283226723503386540591321268603222892807562509801015765174359627788357881606366119032951829868274617539946921221330284257027058653162292482686679275266764009881985590648534544939224296689791195355783205968492422636277656735338488299104238060289209390654467316291591219712866052661347026855261289381236881063068219249064767086495184176816629077103667131505064964190910450196502178972477361881300608688593782509793781457170396897496908861893034634895715117114601514654381347139092345833472226493656930996045016355808162984965203661519182202145414866559662218796964329217241498105206552200001",
"Fail on negative exponent": (function () {
try {
bigInt("12e-5");
return false;
} catch (e) {
return true;
}
})(),
"Fail on divide by zero": (function () {
try {
bigInt("135346").divide("0");
return false;
} catch (e) {
return true;
}
})(),
"Fail on invalid character in number": (function () {
try {
bigInt("43a34");
return false;
} catch (e) {
return true;
}
})()
});
return assertions.join("<br>");
assert({
"1 = 1": bigInt("1").equals("1"),
"987 = 987": bigInt("987").equals("987"),
"-123456789 = -123456789": bigInt("-123456789").equals("-123456789"),
"12e5 = 1200000": bigInt("12e5").equals(1200000),
"str.equals(num)": bigInt("1").equals(1),
"bInt.equals(bInt)": bigInt(123).equals(bigInt(123)),
"0 = -0": bigInt("0").greater("-0"),
"54 != -54": bigInt(54).notEquals(-54),
"4 > 2": bigInt(4).greater(2),
"4 >= 2": bigInt(4).greaterOrEquals(2),
"2 >= 2": bigInt(2).greaterOrEquals(2),
"2 > -2": bigInt(2).greater(-2),
"2 < 4": bigInt(2).lesser(4),
"2 <= 4": bigInt(2).lesserOrEquals(4),
"2 <= 2": bigInt(2).lesserOrEquals(2),
"-2 < 2": bigInt(-2).lesser(2),
"0 != 1": bigInt(0).notEquals(1),
"1 + 1 = 2": bigInt(1).plus(1).equals(2),
"1 + -5 = -4": bigInt(1).plus(-5).equals(-4),
"-1 + 5 = 4": bigInt(-1).plus(5).equals(4),
"-1 + -5 = -6": bigInt(-1).plus(-5).equals(-6),
"1234567890987654321 + 9876543210123456789": bigInt("1234567890987654321").plus("9876543210123456789").equals("11111111101111111110"),
"7 - 3 = 4": bigInt(7).minus(3).equals(4),
"7 - -3 = 10": bigInt(7).minus(-3).equals(10),
"-7 - 3 = -10": bigInt(-7).minus(3).equals(-10),
"0 - 5 = -5": bigInt(0).minus(5).equals(-5),
"|-2| = 2": bigInt(-2).abs().equals(2),
"100 * 100 = 10000": bigInt(100).times(100).equals(10000),
"-100 * 100 = -10000": bigInt(-100).times(100).equals(-10000),
"100 * -100 = -10000": bigInt(100).times(-100).equals(-10000),
"-100 * -100 = 10000": bigInt(-100).times(-100).equals(10000),
"1234567890987654321 * 132435465768798 = 163500573666152634716420931676158": bigInt("1234567890987654321").times("132435465768798").equals("163500573666152634716420931676158"),
"15 / 5 = 3": bigInt(15).over(5).equals(3),
"15 / -5 = -3": bigInt(15).over(-5).equals(-3),
"-15 / 5 = -3": bigInt(-15).over(5).equals(-3),
"-15 / -5 = 3": bigInt(-15).over(-5).equals(3),
"786456456335437356436 / 5423424653 = 145011041298": bigInt("786456456335437356436").over("5423424653").equals(145011041298),
"93453764643534523 / 2342 = 39903400787162": bigInt("93453764643534523").over(2342).equals("39903400787162"),
"124234233 % 2 = 1": bigInt(124234233).mod(2).equals(1),
"124234233 % -2 = 1": bigInt(124234233).mod(-2).equals(1),
"-124234233 % 2 = -1": bigInt(-124234233).mod(2).equals(-1),
"-124234233 % -2 = -1": bigInt(-124234233).mod(-2).equals(-1),
"93453764643534523 % 2342 = 1119": bigInt("93453764643534523").mod(2342).equals(1119),
"2 ^ 3 = 8": bigInt(2).pow(3).equals(8),
"-2 ^ 3 = -8": bigInt(-2).pow(3).equals(-8),
"2 ^ -3 = 0": bigInt(2).pow(-3).equals(0),
"0-- = -1": bigInt.zero.prev().equals(-1),
"9007199254740992++ = 9007199254740993": bigInt(9007199254740992).next().equals("9007199254740993"),
"Leading zeroes": bigInt("10000000").toString() == "10000000",
"Leading zeroes 2": bigInt("100001010000000").toString() == "100001010000000",
"10 Factorial": (function () {
var res = "3628800"; //http://www.wolframalpha.com/input/?i=10%21
return factorial(bigInt(10)).equals(res);
})(),
"100 Factorial": (function () {
var res = "93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000"; //http://puzzles.nigelcoldwell.co.uk/nineteen.htm
return factorial(bigInt(100)).equals(res);
})(),
"3 ^ 10000": bigInt(3).pow(10000).toString() === "16313501853426258743032567291811547168121324535825379939348203261918257308143190787480155630847848309673252045223235795433405582999177203852381479145368112501453192355166224391025423628843556686559659645012014177448275529990373274425446425751235537341867387607813619937225616872862016504805593174059909520461668500663118926911571773452255850626968526251879139867085080472539640933730243410152186914328917354576854457274195562218013337745628502470673059426999114202540773175988199842487276183685299388927825296786440252999444785694183675323521704432195785806270123388382931770198990841300861506996108944782065015163410344894945809337689156807686673462563038164792190665340124344133980763205594364754963451564072340502606377790585114123814919001637177034457385019939060232925194471114235892978565322415628344142184842892083466227875760501276009801530703037525839157893875741192497705300469691062454369926795975456340236777734354667139072601574969834312769653557184396147587071260443947944862235744459711204473062937764153770030210332183635531818173456618022745975055313212598514429587545547296534609597194836036546870491771927625214352957503454948403635822345728774885175809500158451837389413798095329711993092101417428406774326126450005467888736546254948658602484494535938888656542746977424368385335496083164921318601934977025095780370104307980276356857350349205866078371806065542393536101673402017980951598946980664330391505845803674248348878071010412918667335823849899623486215050304052577789848512410263834811719236949311423411823585316405085306164936671137456985394285677324771775046050970865520893596151687017153855755197348199659070192954771308347627111052471134476325986362838585959552209645382089055182871854866744633737533217524880118401787595094060855717010144087136495532418544241489437080074716158404895914136451802032446707961058757633345691696743293869623745410870051851590672859347061212573446572045088465460616826082579731686004585218284333452396157730036306379421822435818001505905203918209206969662326706952623512427380240468784114535101496733983401240219840048956733689309620321613793757156727562461651933397540266795963865921590913322060572673349849253303397874242381960775337182730037783698708748781738419747698880321601186310506332869704931303076839444790968339306301273371014087248060946851793697973114432706759288546077622831002526800554849696867710280945946603669593797354642136622231192695027321229511912952940320879763123151760555959496961163141455688278842949587288399100273691880018774147568892650186152065335219113072582417699616901995530249937735219099786758954892534365835235843156112799728164123461219817343904782402517111603206575330527850752564642995318064985900815557979945885931124351303252811255254295797082281946658798705979077492469849644183166585950844953164726896146168297808178398470451561320526180542310840744843107469368959707726836608471817060598771730170755446473440774031371227437651048421606224757527085958515947273151027400662948161111284777828103531499488913672800783167888051177155427285103861736658069404797695900758820465238673970882660162285107599221418743657006872537842677883708807515850397691812433880561772652364847297019508025848964833883225165668986935081274596293983121864046277268590401580209059988500511262470167150495261908136688693861324081559046336288963037090312033522400722360882494928182809075406914319957044927504420797278117837677431446979085756432990753582588102440240611039084516401089948868433353748444104639734074519165067632941419347985624435567342072815910754484123812917487312938280670403228188813003978384081332242484646571417574404852962675165616101527367425654869508712001788393846171780457455963045764943565964887518396481296159902471996735508854292964536796779404377230965723361625182030798297734785854606060323419091646711138678490928840107449923456834763763114226000770316931243666699425694828181155048843161380832067845480569758457751090640996007242018255400627276908188082601795520167054701327802366989747082835481105543878446889896230696091881643547476154998574015907396059478684978574180486798918438643164618541351689258379042326487669479733384712996754251703808037828636599654447727795924596382283226723503386540591321268603222892807562509801015765174359627788357881606366119032951829868274617539946921221330284257027058653162292482686679275266764009881985590648534544939224296689791195355783205968492422636277656735338488299104238060289209390654467316291591219712866052661347026855261289381236881063068219249064767086495184176816629077103667131505064964190910450196502178972477361881300608688593782509793781457170396897496908861893034634895715117114601514654381347139092345833472226493656930996045016355808162984965203661519182202145414866559662218796964329217241498105206552200001",
"Fail on negative exponent": (function () {
try {
bigInt("12e-5");
return false;
} catch (e) {
return true;
}
})(),
"Fail on divide by zero": (function () {
try {
bigInt("135346").divide("0");
return false;
} catch (e) {
return true;
}
})(),
"Fail on invalid character in number": (function () {
try {
bigInt("43a34");
return false;
} catch (e) {
return true;
}
})()
});
return assertions.join("<br>");
})(bigInt);
{
"name": "big-integer",
"version": "1.0.3",
"version": "1.0.4",
"author": "Peter Olson <peter.e.c.olson+npm@gmail.com>",

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

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc