-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoog.math.integer.js
10 lines (10 loc) · 3.73 KB
/
goog.math.integer.js
1
2
3
4
5
6
7
8
9
10
var window=global;var $CLJS=require("./cljs_env");require("./goog.base.js");
var fa=function(a,b){this.V=[];this.Z=b;for(var c=!0,d=a.length-1;0<=d;d--){var e=a[d]|0;c&&e==b||(this.V[d]=e,c=!1)}},ja=function(a){if(-128<=a&&128>a){var b=ha[a];if(b)return b}b=new fa([a|0],0>a?-1:0);-128<=a&&128>a&&(ha[a]=b);return b},pa=function(a){if(isNaN(a)||!isFinite(a))return ka;if(0>a)return oa(pa(-a));for(var b=[],c=1,d=0;a>=c;d++)b[d]=a/c|0,c*=qa;return new fa(b,0)},ra=function(a){if(-1==a.Z)return-ra(oa(a));for(var b=0,c=1,d=0;d<a.V.length;d++){var e=sa(a,d);b+=(0<=e?e:qa+e)*c;c*=qa}return b},
sa=function(a,b){return 0>b?0:b<a.V.length?a.V[b]:a.Z},ta=function(a){if(0!=a.Z)return!1;for(var b=0;b<a.V.length;b++)if(0!=a.V[b])return!1;return!0},oa=function(a){for(var b=a.V.length,c=[],d=0;d<b;d++)c[d]=~a.V[d];return(new fa(c,~a.Z)).add(ua)},wa=function(a,b){for(;(a[b]&65535)!=a[b];)a[b+1]+=a[b]>>>16,a[b]&=65535,b++},xa=function(a,b){if(ta(b))throw Error("division by zero");if(ta(a))return ka;if(-1==a.Z)return-1==b.Z?xa(oa(a),oa(b)):oa(xa(oa(a),b));if(-1==b.Z)return oa(xa(a,oa(b)));if(30<a.V.length){if(-1==
a.Z||-1==b.Z)throw Error("slowDivide_ only works with positive integers.");for(var c=ua;0>=b.compare(a);)c=c.shiftLeft(1),b=b.shiftLeft(1);var d=ya(c,1),e=ya(b,1);b=ya(b,2);for(c=ya(c,2);!ta(b);){var f=e.add(b);0>=f.compare(a)&&(d=d.add(c),e=f);b=ya(b,1);c=ya(c,1)}return d}for(c=ka;0<=a.compare(b);){d=Math.max(1,Math.floor(ra(a)/ra(b)));e=Math.ceil(Math.log(d)/Math.LN2);e=48>=e?1:Math.pow(2,e-48);f=pa(d);for(var g=f.multiply(b);-1==g.Z||0<g.compare(a);)d-=e,f=pa(d),g=f.multiply(b);ta(f)&&(f=ua);c=
c.add(f);a=a.add(oa(g))}return c},ya=function(a,b){var c=b>>5;b%=32;for(var d=a.V.length-c,e=[],f=0;f<d;f++)e[f]=0<b?sa(a,f+c)>>>b|sa(a,f+c+1)<<32-b:sa(a,f+c);return new fa(e,a.Z)},ha={},qa=4294967296,ka=ja(0),ua=ja(1),za=ja(16777216);$CLJS.h=fa.prototype;
$CLJS.h.toString=function(a){a=a||10;if(2>a||36<a)throw Error("radix out of range: "+a);if(ta(this))return"0";if(-1==this.Z)return"-"+oa(this).toString(a);for(var b=pa(Math.pow(a,6)),c=this,d="";;){var e=xa(c,b),f=e.multiply(b);c=c.add(oa(f));f=((0<c.V.length?c.V[0]:c.Z)>>>0).toString(a);c=e;if(ta(c))return f+d;for(;6>f.length;)f="0"+f;d=""+f+d}};$CLJS.h.compare=function(a){a=this.add(oa(a));return-1==a.Z?-1:ta(a)?0:1};
$CLJS.h.add=function(a){for(var b=Math.max(this.V.length,a.V.length),c=[],d=0,e=0;e<=b;e++){var f=d+(sa(this,e)&65535)+(sa(a,e)&65535),g=(f>>>16)+(sa(this,e)>>>16)+(sa(a,e)>>>16);d=g>>>16;f&=65535;g&=65535;c[e]=g<<16|f}return new fa(c,c[c.length-1]&-2147483648?-1:0)};
$CLJS.h.multiply=function(a){if(ta(this)||ta(a))return ka;if(-1==this.Z)return-1==a.Z?oa(this).multiply(oa(a)):oa(oa(this).multiply(a));if(-1==a.Z)return oa(this.multiply(oa(a)));if(0>this.compare(za)&&0>a.compare(za))return pa(ra(this)*ra(a));for(var b=this.V.length+a.V.length,c=[],d=0;d<2*b;d++)c[d]=0;for(d=0;d<this.V.length;d++)for(var e=0;e<a.V.length;e++){var f=sa(this,d)>>>16,g=sa(this,d)&65535,k=sa(a,e)>>>16,l=sa(a,e)&65535;c[2*d+2*e]+=g*l;wa(c,2*d+2*e);c[2*d+2*e+1]+=f*l;wa(c,2*d+2*e+1);c[2*
d+2*e+1]+=g*k;wa(c,2*d+2*e+1);c[2*d+2*e+2]+=f*k;wa(c,2*d+2*e+2)}for(d=0;d<b;d++)c[d]=c[2*d+1]<<16|c[2*d];for(d=b;d<2*b;d++)c[d]=0;return new fa(c,0)};$CLJS.h.and=function(a){for(var b=Math.max(this.V.length,a.V.length),c=[],d=0;d<b;d++)c[d]=sa(this,d)&sa(a,d);return new fa(c,this.Z&a.Z)};$CLJS.h.or=function(a){for(var b=Math.max(this.V.length,a.V.length),c=[],d=0;d<b;d++)c[d]=sa(this,d)|sa(a,d);return new fa(c,this.Z|a.Z)};
$CLJS.h.xor=function(a){for(var b=Math.max(this.V.length,a.V.length),c=[],d=0;d<b;d++)c[d]=sa(this,d)^sa(a,d);return new fa(c,this.Z^a.Z)};$CLJS.h.shiftLeft=function(a){var b=a>>5;a%=32;for(var c=this.V.length+b+(0<a?1:0),d=[],e=0;e<c;e++)d[e]=0<a?sa(this,e-b)<<a|sa(this,e-b-1)>>>32-a:sa(this,e-b);return new fa(d,this.Z)};