-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjints.min.js
1 lines (1 loc) · 7.38 KB
/
jints.min.js
1
!function(t){function r(t,r){if(t instanceof n||(t=new n(t)),r instanceof n||(r=new n(r)),0!==r.negative){r.negative=0;var o=e(t,r);return r.negative=1,o}if(0!==t.negative){t.negative=0;var i=e(t,r);return t.negative=1,i.negative=1,i}var s=t.compare(r);if(0===s)return new n;var h,a;s>0?(h=t.clone(),a=r.clone()):(a=t.clone(),h=r.clone());var f,u=h.clone(),l=0,d=0;for(d=0;d<a.length;d++)f=(0|h.words[d])-(0|a.words[d])+l,l=f>>26,u.words[d]=67108863&f;for(;0!==l&&d<h.length;d++)f=(0|h.words[d])+l,l=f>>26,u.words[d]=67108863&f;if(0===l&&d<h.length&&s<=0)for(;d<h.length;d++)u.words[d]=h.words[d];return s<0&&!u.isZero()&&(u.negative=1),u}function e(t,e){if(t instanceof n||(t=new n(t)),e instanceof n||(e=new n(e)),0!==t.negative&&0===e.negative){t.negative=0;var o=r(t,e);return t.negative=1,o.negative^=1,o}if(0===t.negative&&0!==e.negative){e.negative=0;var i=r(t,e);return e.negative=1,i}var s,h;t.length>e.length?(s=t.clone(),h=e.clone()):(h=t.clone(),s=e.clone());var a,f=0,u=0,l=s.clone();for(u=0;u<h.length;u++)a=(0|s.words[u])+(0|h.words[u])+f,l.words[u]=67108863&a,f=a>>>26;for(;0!==f&&u<s.length;u++)a=(0|s.words[u])+f,l.words[u]=67108863&a,f=a>>>26;if(0!==f)l.words[l.length]=f;else if(t.length<=e.length)for(;u<s.length;u++)l.words[u]=s.words[u];return l}var n=function(){function t(t){if(void 0===t&&(t=null),this.negative=0,"string"==typeof t){var r=t.match(/^([+-]?)((?:0x|0b|0o)?)(\w+)/i);if(r){var e={"0b":2,"0o":8,"0x":16}[r[2].toLowerCase()]||10;"-"===r[1]&&(this.negative=1),this.parse(r[3],e,0)}else this.words=[0]}else t<0&&(this.negative=1,t=-t),this.words=t<67108864?[67108863&t]:t<4503599627370496?[67108863&t,t/67108864&67108863]:[67108863&t,t/67108864&67108863,1]}return t.parseText=function(t,r,e,n){for(var o=0,i=Math.min(t.length,e),s=r;s<i;s++){o*=n;var h=t.charCodeAt(s)-48;o+=h>=49?h-49+10:h>=17?h-17+10:h}return o},t.prototype.parse=function(r,e,n){void 0===n&&(n=0),this.words=[0];for(var o=0,i=1;i<=67108863;i*=e)o++;o--,i=i/e|0;var s,h=r.length-n,a=h%o,f=Math.min(h,h-a)+n,u=0;for(s=n;s<f;s+=o)u=t.parseText(r,s,s+o,e),this.mul(i),this.words[0]+u<67108864?this.words[0]+=u:this.add(u);if(0!==a){var l=1;for(u=t.parseText(r,s,r.length,e),s=0;s<a;s++)l*=e;this.mul(l),this.words[0]+u<67108864?this.words[0]+=u:this.add(u)}},t.prototype.div=function(t){for(var r=0,e=this.words.length-1;e>=0;e--){var n=(0|this.words[e])+67108864*r;this.words[e]=n/t|0,r=n%t}this.strip()},t.prototype.strip=function(){for(;this.words.length>1&&0===this.words[this.words.length-1];)this.words.length--;this.normSign()},t.prototype.normSign=function(){1===this.words.length&&0===this.words[0]&&(this.negative=0)},t.prototype.mul=function(t){for(var r=0,e=0;e<this.words.length;e++){var n=(0|this.words[e])*t,o=(67108863&n)+(67108863&r);r>>=26,r+=n/67108864|0,r+=o>>>26,this.words[e]=67108863&o}0!==r&&(this.words[e]=r)},t.prototype.add=function(t){this.words[0]+=t;for(var r=0;r<this.words.length&&this.words[r]>=67108864;r++)this.words[r]-=67108864,r===this.words.length-1&&(this.words[r+1]=0),this.words[r+1]++},t.prototype.mod=function(t){for(var r=(1<<26)%t,e=0,n=this.words.length-1;n>=0;n--)e=(r*e+(0|this.words[n]))%t;return e},t.prototype.isZero=function(){return 1===this.words.length&&0===this.words[0]},t.prototype.clone=function(){var r=new t;return r.words=this.words.slice(),r.negative=this.negative,r},t.prototype.toString=function(t){if(void 0===t&&(t=10),this.isZero())return"0";var r=Math.floor(26*Math.LN2/Math.log(t)),e=Math.pow(t,r),n="",o=this.clone();for(o.negative=0;!o.isZero();){var i=o.mod(e).toString(t);o.div(e),n=o.isZero()?i+n:new Array(r-i.length+1).join("0")+i+n}return 1===this.negative&&(n="-"+n),n},Object.defineProperty(t.prototype,"length",{get:function(){return this.words.length},enumerable:!0,configurable:!0}),t.prototype.compare=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var r=0!==this.negative?-1:1;if(this.length>t.length)return 1*r;if(this.length<t.length)return-1*r;for(var e=this.length-1;e>=0;e--){var n=0|this.words[e],o=0|t.words[e];if(n!==o)return n<o?-1*r:1*r}return 0},t.prototype.bitLength=function(){var t=this.words[this.length-1],r=32-function(t){return null==t||0===t?32:31-Math.floor(Math.log(t>>>0)*Math.LOG2E)}(t);return 26*(this.length-1)+r},t.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},t.prototype.and=function(t){return this.words[0]&t},t.prototype.shr=function(t){var r=0,e=t%26,n=Math.min((t-e)/26,this.length),o=67108863^67108863>>>e<<e;if(r-=n,r=Math.max(0,r),0===n);else if(this.length>n){for(var i=0;i<this.length-n;i++)this.words[i]=this.words[i+n];this.words.length-=n}else this.words=[0];for(var s=0,i=this.length-1;i>=0&&(0!==s||i>=r);i--){var h=0|this.words[i];this.words[i]=s<<26-e|h>>>e,s=h&o}this.strip()},t.prototype.toArray=function(t,r){void 0===t&&(t="le"),void 0===r&&(r=0);var e,n=this.byteLength(),o=r||Math.max(1,n),i=new Array(o),s=this.clone();if("le"!==t){for(e=0;e<o-n;e++)i[e]=0;for(e=0;!s.isZero();e++){var h=s.and(255);s.shr(8),i[o-e-1]=h}}else{for(e=0;!s.isZero();e++){var h=s.and(255);s.shr(8),i[e]=h}for(;e<o;e++)i[e]=0}return i},t.prototype.fromArray=function(t,r){if(void 0===r&&(r="le"),t.length<=0)return this.words=[0],this;var e=Math.ceil(t.length/3);this.words=new Array(e);for(var n=0;n<e;n++)this.words[n]=0;var o=0;if("be"===r)for(var n=t.length-1,i=0;n>=0;n-=3){var s=t[n]|t[n-1]<<8|t[n-2]<<16;this.words[i]|=s<<o&67108863,this.words[i+1]=s>>>26-o&67108863,o+=24,o>=26&&(o-=26,i++)}else for(var n=0,i=0;n<t.length;n+=3){var s=t[n]|t[n+1]<<8|t[n+2]<<16;this.words[i]|=s<<o&67108863,this.words[i+1]=s>>>26-o&67108863,o+=24,o>=26&&(o-=26,i++)}this.strip()},t.prototype.abs=function(){this.negative=0},t.prototype.expand=function(t){for(;this.length<t;)this.words[this.words.length++]=0},t.prototype.twos=function(t){0!==this.negative&&(this.abs(),this.not(t),this.add(1))},t.prototype.not=function(t){var r=0|Math.ceil(t/26),e=t%26;this.expand(r),e>0&&r--;for(var n=0;n<r;n++)this.words[n]=67108863&~this.words[n];e>0&&(this.words[n]=~this.words[n]&67108863>>26-e),this.strip()},t}(),o=function(){function t(t){this.value=new n(t),this.value.twos(64);var r=new Int32Array(new Uint8Array(this.toArray()).buffer);this.low=r[0],this.high=r[1]}return t.compare=function(t,r){return t.value.compare(r.value)},t.hi=function(t){return t.high},t.lo=function(t){return t.low},t.join=function(r,e){var n=new t(0),o=new Uint8Array(new Int32Array([e,r]).buffer);return n.value.fromArray(o),n.low=e,n.high=r,n},t.prototype.toString=function(t){return void 0===t&&(t=10),this.value.toString(t)},t.prototype.toArray=function(t){return void 0===t&&(t="le"),this.value.toArray(t,8)},t}(),i=function(){function t(t){this.value=new n(t);var r=new Int32Array(new Uint8Array(this.toArray()).buffer);this.low=r[0],this.high=r[1]}return t.compare=function(t,r){return t.value.compare(r.value)},t.hi=function(t){return t.high},t.lo=function(t){return t.low},t.join=function(r,e){var n=new t(0),o=new Uint8Array(new Int32Array([e,r]).buffer);return n.value.fromArray(o),r<0&&(n.value.negative=1,n.value.twos(64),n.value.negative=1),n.low=e,n.high=r,n},t.prototype.toString=function(t){return void 0===t&&(t=10),this.value.toString(t)},t.prototype.toArray=function(t){void 0===t&&(t="le");var r=this.value.clone();return r.twos(64),r.toArray(t,8)},t}(),s={add:e,sub:r},h={BigInteger:n,UInt64:o,Int64:i,BigMath:s};"function"==typeof define?(define.amd||define.cmd)&&define(function(){return h}):"undefined"!=typeof module&&module.exports?module.exports=h:window.jints=h}();