powiaina_num.js 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self).PowiainaNum={})}(this,(function(r){"use strict";function e(r){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}function t(r,e,t){if(t||2===arguments.length)for(var a,n=0,o=e.length;n<o;n++)!a&&n in e||(a||(a=Array.prototype.slice.call(e,0,n)),a[n]=e[n]);return r.concat(a||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var a=9007199254740991,n=15.954589770191003,o=1.444667861009766,i=/^(PN)?[\/\-\+]*(Infinity|NaN|(P+|P\^\d+ )?(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})|\(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})\)\^[1-9]\d*\x20*)*((\d+(\.\d*)?|\d*\.\d+)?([Ee][-\+]*))*(0|\d+(\.\d*)?|\d*\.\d+))$/;function s(r,e,t,a){return void 0===e&&(e=0),void 0===t&&(t=1),void 0===a&&(a=1),{repeat:r,arrow:e,expans:t,megota:a,valuereplaced:e==1/0?0:t==1/0?1:-1}}function u(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];for(var t=0;t<Math.min(r[0].length,r[1].length);t++){var a=r[0][t],n=r[1][t];if(a<n)return-1;if(a>n)return 1}return 0}function l(r){return Math.log10(Number(r.substring(0,17)))+(r.length-17)}var p=.5671432904097838;function c(r,e,t){void 0===e&&(e=1e-10),void 0===t&&(t=!0);var a,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-10,i=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!Number.isFinite(r))return r;if(i){if(0===r)return r;if(1===r)return p;a=r<10?0:Math.log(r)-Math.log(Math.log(r))}else{if(0===r)return-1/0;a=r<=-.1?-2:Math.log(-r)-Math.log(-Math.log(-r))}for(var s=0;s<100;++s){if(n=(r*Math.exp(-a)+a*a)/(a+1),Math.abs(n-a)<o*Math.abs(n))return n;a=n}throw Error("Iteration failed to converge: ".concat(r.toString()))}function f(r){return 2==r.length}function g(r){return"number"==typeof r[0]&&"number"==typeof r[1]}function h(r,e,t){var a;if(void 0===e&&(e=1e10),void 0===t&&(t=!0),!(r=new N(r)).isFinite())return r;if(t){if(r.eq(N.ZERO))return r;if(r.eq(N.ONE))return new N(p);a=N.log(r)}else{if(r.eq(N.ZERO))return N.NEGATIVE_INFINITY.clone();a=N.log(r.neg())}for(var n=0;n<100;++n){var o=a.neg().exp(),i=a.sub(r.mul(o)),s=a.add(N.ONE).sub(a.add(2).mul(i).div(N.mul(2,a).add(2)));if(s.eq(N.ZERO))return a;var u=a.sub(i.div(s));if(N.abs(u.sub(a)).lt(N.abs(u).mul(e)))return u;a=u}throw Error("Iteration failed to converge: "+r)}function y(r,e){return u([r.megota,r.expans,r.arrow],[e.megota,e.expans,e.arrow])}var N=function(){function r(t){if(this[p]="PowiainaNum",this.array=[{arrow:0,expans:1,megota:1,repeat:NaN}],this.small=!1,this.sign=0,this.layer=0,void 0===t);else if("number"==typeof t){var a=r.fromNumber(t);this.resetFromObject(a)}else if("object"==e(t)){a=r.fromObject(t);this.resetFromObject(a)}else if("string"==typeof t){a=r.fromString(t);this.resetFromObject(a)}}var p,N;return r.prototype.add=function(e){var t,o,i,u,l,p,c=this.clone(),f=new r(e);if(c.eq(r.POSITIVE_INFINITY)&&f.eq(r.NEGATIVE_INFINITY)||c.eq(r.NEGATIVE_INFINITY)&&f.eq(r.POSITIVE_INFINITY))return r.NaN.clone();if(!c.isFinite())return c.clone();if(!f.isFinite())return f.clone();if(c.isZero())return f.clone();if(f.isZero())return c.clone();if(c.sign==-f.sign&&function(){var r=c.abs(),e=f.abs();return r.eq(e)}())return r.ZERO.clone();if(c.abs().lt(a)&&f.abs().lt(a))return r.fromNumber(c.toNumber()+f.toNumber());if(c.abs().lt(r.E_MSI_REC)||c.abs().gt(r.E_MSI)||f.abs().lt(r.E_MSI_REC)||f.abs().gt(r.E_MSI))return c.maxabs(f);if(-1==c.sign)return c.neg().add(f.neg()).neg();c.cmpabs(f)>0?(l=c,p=f):(p=c,l=f);var g=l.toNumber()+p.toNumber();if(isFinite(g)&&0!==g)return r.fromNumber(g);var h=1;if(!(l.small||p.small||(null===(t=l.array[1])||void 0===t?void 0:t.repeat)||(null===(o=p.array[1])||void 0===o?void 0:o.repeat)||l.sign!=p.sign))return new r((l.array[0].repeat+p.array[0].repeat)*l.sign);var y=(l.small?-1:1)*((null===(i=l.array[1])||void 0===i?void 0:i.repeat)?l.array[0].repeat:Math.log10(l.array[0].repeat)),N=(p.small?-1:1)*((null===(u=p.array[1])||void 0===u?void 0:u.repeat)?p.array[0].repeat:Math.log10(p.array[0].repeat));if(y-N>n)return l;var m,w,v=-Math.floor(y),b=0;if((w=l.sign*Math.pow(10,y+v)+p.sign*Math.pow(10,N+v))>0&&(b=Math.log10(w)-v),w<0&&(b=Math.log10(-w)-v,h*=-1),0==w)throw Error("Encounter a calculate error");return(m=new r).sign=1,m.array=b>n||b<-n?[s(b,0),s(1,1)]:[s(Math.pow(10,Math.abs(b)),0)],m.small=b<0,m.sign*=h,m},r.add=function(e,t){return new r(e).add(t)},r.prototype.sub=function(e){return this.add(new r(e).neg())},r.sub=function(e,t){return new r(e).sub(t)},r.prototype.mul=function(e){var t=this.clone(),a=new r(e);if(t.eq(r.POSITIVE_INFINITY)&&a.eq(r.NEGATIVE_INFINITY)||a.eq(r.POSITIVE_INFINITY)&&t.eq(r.NEGATIVE_INFINITY))return r.NEGATIVE_INFINITY.clone();if(t.isInfiNaN()&&a.isZero()||a.isInfiNaN()&&t.isZero())return r.NaN.clone();if(t.eq(r.NEGATIVE_INFINITY)&&a.eq(r.NEGATIVE_INFINITY))return r.POSITIVE_INFINITY.clone();if(!t.isFinite())return t.clone();if(!a.isFinite())return a.clone();if(t.isZero()||a.isZero())return r.ZERO.clone();var n,o=t.toNumber()*a.toNumber();return isFinite(o)&&0!==o?r.fromNumber(o):((n=t.abs().log10().add(a.abs().log10()).pow10()).sign=t.sign*a.sign,n)},r.mul=function(e,t){return new r(e).mul(t)},r.prototype.div=function(e){var t=new r(e).rec();return this.mul(t)},r.div=function(e,t){return new r(e).div(t)},r.prototype.mod=function(e){var t=new r(e),a=this.div(t);return a.sub(a.floor()).mul(t)},r.prototype.pow10=function(){var e,t,a=this.clone();return this.isFinite()?a.isneg()?(a.sign*=-1,a.pow10().rec()):a.lte(308.25471555991675)?r.fromNumber(Math.pow(10,a.toNumber())):a.small?a.lt(r.MSI_REC)?r.ONE:new r(Math.pow(10,Math.pow(a.array[0].repeat,-1))):(a.gt(r.TETRATED_MSI)||(a.setOperator((null!==(t=null===(e=a.array[1])||void 0===e?void 0:e.repeat)&&void 0!==t?t:0)+1,1),a.normalize()),a):this.clone()},r.prototype.pow=function(e){var t=new r(e);if(this.eq(1))return r.ONE.clone();if(!t.isFinite())return t.clone();if(!this.isFinite())return this.clone();if(this.eq(10))return t.pow10();if(this.isneg()){if(!t.isInt())return r.NaN.clone();var a=this.abs().pow(t);return a.sign=function(){var r=t.mod(2).round();return r.eq(0)||r.eq(2)?1:-1}(),a}var n=this.toNumber(),o=t.toNumber(),i=Math.pow(n,o);return isFinite(i)&&0!==i?r.fromNumber(i):this.isZero()&&t.isZero()?r.ONE.clone():this.isZero()?r.ZERO.clone():t.isZero()?r.ONE.clone():this.gt(0)?this.log10().mul(t).pow10():t.rec().mod(2).eq(1)?this.neg().log10().mul(t).pow10().neg():r.NaN.clone()},r.prototype.pow_base=function(e){return new r(e).pow(this)},r.pow=function(e,t){return new r(e).pow(t)},r.prototype.root=function(e){var t=new r(e);return this.pow(t.rec())},r.root=function(e,t){return new r(e).root(t)},r.prototype.sqrt=function(){return this.pow(.5)},r.sqrt=function(e){return new r(e).sqrt()},r.prototype.cbrt=function(){return this.abs().root(3).mul(this.sign)},r.cbrt=function(e){return new r(e).cbrt()},r.prototype.log10=function(){if(this.isneg())return r.NaN.clone();if(this.isZero())return r.NEGATIVE_INFINITY.clone();if(this.small){var e=this.clone();return e.small=!e.small,e.log10().neg()}if(1==this.array.length)return new r(Math.log10(this.array[0].repeat));if(this.gte(r.TETRATED_MSI))return this.clone();var t=this.clone();return t.array[1].repeat=t.array[1].repeat-1,t.normalize(),t},r.log10=function(e){return new r(e).log10()},r.prototype.log=function(e){void 0===e&&(e=Math.E);var t=new r(e);return this.log10().div(t.log10())},r.log=function(e,t){return void 0===t&&(t=Math.E),new r(e).log(t)},r.prototype.ln=function(){return this.log()},r.prototype.pLog10=function(){return this.isneg()?r.ZERO:this.log10()},r.pLog10=function(e){return new r(e).pLog10()},r.exp=function(e){return new r(e).pow_base(Math.E)},r.prototype.exp=function(){return this.pow_base(Math.E)},r.prototype.factorial=function(){return this.abs().lt(a)?this.add(1).gamma():this.abs().lt(r.E_MSI)?r.exp(this.mul(this.log10().sub(1))):r.exp(this)},r.factorial=function(e){return new r(e).factorial()},r.prototype.gamma=function(){if(this.small)return this.rec();if(this.lte(a)){if(this.lt(24))return r.fromNumber(function(r){if(!isFinite(r))return r;if(r<-50)return r===Math.trunc(r)?Number.NEGATIVE_INFINITY:0;for(var e=1;r<10;)e*=r,++r;var t=.9189385332046727;t+=((r-=1)+.5)*Math.log(r),t-=r;var a=r*r,n=r;return t+=1/(12*n),t-=1/(360*(n*=a)),t+=1/(1260*(n*=a)),t-=1/(1680*(n*=a)),t+=1/(1188*(n*=a)),t-=691/(360360*(n*=a)),t+=7/(1092*(n*=a)),t-=3617/(122400*(n*=a)),Math.exp(t)/e}(this.sign*this.getOperator(0)));var e=this.getOperator(0)-1,t=.9189385332046727;t+=(e+.5)*Math.log(e);var n=e*e,o=e,i=12*o,s=1/i,u=(t-=e)+s;if(u===t)return r.exp(t);if((u=(t=u)-(s=1/(i=360*(o*=n))))===t)return r.exp(t);t=u;var l=1/(i=1260*(o*=n));return t+=l,t-=l=1/(i=1680*(o*=n)),r.exp(t)}return this.gt(a)?r.exp(this.mul(this.log().sub(1))):r.exp(this)},r.gamma=function(e){return new r(e).gamma()},r.prototype.lambertw=function(e){void 0===e&&(e=!0);var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this.lt(-.3678794411710499)?r.NaN.clone():t?this.abs().lt("1e-300")?new r(this):this.small?r.fromNumber(c(this.toNumber())):this.lt(a)?r.fromNumber(c(this.sign*this.getOperator(0))):this.lt("eee15")?h(this):this.log():1===this.sign?r.NaN.clone():0===this.layer?r.fromNumber(c(this.sign*this.array[0].repeat,1e-10,!1)):1==this.layer?h(this,1e-10,!1):this.neg().rec().lambertw().neg()},r.lambertw=function(e,t){return void 0===t&&(t=!0),new r(e).lambertw(t)},r.prototype.tetrate=function(e,t){void 0===t&&(t=1);var n,i=this.clone(),s=new r(e),u=new r(t);if(i.isNaN()||s.isNaN()||u.isNaN())return r.NaN.clone();if(i.eq(1))return r.ONE.clone();if(u.neq(r.ONE)&&(s=s.add(u.slog(i))),s.isInfi()&&s.sign>0)return i.gte(o)?r.POSITIVE_INFINITY.clone():(n=this.log().neg()).lambertw().div(n);if(s.lte(-2))return r.NaN.clone();if(i.isZero())return s.isZero()?r.NaN.clone():s.gte(a/2)||s.toNumber()%2==0?r.ZERO.clone():r.ONE.clone();if(i.eq(r.ONE))return s.eq(r.ONE.neg())?r.NaN.clone():r.ONE.clone();if(s.eq(r.ONE.neg()))return r.ZERO.clone();if(s.eq(r.ZERO))return r.ONE.clone();if(s.eq(r.ONE))return i;if(s.eq(2))return i.pow(i);if(i.eq(2)){if(s.eq(3))return r.fromNumber(16);if(s.eq(4))return r.fromNumber(65536)}var l=i.max(s);if(l.gt(r.PENTATED_MSI))return l;if(l.gt(r.TETRATED_MSI)||s.gt(a)){if(this.lt(o))return(n=i.ln().neg()).lambertw().div(n);var p=i.slog(10).add(s);return p.setOperator(p.getOperator(2)+1,2),p.normalize(),p}for(var c=s.toNumber(),f=Math.floor(c),g=i.pow(c-f),h=r.NaN,y=0,N=r.E_MSI.clone();0!==f&&g.lt(N)&&y<100;++y)if(f>0){if(g=i.pow(g),h.eq(g)){f=0;break}h=g,--f}else{if(g=g.log(i),h.eq(g)){f=0;break}h=g,++f}return(100==y||this.lt(o))&&(f=0),g.setOperator(g.getOperator(1)+f,1),g.normalize(),g},r.prototype.slog=function(e){void 0===e&&(e=10);var t=this.clone(),a=new r(e);if(t.isInfiNaN())return t;if(a.isNaN())return a;if(a.isInfi())return r.ZERO.clone();if(t.isZero())return r.ONE.clone();if(t.eq(r.ONE))return r.ZERO.clone();if(t.eq(a))return r.ONE.clone();if(a.lt(o)){var n=a.tetrate(1/0);if(t.eq(n))return r.POSITIVE_INFINITY.clone();if(t.gt(n))return r.NaN.clone()}if(t.max(a).gt(r.PENTATED_MSI))return t.gt(a)?t:r.ZERO.clone();if(t.max(a).gt(r.TETRATED_MSI)&&t.gt(a))return t.setOperator(t.getOperator(2)-1,2),t.normalize(),t.sub(t.getOperator(1));if(t.lt(r.ZERO.clone()))return a.pow(t).sub(2);var i=0,s=t.getOperator(1)-a.getOperator(1);if(s>3){var u=s-3;i+=u,t.setOperator(t.getOperator(1)-u,1)}for(var l=0;l<100;++l)if(t.lt(r.ZERO))t=r.pow(e,t),--i;else{if(t.lte(1))return new r(i+t.toNumber()-1);++i,t=r.log(t,e)}return t.gt(10)?new r(i):r.NaN.clone()},r.tetrate=function(e,t,a){return void 0===a&&(a=1),new r(e).tetrate(t,a)},r.prototype.ssqrt=function(){var e=this.clone();if(e.lt(1/o))return r.NaN.clone();if(!e.isFinite())return e;if(e.gt(r.TETRATED_MSI))return e;if(e.gt(r.EE_MSI))return e.setOperator(e.getOperator(1)-1,1),e;var t=e.ln();return t.div(t.lambertw())},r.tetrate_10=function(e){return r.fromNumber(10).tetrate(e)},r.prototype.iteratedlog=function(e,t){void 0===e&&(e=1),void 0===t&&(t=10);var a=this.clone(),n=new r(t),o=new r(e);return o.isZero()?a:o.eq(r.ONE)?a.log(n):n.tetrate(a.slog(n).sub(o))},r.prototype.arrow=function(e){var t=this.clone(),n=new r(e);return!n.isInt()||n.lt(r.ZERO)?(console.warn("The arrow is <0 or not a integer, the returned function will return NaN."),function(){return r.NaN.clone()}):n.eq(0)?function(r){return t.mul(r)}:n.eq(1)?function(r){return t.pow(r)}:n.eq(2)?function(r){return t.tetrate(r)}:function(e,o,i){void 0===i&&(i=0);var u=new r(e),l=new r(o),p=r.arrowFuncMap.get("".concat(t.toString()," ").concat(n.toString()," ").concat(u.toString()," ").concat(i));if(p)return p.clone();var c=function(){var e;if(t.isNaN()||u.isNaN()||l.isNaN())return r.NaN.clone();if(u.lt(r.ZERO))return r.NaN.clone();if(t.eq(r.ZERO))return u.eq(r.ONE)?r.ZERO.clone():r.NaN.clone();if(l.neq(r.ONE)&&(u=u.add(l.anyarrow_log(n)(t))),t.eq(r.ONE))return r.ONE.clone();if(u.eq(r.ZERO))return r.ONE.clone();if(u.eq(r.ONE))return t.clone();if(n.gt(r.MSI))return(e=n.clone()).setOperator(e.getOperator(1/0)+1,1/0),e;var o=n.toNumber();if(u.eq(2))return t.arrow(o-1)(t,l,i+1);if(t.max(u).gt(r.arrowMSI(o+1)))return t.max(u);if(t.gt(r.arrowMSI(o))||u.gt(a)){t.gt(r.arrowMSI(o))?((e=t.clone()).setOperator(e.getOperator(o)-1,o),e.normalize()):e=t.gt(r.arrowMSI(o-1))?new r(t.getOperator(o-1)):r.ZERO;var p=e.add(u);return p.setOperator(p.getOperator(o)+1,o),p.normalize(),p}if(i>=r.maxOps+10)return new r({small:!1,sign:1,layer:0,array:[s(10,0),s(1,o)]});var c=u.toNumber(),f=Math.floor(c),g=n.sub(r.ONE);e=t.arrow(g)(c-f,l,i+1);for(var h=0,y=r.arrowMSI(o-1);0!==f&&e.lt(y)&&h<100;h++)f>0&&(e=t.arrow(g)(e,l,i+1),--f);return 100==h&&(f=0),e.setOperator(e.getOperator(o-1)+f,o-1),e.normalize(),e}();return i<r.maxOps+10&&r.arrowFuncMap.set("".concat(t.toString()," ").concat(n.toString()," ").concat(u.toString()," ").concat(i),c.clone()),c}},r.prototype.anyarrow_log=function(e){var t=this.clone(),n=new r(e),o=n.toNumber();if(n.gt(a))throw new Error("[PowiainaNum 0.2 error]Not implemented");return!n.isInt()||n.lt(0)?function(){return r.NaN.clone()}:n.eq(0)?function(r){return t.div(r)}:n.eq(1)?function(r){return t.log(r)}:n.eq(2)?function(r){return t.slog(r)}:t.isInfiNaN()?function(){return t}:function(e,a){void 0===a&&(a=0);var n=new r(e);if(n.isNaN())return n;if(n.isInfi())return r.ZERO.clone();if(t.isZero())return r.ONE.clone();if(t.eq(r.ONE))return r.ZERO.clone();if(t.eq(n))return r.ONE.clone();if(t.max(n).gt(r.arrowMSI(o+1)))return t.gt(n)?t:r.ZERO.clone();if(t.max(n).gt(r.arrowMSI(o))&&t.gt(n))return t.setOperator(t.getOperator(o)-1,o),t.normalize(),t.sub(t.getOperator(o-1));if(t.lt(r.ZERO.clone()))return r.NaN.clone();var i=0,s=t.getOperator(o)-n.getOperator(o);if(s>3){var u=s-3;i+=u,t.setOperator(t.getOperator(o)-u,o)}for(var l=0;l<100;++l)if(t.lt(r.ZERO))t=t.arrow(o-1)(e),--i;else{if(t.lte(1))return new r(i+t.toNumber()-1);++i,t=t.anyarrow_log(o-1)(e,a+1)}return t.gt(10)?new r(i):r.NaN.clone()}},r.prototype.arrow_height_inverse=function(r){return this.anyarrow_log(r)},r.arrowMSI=function(e){return new r("10{".concat(e,"}").concat(a))},r.prototype.chain=function(r,e){return this.arrow(e)(r)},r.hyper=function(e){var t=new r(e);return t.eq(0)?function(e,t){return new r(t).eq(0)?new r(e):new r(e).add(1)}:t.eq(1)?r.add:t.eq(2)?r.mul:t.eq(3)?r.pow:function(e,a){return new r(e).arrow(t.sub(2))(a)}},r.prototype.pentate=function(r){return this.arrow(3)(r)},r.prototype.hexate=function(r){return this.arrow(4)(r)},r.prototype.penta_log=function(r){return void 0===r&&(r=10),this.anyarrow_log(3)(r)},r.prototype.expansion=function(e){var t,n=new r(e),o=this.clone();if(n.lt(r.ZERO)||!n.isInt())return r.NaN.clone();if(n.eq(r.ONE))return this.clone();if(this.eq(r.ONE))return r.ONE.clone();if(!this.isInt())return r.NaN.clone();if(this.eq(2))return new r(4);if(n.eq(0))return r.ONE.clone();if(o.gt("10{1,2}".concat(a))||n.gt(a)){o.gt("10{1,2}".concat(a))?((t=o.clone()).setOperator(t.getOperator(1,2)-1,1,2),t.normalize()):t=o.gt("10{".concat(a,"}10"))?new r(o.getOperator(1/0)):r.ZERO;var i=t.add(n);return i.setOperator(i.getOperator(1,2)+1,1,2),i.normalize(),i}var s,u=n.toNumber()-1;for(t=o.clone(),s=0;0!==u&&t.lt(a)&&s<100;++s)u>0&&(t=o.arrow(t)(o),--u);return 100==s&&(u=0),t.setOperator(t.getOperator(1/0)+u,1/0),t.normalize(),t},r.prototype.expansionArrow=function(e){var t=new r(e),n=this.clone();if(t.lt(0)||!t.isInt()||t.isNaN()||this.isNaN())return function(){return r.NaN.clone()};if(t.eq(0))return function(r){return n.arrow(r)(n)};if(t.eq(1))return function(r){return n.expansion(r)};var o=t;return function(e,t){void 0===t&&(t=0);var i,u=new r(e);if(n.isNaN()||u.isNaN())return r.NaN.clone();if(u.lt(r.ZERO))return r.NaN.clone();if(n.eq(r.ZERO))return u.eq(r.ONE)?r.ZERO.clone():r.NaN.clone();if(n.eq(r.ONE))return r.ONE.clone();if(u.eq(r.ZERO))return r.ONE.clone();if(u.eq(r.ONE))return n.clone();if(o.gt(r.MSI))return(i=o.clone()).setOperator(i.getOperator(1/0,2)+1,1/0,2),i;var l=o.toNumber();if(u.eq(2))return n.expansionArrow(l-1)(n,t+1);if(n.max(u).gt("10{".concat(l+1,",2}").concat(a)))return n.max(u);if(n.gt("10{".concat(l,",2}").concat(a))||u.gt(a)){n.gt("10{".concat(l,",2}").concat(a))?((i=n.clone()).setOperator(i.getOperator(l,2)-1,l,2),i.normalize()):i=n.gt("10{".concat(l-1,",2}").concat(a))?new r(n.getOperator(l-1,2)):r.ZERO;var p=i.add(u);return p.setOperator(p.getOperator(l,2)+1,l,2),p.normalize(),p}if(t>=r.maxOps+10)return new r({small:!1,sign:1,layer:0,array:[s(10,0),s(1,l,2)]});var c=u.toNumber(),f=Math.floor(c),g=o.sub(r.ONE);i=n.expansionArrow(g)(c-f,t+1);for(var h=0,y=new r("10{".concat(l-1,",2}").concat(a));0!==f&&i.lt(y)&&h<100;h++)f>0&&(i=n.expansionArrow(g)(i,t+1),--f);return 100==h&&(f=0),i.setOperator(i.getOperator(l-1,2)+f,l-1,2),i.normalize(),i}},r.expansion=function(e,t){return new r(e).expansion(t)},r.prototype.multiExpansion=function(r){return this.expansionArrow(2)(r)},r.multiExpansion=function(e,t){return new r(e).multiExpansion(t)},r.prototype.powerExpansion=function(r){return this.expansionArrow(3)(r)},r.powerExpansion=function(e,t){return new r(e).powerExpansion(t)},r.prototype.explosion=function(e){return r.BEAF(this,e,1,3)},r.prototype.megotion=function(e){return r.BEAF(this,e,1,1,2)},r.prototype.powiaination=function(e){return r.BEAF(this,e,1,1,1,2)},r.BEAF=function(e,n,o,i,u,l,p){void 0===o&&(o=1),void 0===i&&(i=1),void 0===u&&(u=1),void 0===l&&(l=1),void 0===p&&(p=0);var c=new r(e),f=new r(n);function g(e){var t;return new r(null!==(t=[o,i,u,l][e])&&void 0!==t?t:1)}if(c.eq(1))return new r(1);if(f.eq(1))return new r(c);if(f.isZero())return new r(1);if(c.lt(0))return r.NaN.clone();if(new r(l).gte(3))return r.POSITIVE_INFINITY.clone();if(g(0).eq(1)&&g(1).eq(1)&&g(2).eq(1))return c.pow(f);if(g(0).eq(2)&&g(1).eq(1)&&g(2).eq(1)&&g(3).eq(1))return c.tetrate(f);if(g(1).eq(1)&&g(2).eq(1)&&g(3).eq(1))return c.arrow(g(0))(f);if(g(1).eq(2)&&g(2).eq(1)&&g(3).eq(1))return c.expansionArrow(g(0))(f);var h=g(0).toNumber(),y=g(1),N=g(2);if(g(3).eq(2)){if(1!=h)return r.POSITIVE_INFINITY.clone();if(y.neq(1))return r.POSITIVE_INFINITY.clone();if(N.neq(1))return r.POSITIVE_INFINITY.clone();if(f.gte(a))return r.POSITIVE_INFINITY.clone();var m=new r(10);return m.layer=f.toNumber(),m.normalize(),m}function w(r,e,t){return 0==r&&e>1?[1/0,e-1,t]:0==r&&1==e&&t>1?[1,1/0,t-1]:[r,e,t]}if(N.gt(a)){var v=new r(N);return v.layer++,v.normalize(),v}function b(r){return isFinite(r)?r.toString():"!"}function O(r,e,t){return"10{".concat(b(r),",").concat(b(e),",").concat(t,"}").concat(a)}var E=c.clone(),I=new r(g(0)),d=function(p,g){void 0===g&&(g=0),console.log("".concat("-".repeat(g)," {").concat(e,",").concat(n,",").concat(o,",").concat(i,",").concat(u,"}"));var h,m=new r(p);if(E.isNaN()||m.isNaN())return r.NaN.clone();if(m.lt(r.ZERO))return r.NaN.clone();if(E.eq(r.ZERO))return m.eq(r.ONE)?r.ZERO.clone():r.NaN.clone();if(E.eq(r.ONE))return r.ONE.clone();if(m.eq(r.ZERO))return r.ONE.clone();if(m.eq(r.ONE))return E.clone();if(I.eq(0))return r.BEAF(E,E,f,y.sub(1),N,l,g+1);if(N.eq(0))return r.BEAF(E,E,E,E,y,new r(l).sub(1),g+1);if(y.gt(a))return(h=new r(y)).setOperator(h.getOperator(1,1/0,N.toNumber())+1,1,1/0,N.toNumber()),h;if(I.gt(r.MSI))return(h=I.clone()).setOperator(h.getOperator(1/0,y.toNumber(),N.toNumber())+1,1/0,y.toNumber(),N.toNumber()),h;var v=I.toNumber();if(m.eq(2))return r.BEAF(E,E,v-1,y,N,l,g+1);if(E.max(m).gt(O(v+1,y.toNumber(),N.toNumber())))return E.max(m);if(E.gt(O(v,y.toNumber(),N.toNumber()))||m.gt(a)){E.gt(O(v,y.toNumber(),N.toNumber()))?((h=E.clone()).setOperator(h.getOperator(v,y.toNumber(),N.toNumber())-1,v,y.toNumber(),N.toNumber()),h.normalize()):h=E.gt(O.apply(void 0,w(v-1,y.toNumber(),N.toNumber())))?new r(E.getOperator.apply(E,w(v-1,y.toNumber(),N.toNumber()))):r.ZERO;var b=h.add(m);return b.setOperator(b.getOperator(v,y.toNumber(),N.toNumber())+1,v,y.toNumber(),N.toNumber()),b.normalize(),b}if(g>=r.maxOps+10)return new r({small:!1,sign:1,layer:0,array:[s(10,0),s(1,v,y.toNumber(),N.toNumber())]});var d=m.toNumber(),x=Math.floor(d),M=I.sub(r.ONE);h=r.BEAF(E,d-x,M.toNumber(),y,N,l,g+1);for(var q=0,T=new r(O.apply(void 0,w(v-1,y.toNumber(),N.toNumber())));0!==x&&h.lt(T)&&q<100;q++)x>0&&(h=r.BEAF(c,h,M.toNumber(),y,N,l,g+1),--x);return 100==q&&(x=0),h.setOperator.apply(h,t([h.getOperator.apply(h,w(v-1,y.toNumber(),N.toNumber()))+x],w(v-1,y.toNumber(),N.toNumber()),!1)),h.normalize(),h}(f,p);return console.log("".concat("-".repeat(p)," = ").concat(d)),d},r.prototype.abs=function(){var r=this.clone();return r.sign<0&&(r.sign*=-1),r},r.abs=function(e){return new r(e).abs()},r.max=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var a=r.NEGATIVE_INFINITY,n=0;n<e.length;n++)a.lt(e[n])&&(a=new r(e[n]).clone());return a},r.min=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var a=r.POSITIVE_INFINITY,n=0;n<e.length;n++)a.gt(e[n])&&(a=new r(e[n]).clone());return a},r.clampMin=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return r.max.apply(r,e)},r.prototype.clampMin=function(){for(var e=[],a=0;a<arguments.length;a++)e[a]=arguments[a];return r.max.apply(r,t([this],e,!1))},r.clampMax=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return r.min.apply(r,e)},r.prototype.clampMax=function(){for(var e=[],a=0;a<arguments.length;a++)e[a]=arguments[a];return r.min.apply(r,t([this],e,!1))},r.prototype.clamp=function(r,e){return this.max(r).min(e)},r.prototype.max=function(){for(var e=[],a=0;a<arguments.length;a++)e[a]=arguments[a];return r.max.apply(r,t([this],e,!1))},r.prototype.min=function(){for(var e=[],a=0;a<arguments.length;a++)e[a]=arguments[a];return r.min.apply(r,t([this],e,!1))},r.prototype.maxabs=function(){for(var e=[],a=0;a<arguments.length;a++)e[a]=arguments[a];var n=e.map((function(e){return new r(e).abs()}));return r.max.apply(r,t([this.abs()],n,!1))},r.prototype.minabs=function(){for(var e=[],a=0;a<arguments.length;a++)e[a]=arguments[a];var n=e.map((function(e){return new r(e).abs()}));return r.min.apply(r,t([this.abs()],n,!1))},r.prototype.cmpabs=function(e){var t=new r(e).abs();return this.abs().cmp(t)},r.prototype.compare=function(e){var t=new r(e);if(this.isNaN()||t.isNaN())return 2;if(this.sign<t.sign)return-1;if(this.sign>t.sign)return 1;var a=-1==this.sign&&-1==t.sign;if(this.small&&!t.small)return-1*(a?-1:1);if(t.small&&!this.small)return 1*(a?-1:1);var n=1;this.small&&t.small&&(n*=-1),a&&(n*=-1);for(var o=0,i=0;this.array.length-1-i>=0&&t.array.length-1-i>=0;i++){var s=this.array[this.array.length-1-i],l=t.array[t.array.length-1-i],p=u([s.megota,s.expans,s.arrow,s.repeat],[l.megota,l.expans,l.arrow,l.repeat]);if(1==p){o=1;break}if(-1==p){o=-1;break}}return o*n+1-1},r.prototype.cmp=function(r){return this.compare(r)},r.prototype.eq=function(r){return 0===this.cmp(r)},r.prototype.neq=function(r){return 0!==this.cmp(r)},r.prototype.lt=function(r){return-1===this.cmp(r)},r.prototype.lte=function(r){return this.cmp(r)<=0},r.prototype.gt=function(r){return 1==this.cmp(r)},r.prototype.gte=function(r){var e=this.cmp(r);return 0==e||1==e},r.prototype.eq_tolerance=function(e,t){void 0===t&&(t=1e-7);var a=new r(e);return this.sub(a).lte(this.max(a).mul(t))},r.prototype.sin=function(){var e=this.clone();if(e.isneg())return e.neg().sin().neg();var t=e.mod(7074237752028440);return r.fromNumber(Math.sin(t.toNumber()))},r.prototype.cos=function(){return this.sub(Math.PI/2).sin()},r.prototype.tan=function(){return this.sin().div(this.cos())},r.prototype.cot=function(){return this.cos().div(this.sin())},r.prototype.sec=function(){return this.cos().rec()},r.prototype.csc=function(){return this.sin().rec()},r.prototype.neg=function(){var r=this.clone();return r.sign*=-1,r.normalize(),r},r.prototype.rec=function(){var r=this.clone();return r.small=!r.small,r},r.prototype.floor=function(){if(this.isInt())return this.clone();if(this.small)return 1==this.sign?r.ZERO.clone():r.ONE.neg().clone();var e=this.abs();return e.array[0].repeat=Math[1==this.sign?"floor":"ceil"](e.getOperator(0)),e},r.prototype.ceil=function(){if(this.isInt())return this.clone();if(this.small)return 1==this.sign?r.ONE.clone():r.ZERO.clone();var e=this.abs();return e.array[0].repeat=Math[1==this.sign?"ceil":"floor"](e.getOperator(0)),e.sign=this.sign,e},r.prototype.round=function(){if(this.isInt())return this.clone();if(this.small)return 1==this.sign?this.rec().lte(2)?r.ONE.clone():r.ZERO.clone():this.abs().rec().lte(2)?r.ZERO.clone():r.ONE.neg().clone();var e=this.abs();return e.array[0].repeat=Math.round(e.array[0].repeat),e.sign=this.sign,e},r.prototype.trunc=function(){var r=this.clone();return r.gte(0)?r.floor():r.ceil()},r.sign=function(e){return new r(e).sign},r.prototype.isNaN=function(){return isNaN(this.getOperator(0))},r.prototype.isZero=function(){return Boolean(this.small&&!isFinite(this.getOperator(0)))},r.prototype.isFinite=function(){return Boolean(this.small||isFinite(this.getOperator(0)))&&!this.isNaN()},r.prototype.isInfi=function(){return this.rec().isZero()},r.prototype.isInfiNaN=function(){return this.isInfi()||this.isNaN()},r.prototype.isInt=function(){return!!this.isZero()||(!(this.small||!Number.isInteger(this.getOperator(0)))||!!this.abs().gte(a/2))},r.prototype.ispos=function(){return this.sign>0},r.prototype.isneg=function(){return this.sign<0},r.isNaN=function(e){return new r(e).isNaN()},r.prototype.normalize=function(){for(var e=!0,t=this,o=0;o<this.array.length;o++)if(this.array[o].repeat==1/0)return this.array=[{arrow:0,expans:1,megota:1,repeat:1/0}],this.layer=0,this;for(var i=1;i<t.array.length;++i){var u=t.array[i];if(null!==u.arrow&&void 0!==u.arrow||(u.arrow=0),null!==u.expans&&void 0!==u.expans||(u.expans=1),null!==u.megota&&void 0!==u.megota||(u.megota=1),isNaN(u.arrow)||isNaN(u.repeat)||isNaN(u.expans)||isNaN(u.megota))return t.array=[s(NaN,0,1,1)],t;if(!isFinite(u.repeat)||!isFinite(u.megota))return t.array=[s(1/0,0,1,1)],t;Number.isInteger(u.arrow)||(u.arrow=Math.floor(u.arrow)),Number.isInteger(u.repeat)||(u.repeat=Math.floor(u.repeat)),Number.isInteger(u.expans)||(u.expans=Math.floor(u.expans)),Number.isInteger(u.megota)||(u.megota=Math.floor(u.megota))}t.array.length||(t.small=!t.small,t.array=[s(1/0)]);do{for(e=!1,this.array.sort(y),i=1;i<t.array.length-1;++i)t.array[i].arrow==t.array[i+1].arrow&&t.array[i].expans==t.array[i+1].expans&&t.array[i].megota==t.array[i+1].megota&&(t.array[i].repeat+=t.array[i+1].repeat,t.array.splice(i+1,1),--i,e=!0);for(i=1;i<t.array.length;++i)0===t.array[i].arrow||0!==t.array[i].repeat&&null!==t.array[i].repeat&&void 0!==t.array[i].repeat?0==t.array[i].arrow&&t.array[i].expans>=2&&(t.array[i].arrow=1/0,t.array[i].valuereplaced=0,t.array[i].expans=t.array[i].expans-1):(t.array.splice(i,1),--i);for(t.array.length>r.maxOps&&t.array.splice(1,t.array.length-r.maxOps),this.array.length>=2&&1==this.array[1].arrow&&this.array[1].repeat>=1&&this.array[0].repeat<n&&(this.setOperator(this.array[1].repeat-1,1),this.setOperator(Math.pow(10,this.array[0].repeat),0),e=!0),this.getOperator(0)>a&&isFinite(this.getOperator(0))&&(this.setOperator(this.getOperator(1)+1,1),this.setOperator(Math.log10(this.getOperator(0)),0),e=!0),this.array[this.array.length-1].megota>a?(this.layer++,this.array=[s(this.array[this.array.length-1].megota)],e=!0):this.layer&&1==this.array.length&&0===this.array[0].arrow&&(this.layer--,this.array=[s(10),s(1,10,10,this.array[0].repeat)],e=!0),1==this.array.length&&this.array[0].repeat<1&&(this.array[0].repeat=1/this.array[0].repeat,this.small=!this.small,e=!0);t.array.length>=2&&1==t.array[0].repeat&&t.array[1].repeat;)t.array[1].repeat>1?t.array[1].repeat--:t.array.splice(1,1),t.array[0].repeat=10,e=!0;t.array.length>=2&&t.array[0].repeat<a&&t.array[1].arrow>=2&&t.array[1].repeat>1&&isFinite(t.array[1].arrow)&&(t.array[1].repeat--,t.array.splice(1,0,s(t.array[0].repeat-1,t.array[1].arrow-1,t.array[1].expans,t.array[1].megota)),t.array[0].repeat=10,e=!0),t.array.length>=2&&t.array[0].repeat<a&&t.array[1].arrow>=2&&1==t.array[1].repeat&&isFinite(t.array[1].arrow)&&(t.array.splice(1,1,s(t.array[0].repeat-1,t.array[1].arrow-1,t.array[1].expans,t.array[1].megota)),t.array[0].repeat=10,e=!0),t.array.length>=2&&t.array[1].repeat>a&&t.array[1].arrow!==1/0&&(t.array[1].arrow++,t.array[0].repeat=t.array[1].repeat,t.array[1].repeat=1,e=!0),t.array.length>=2&&t.array[1].repeat>a&&t.array[1].arrow===1/0&&(t.array[1].arrow=1,t.array[1].expans++,t.array[0].repeat=t.array[1].repeat,t.array[1].repeat=1,e=!0)}while(e);return this},r.prototype.getOperatorIndex=function(r,e,t){void 0===e&&(e=1),void 0===t&&(t=1);for(var a=0;a<this.array.length;a++){var n=u([this.array[a].megota,this.array[a].expans,this.array[a].arrow],[t,e,r]);if(0==n)return a;if(1==n)return a-.5}return this.array.length-.5},r.prototype.getOperator=function(r,e,t){void 0===e&&(e=1),void 0===t&&(t=1);var a=this.getOperatorIndex(r,e,t);return this.array[a]?this.array[a].repeat:0},r.prototype.setOperator=function(r,e,t,a){void 0===t&&(t=1),void 0===a&&(a=1);var n=this.getOperatorIndex(e,t,a);return this.array[n]?(this.array[n].repeat=r,!1):(this.array.splice(Math.ceil(n),0,{arrow:e,expans:t,megota:a,valuereplaced:t===1/0?1:e==1/0?0:-1,repeat:r}),!0)},r.prototype.clone=function(){var e=new r;return e.resetFromObject(this),e},r.prototype.resetFromObject=function(r){this.array=[];for(var e=0;e<r.array.length;e++)this.array[e]={arrow:r.array[e].arrow,expans:r.array[e].expans,megota:r.array[e].megota,repeat:r.array[e].repeat,valuereplaced:r.array[e].valuereplaced};return this.small=r.small,this.sign=r.sign,this.layer=r.layer,this},r.prototype.toNumber=function(){return-1==this.sign?-this.neg().toNumber():this.small?1/this.rec().toNumber():this.array.length>2?1/0:1==this.array.length?this.array[0].repeat:2==this.array.length&&1==this.array[1].arrow&&1==this.array[1].expans&&1==this.array[1].megota&&1==this.array[1].repeat?Math.pow(10,this.getOperator(0)):NaN},r.prototype.toString=function(){if(this.isNaN())return"NaN";if(-1==this.sign)return"-".concat(this.neg().toString());if(this.small)return this.isZero()?"0":"/".concat(this.rec().toString());if(this.isInfi())return"Infinity";var r="";this.layer?this.layer<3?r+="P".repeat(this.layer):r+="P^"+this.layer+" ":r+="";for(var e=this.array.length-1;e>=0;e--){var t=this.array[e],a="10{".concat(t.arrow===1/0?"!":t.arrow).concat(t.expans>1||t.megota>1?",".concat(t.expans===1/0?"!":t.expans):"").concat(t.megota>1?",".concat(t.megota):"","}");a=1==t.arrow&&1==t.expans&&1==t.megota&&t.repeat<5?"e".repeat(t.repeat):0==t.arrow&&1==t.expans&&1==t.megota?t.repeat.toString():t.repeat>1?"(".concat(a,")^").concat(t.repeat," "):"".concat(a),r+="".concat(a)}return r},r.fromNumber=function(e){var t=new r;if(e<0)t.sign=-1;else{if(0==e)return t.sign=0,t.small=!0,t.array=[s(1/0,0)],t;e>0&&(t.sign=1)}var n=Math.abs(e);return n==1/0?t.array=[s(1/0,0)]:n>=11102230246251568e-32&&n<1?(t.small=!0,t.array=[s(1/n,0)]):n<11102230246251568e-32?(t.small=!0,t.array=[s(-Math.log10(n),0),s(1,1)]):n<=a?t.array=[s(n,0)]:(t.setOperator(Math.log10(n),0),t.array=[s(Math.log10(n),0),s(1,1)]),t},r.prototype.toJSON=function(){return"PN"+this.toString()},r.fromString=function(e){var t,o,u,p,c,f,g,h=new r;if(e.startsWith("PN")&&(e=e.substring(2)),!isNaN(Number(e))){var y=Number(e),N=!1;if(0==y?/^((0)|(0*\.0+e\d+)|(0*\.0*))$/.test(e)&&(N=!0):N=!0,!N){var m=e.search(/e/),w=e.substring((-1==m?e.length:m)+1),v=e.substring(0,-1==m?void 0:m),b=[0,0];if(b[1]=Number(w||"0"),Number(v)>=1){var O=v.length>=17?l(v):Math.log10(Number(v)),E=O-(Math.floor(O)-1);b[0]=Math.pow(10,E),b[1]+=E}else{var I=(g=v.match(/^0\.(0*)[1-9]/))?g[1].length:0;v=(v=v.substring(v.search(/[1-9]/))).charAt(0)+"."+v.substring(1),I+=1,b[0]=Number(v),b[1]+=-I}return r.pow(10,-b[1]-1).mul(10*Math.pow(b[0],-1)).rec()}if(isFinite(y)&&N)return h=r.fromNumber(Number(e))}if(e=e.replace(/\(e\^(\d+)\)/g,"(10^)^$1 ").replace(/(\d+)\x20*PT/g,"(10^)^$1 "),!i.test(e))throw"[PowiainaNum 0.2 error]malformed input: "+e;var d=!1,x=!1;if("-"==e[0]||"+"==e[0]){var M=e.search(/[^-\+]/);d=(null!==(o=null===(t=e.substring(0,M).match(/-/g))||void 0===t?void 0:t.length)&&void 0!==o?o:0)%2==1,e=e.substring(M)}if("/"==e[0]){M=e.search(/[^\/]/);x=(null!==(p=null===(u=e.substring(0,M).match(/\//g))||void 0===u?void 0:u.length)&&void 0!==p?p:0)%2==1,e=e.substring(M)}if("NaN"==e)h.array=[s(NaN)];else if("Infinity"==e)h.array=[s(1/0)];else{var q,T,S,_;for(h.sign=1,h.array=[s(0)],"P"==e[0]&&("^"==e[1]?(q=e.substring(2).search(/[^0-9]/)+2,h.layer=Number(e.substring(2,q)),e=e.substring(q+1)):(q=e.search(/[^P]/),h.layer=q,e=e.substring(q)));e&&/^(\(?10[\^\{])/.test(e);){var F,Z,R;if("("==e[0]&&(e=e.substring(1)),"^"==e[2])F=q=e.substring(2).search(/[^\^]/),T=q+2;else{q=e.indexOf("}");var A=e.substring(3,q).split(",");F=Number("!"==A[0]?1/0:A[0]),Z=Number(null!==(c="!"==A[1]?1/0:A[1])&&void 0!==c?c:1),R=Number(null!==(f=A[2])&&void 0!==f?f:1),T=q+1}")"==(e=e.substring(T))[0]?(q=e.indexOf(" "),S=Number(e.substring(2,q)),e=e.substring(q+1)):S=1,1==F&&1==Z&&1==R?h.array.length>=2&&1==h.array[1].arrow?h.array[1].repeat+=S:h.array.splice(1,0,s(S,1,Z,R)):2==F&&1==Z&&1==R?(q=h.array.length>=2&&1==h.array[1].arrow?h.array[1].repeat:0,(T=h.array[0].repeat)>=1e10&&++q,T>=10&&++q,h.array[0].repeat=q,h.array.length>=2&&1==h.array[1].arrow&&h.array.splice(1,1),_=h.getOperatorIndex(2),Number.isInteger(_)?h.array[_].repeat+=S:h.array.splice(Math.ceil(_),0,s(S,2,Z,R))):isFinite(F)?(q=h.getOperator(F-1),(T=h.getOperator(F-2))>=10&&++q,_=h.getOperatorIndex(F),h.array.splice(1,Math.ceil(_)-1),h.array[0].repeat=q,Number.isInteger(_)?h.array[1].repeat+=S:h.array.splice(1,0,s(S,F,Z,R))):h.array.splice(1,0,s(S,F,Z,R))}q=e.split(/[Ee]/),T=[h.array[0].repeat,0],S=1;for(var P=q.length-1;P>=0;--P){T[0]<n&&0===T[1]?T[0]=Math.pow(10,S*T[0]):-1==S?(0===T[1]?T[0]=Math.pow(10,S*T[0]):1==T[1]&&T[0]<=Math.log10(Number.MAX_VALUE)?T[0]=Math.pow(10,S*Math.pow(10,T[0])):T[0]=0,T[1]=0):T[1]++;var V=q[P].indexOf("."),Y=-1==V?q[P].length:V;0===T[1]?Y>=17?(T[0]=Math.log10(T[0])+l(q[P].substring(0,Y)),T[1]=1):q[P]&&(T[0]*=Number(q[P])):(_=Y>=17?l(q[P].substring(0,Y)):q[P]?Math.log10(Number(q[P])):0,1==T[1]?T[0]+=_:2==T[1]&&T[0]<n+Math.log10(_)&&(T[0]+=Math.log10(1+Math.pow(10,Math.log10(_)-T[0])))),T[0]<n&&T[1]?(T[0]=Math.pow(10,T[0]),T[1]--):T[0]>a&&(T[0]=Math.log10(T[0]),T[1]++)}h.array[0].repeat=T[0],T[1]&&(h.array.length>=2&&1==h.array[1].arrow&&1==h.array[1].expans&&1==h.array[1].megota?h.array[1].repeat+=T[1]:h.array.splice(1,0,s(T[1],1,1,1)))}return d&&(h.sign*=-1),x&&(h.small=!h.small),h.normalize(),h.normalize(),h},r.fromObject=function(e){var t=new r;if(t.array=[],function(r){if(!Array.isArray(r))return!1;for(var e=0;e<r.length;e++){var t=r[e];if(!Array.isArray(t))return!1;if(!f(t))return!1;if(!g(t))return!1}return!0}(e)){for(var a=0;a<e.length;a++)t.array[a]={arrow:e[a][0],expans:1,megota:1,repeat:e[a][1]};return t.small=!1,t.sign=1,t.layer=0,t}for(a=0;a<e.array.length;a++)t.array[a]={arrow:e.array[a].arrow,expans:e.array[a].expans,megota:e.array[a].megota,repeat:e.array[a].repeat,valuereplaced:e.array[a].valuereplaced};return t.small=e.small,t.sign=e.sign,t.layer=e.layer,t},Object.defineProperty(r.prototype,"arr01",{get:function(){for(var r=[0],e=0;e<this.array.length;e++)0==e?r[0]=this.array[e].repeat:(r[e]=[0,0,0,0],r[e][0]=this.array[e].arrow==1/0?"x":this.array[e].arrow,r[e][1]=this.array[e].repeat,r[e][2]=this.array[e].expans==1/0?"x":this.array[e].expans,r[e][3]=this.array[e].megota);return r},enumerable:!1,configurable:!0}),p=Symbol.toStringTag,r.ZERO=new r({array:[{arrow:0,expans:1,megota:1,repeat:1/0}],small:!0,layer:0,sign:0}),r.ONE=new r({array:[{arrow:0,expans:1,megota:1,repeat:1}],small:!1,layer:0,sign:1}),r.MSI=new r(a),r.MSI_REC=((N=new r(a)).small=!0,N),r.E_MSI=new r({array:[{arrow:0,expans:1,megota:1,repeat:a},{arrow:1,expans:1,megota:1,repeat:1}],small:!1,layer:0,sign:1}),r.EE_MSI=new r({array:[{arrow:0,expans:1,megota:1,repeat:a},{arrow:1,expans:1,megota:1,repeat:2}],small:!1,layer:0,sign:1}),r.E_MSI_REC=new r({array:[{arrow:0,expans:1,megota:1,repeat:a},{arrow:1,expans:1,megota:1,repeat:1}],small:!0,layer:0,sign:1}),r.TETRATED_MSI=new r({array:[{arrow:0,expans:1,megota:1,repeat:1e10},{arrow:1,expans:1,megota:1,repeat:a-2}],small:!1,layer:0,sign:1}),r.PENTATED_MSI=new r({array:[{arrow:0,expans:1,megota:1,repeat:10},{arrow:2,expans:1,megota:1,repeat:a-1}],small:!1,layer:0,sign:1}),r.TRITRI=new r({small:!1,layer:0,sign:1,array:[s(3638334640023.7783,0,1,1),s(7625587484984,1,1,1)]}),r.GRAHAMS_NUMBER=new r("(10{!})^63 10^^^(10^)^7625597484984 3638334640023.7783"),r.POSITIVE_INFINITY=new r(1/0),r.NEGATIVE_INFINITY=new r(-1/0),r.NaN=new r({array:[{arrow:0,expans:1,megota:1,repeat:NaN}],small:!1,layer:0,sign:0}),r.E=new r(Math.E),r.LN2=new r(Math.LN2),r.LN10=new r(Math.LN10),r.LOG2E=new r(Math.LOG2E),r.LOG10E=new r(Math.LOG10E),r.PI=new r(Math.PI),r.SQRT1_2=new r(Math.SQRT1_2),r.SQRT2=new r(Math.SQRT2),r.maxOps=100,r.POW_2_44_MOD_PI=1.701173079953,r.arrowFuncMap=new Map,r}();r.arraySortFunction=y,r.default=N,r.mergeSameArrays=function(r){for(var e=1;e<r.array.length-1;++e)r.array[e].arrow==r.array[e+1].arrow&&r.array[e].expans==r.array[e+1].expans&&r.array[e].megota==r.array[e+1].megota&&(r.array[e].repeat+=r.array[e+1].repeat,r.array.splice(e+1,1),--e)},Object.defineProperty(r,"__esModule",{value:!0})}));
1
+ !function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self).PowiainaNum={})}(this,(function(r){"use strict";function e(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,a=Array(e);t<e;t++)a[t]=r[t];return a}function t(r,e){for(var t=0;t<e.length;t++){var a=e[t];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(r,n(a.key),a)}}function a(r){return function(r){if(Array.isArray(r))return e(r)}(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||function(r,t){if(r){if("string"==typeof r)return e(r,t);var a={}.toString.call(r).slice(8,-1);return"Object"===a&&r.constructor&&(a=r.constructor.name),"Map"===a||"Set"===a?Array.from(r):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?e(r,t):void 0}}(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(r){var e=function(r,e){if("object"!=typeof r||!r)return r;var t=r[Symbol.toPrimitive];if(void 0!==t){var a=t.call(r,e||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(r)}(r,"string");return"symbol"==typeof e?e:e+""}function i(r){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}var o,u=9007199254740991,l=15.954589770191003,s=1.444667861009766,c=/^(PN)?[\/\-\+]*(Infinity|NaN|(P+|P\^\d+ )?(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})|\(10(\^+|\{([1-9]\d*|!)(,([1-9]\d*|!))?(,[1-9]\d*)?\})\)\^[1-9]\d*\x20*)*((\d+(\.\d*)?|\d*\.\d+)?([Ee][-\+]*))*(0|\d+(\.\d*)?|\d*\.\d+))$/;function f(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1;return{repeat:r,arrow:e,expans:t,megota:a,valuereplaced:e==1/0?0:t==1/0?1:-1}}function g(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];for(var a=0;a<Math.min(e[0].length,e[1].length);a++){var n=e[0][a],i=e[1][a];if(n<i)return-1;if(n>i)return 1}return 0}function h(r){return Math.log10(Number(r.substring(0,17)))+(r.length-17)}var y=.5671432904097838;function p(r){var e,t,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-10,n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!Number.isFinite(r))return r;if(n){if(0===r)return r;if(1===r)return y;e=r<10?0:Math.log(r)-Math.log(Math.log(r))}else{if(0===r)return-1/0;e=r<=-.1?-2:Math.log(-r)-Math.log(-Math.log(-r))}for(var i=0;i<100;++i){if(t=(r*Math.exp(-e)+e*e)/(e+1),Math.abs(t-e)<a*Math.abs(t))return t;e=t}throw Error("Iteration failed to converge: ".concat(r.toString()))}function m(r){return 2==r.length}function N(r){return"number"==typeof r[0]&&"number"==typeof r[1]}function v(r){return"x"===r?1/0:r}function w(r){return 4==r.length}function b(r){return"number"==typeof r[0]&&"number"==typeof r[1]&&"number"==typeof r[2]&&"number"==typeof r[3]}function O(r){return"x"===r[0]&&"number"==typeof r[1]&&"number"==typeof r[2]&&"number"==typeof r[3]}function E(r){return"number"==typeof r[0]&&"number"==typeof r[1]&&"x"==r[2]&&"number"==typeof r[3]}function I(r){var e,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e10,a=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!(r=new M(r)).isFinite())return r;if(a){if(r.eq(M.ZERO))return r;if(r.eq(M.ONE))return new M(y);e=M.log(r)}else{if(r.eq(M.ZERO))return M.NEGATIVE_INFINITY.clone();e=M.log(r.neg())}for(var n=0;n<100;++n){var i=e.neg().exp(),o=e.sub(r.mul(i)),u=e.add(M.ONE).sub(e.add(2).mul(o).div(M.mul(2,e).add(2)));if(u.eq(M.ZERO))return e;var l=e.sub(o.div(u));if(M.abs(l.sub(e)).lt(M.abs(l).mul(t)))return l;e=l}throw Error("Iteration failed to converge: "+r)}function d(r,e){return g([r.megota,r.expans,r.arrow],[e.megota,e.expans,e.arrow])}var x,M=function(){function r(e){if(function(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}(this,r),this[o]="PowiainaNum",this.array=[{arrow:0,expans:1,megota:1,repeat:NaN}],this.small=!1,this.sign=0,this.layer=0,void 0===e);else if("number"==typeof e){var t=r.fromNumber(e);this.resetFromObject(t)}else if("object"==i(e)){var a=r.fromObject(e);this.resetFromObject(a)}else if("string"==typeof e){var n=r.fromString(e);this.resetFromObject(n)}}return function(r,e,a){return e&&t(r.prototype,e),a&&t(r,a),Object.defineProperty(r,"prototype",{writable:!1}),r}(r,[{key:"add",value:function(e){var t,a,n,i,o,s,c=this.clone(),g=new r(e);if(c.eq(r.POSITIVE_INFINITY)&&g.eq(r.NEGATIVE_INFINITY)||c.eq(r.NEGATIVE_INFINITY)&&g.eq(r.POSITIVE_INFINITY))return r.NaN.clone();if(!c.isFinite())return c.clone();if(!g.isFinite())return g.clone();if(c.isZero())return g.clone();if(g.isZero())return c.clone();if(c.sign==-g.sign&&function(){var r=c.abs(),e=g.abs();return r.eq(e)}())return r.ZERO.clone();if(c.abs().lt(u)&&g.abs().lt(u))return r.fromNumber(c.toNumber()+g.toNumber());if(c.abs().lt(r.E_MSI_REC)||c.abs().gt(r.E_MSI)||g.abs().lt(r.E_MSI_REC)||g.abs().gt(r.E_MSI))return c.maxabs(g);if(-1==c.sign)return c.neg().add(g.neg()).neg();c.cmpabs(g)>0?(o=c,s=g):(s=c,o=g);var h=o.toNumber()+s.toNumber();if(isFinite(h)&&0!==h)return r.fromNumber(h);var y=1;if(!(o.small||s.small||(null===(t=o.array[1])||void 0===t?void 0:t.repeat)||(null===(a=s.array[1])||void 0===a?void 0:a.repeat)||o.sign!=s.sign))return new r((o.array[0].repeat+s.array[0].repeat)*o.sign);var p=(o.small?-1:1)*((null===(n=o.array[1])||void 0===n?void 0:n.repeat)?o.array[0].repeat:Math.log10(o.array[0].repeat)),m=(s.small?-1:1)*((null===(i=s.array[1])||void 0===i?void 0:i.repeat)?s.array[0].repeat:Math.log10(s.array[0].repeat));if(p-m>l)return o;var N,v,w=-Math.floor(p),b=0;if((v=o.sign*Math.pow(10,p+w)+s.sign*Math.pow(10,m+w))>0&&(b=Math.log10(v)-w),v<0&&(b=Math.log10(-v)-w,y*=-1),0==v)throw Error("Encounter a calculate error");return(N=new r).sign=1,N.array=b>l||b<-l?[f(b,0),f(1,1)]:[f(Math.pow(10,Math.abs(b)),0)],N.small=b<0,N.sign*=y,N}},{key:"sub",value:function(e){return this.add(new r(e).neg())}},{key:"mul",value:function(e){var t=this.clone(),a=new r(e);if(t.eq(r.POSITIVE_INFINITY)&&a.eq(r.NEGATIVE_INFINITY)||a.eq(r.POSITIVE_INFINITY)&&t.eq(r.NEGATIVE_INFINITY))return r.NEGATIVE_INFINITY.clone();if(t.isInfiNaN()&&a.isZero()||a.isInfiNaN()&&t.isZero())return r.NaN.clone();if(t.eq(r.NEGATIVE_INFINITY)&&a.eq(r.NEGATIVE_INFINITY))return r.POSITIVE_INFINITY.clone();if(!t.isFinite())return t.clone();if(!a.isFinite())return a.clone();if(t.isZero()||a.isZero())return r.ZERO.clone();var n,i=t.toNumber()*a.toNumber();return isFinite(i)&&0!==i?r.fromNumber(i):((n=t.abs().log10().add(a.abs().log10()).pow10()).sign=t.sign*a.sign,n)}},{key:"div",value:function(e){var t=new r(e).rec();return this.mul(t)}},{key:"mod",value:function(e){var t=new r(e),a=this.div(t);return a.sub(a.floor()).mul(t)}},{key:"pow10",value:function(){var e,t,a=this.clone();return this.isFinite()?a.isneg()?(a.sign*=-1,a.pow10().rec()):a.lte(308.25471555991675)?r.fromNumber(Math.pow(10,a.toNumber())):a.small?a.lt(r.MSI_REC)?r.ONE:new r(Math.pow(10,Math.pow(a.array[0].repeat,-1))):(a.gt(r.TETRATED_MSI)||(a.setOperator((null!==(t=null===(e=a.array[1])||void 0===e?void 0:e.repeat)&&void 0!==t?t:0)+1,1),a.normalize()),a):this.clone()}},{key:"pow",value:function(e){var t=new r(e);if(this.eq(1))return r.ONE.clone();if(!t.isFinite())return t.clone();if(!this.isFinite())return this.clone();if(this.eq(10))return t.pow10();if(this.isneg()){if(!t.isInt())return r.NaN.clone();var a=this.abs().pow(t);return a.sign=function(){var r=t.mod(2).round();return r.eq(0)||r.eq(2)?1:-1}(),a}var n=this.toNumber(),i=t.toNumber(),o=Math.pow(n,i);return isFinite(o)&&0!==o?r.fromNumber(o):this.isZero()&&t.isZero()?r.ONE.clone():this.isZero()?r.ZERO.clone():t.isZero()?r.ONE.clone():this.gt(0)?this.log10().mul(t).pow10():t.rec().mod(2).eq(1)?this.neg().log10().mul(t).pow10().neg():r.NaN.clone()}},{key:"pow_base",value:function(e){return new r(e).pow(this)}},{key:"root",value:function(e){var t=new r(e);return this.pow(t.rec())}},{key:"sqrt",value:function(){return this.pow(.5)}},{key:"cbrt",value:function(){return this.abs().root(3).mul(this.sign)}},{key:"log10",value:function(){if(this.isneg())return r.NaN.clone();if(this.isZero())return r.NEGATIVE_INFINITY.clone();if(this.small){var e=this.clone();return e.small=!e.small,e.log10().neg()}if(1==this.array.length)return new r(Math.log10(this.array[0].repeat));if(this.gte(r.TETRATED_MSI))return this.clone();var t=this.clone();return t.array[1].repeat=t.array[1].repeat-1,t.normalize(),t}},{key:"log",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Math.E,t=new r(e);return this.log10().div(t.log10())}},{key:"ln",value:function(){return this.log()}},{key:"pLog10",value:function(){return this.isneg()?r.ZERO:this.log10()}},{key:"exp",value:function(){return this.pow_base(Math.E)}},{key:"factorial",value:function(){return this.abs().lt(u)?this.add(1).gamma():this.abs().lt(r.E_MSI)?r.exp(this.mul(this.log10().sub(1))):r.exp(this)}},{key:"gamma",value:function(){if(this.small)return this.rec();if(this.lte(u)){if(this.lt(24))return r.fromNumber(function(r){if(!isFinite(r))return r;if(r<-50)return r===Math.trunc(r)?Number.NEGATIVE_INFINITY:0;for(var e=1;r<10;)e*=r,++r;var t=.9189385332046727;t+=((r-=1)+.5)*Math.log(r),t-=r;var a=r*r,n=r;return t+=1/(12*n),t-=1/(360*(n*=a)),t+=1/(1260*(n*=a)),t-=1/(1680*(n*=a)),t+=1/(1188*(n*=a)),t-=691/(360360*(n*=a)),t+=7/(1092*(n*=a)),t-=3617/(122400*(n*=a)),Math.exp(t)/e}(this.sign*this.getOperator(0)));var e=this.getOperator(0)-1,t=.9189385332046727;t+=(e+.5)*Math.log(e);var a=e*e,n=e,i=12*n,o=1/i,l=(t-=e)+o;if(l===t)return r.exp(t);if((l=(t=l)-(o=1/(i=360*(n*=a))))===t)return r.exp(t);t=l;var s=1/(i=1260*(n*=a));return t+=s,t-=s=1/(i=1680*(n*=a)),r.exp(t)}return this.gt(u)?r.exp(this.mul(this.log().sub(1))):r.exp(this)}},{key:"lambertw",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this.lt(-.3678794411710499)?r.NaN.clone():e?this.abs().lt("1e-300")?new r(this):this.small?r.fromNumber(p(this.toNumber())):this.lt(u)?r.fromNumber(p(this.sign*this.getOperator(0))):this.lt("eee15")?I(this):this.log():1===this.sign?r.NaN.clone():0===this.layer?r.fromNumber(p(this.sign*this.array[0].repeat,1e-10,!1)):1==this.layer?I(this,1e-10,!1):this.neg().rec().lambertw().neg()}},{key:"tetrate",value:function(e){var t,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=this.clone(),i=new r(e),o=new r(a);if(n.isNaN()||i.isNaN()||o.isNaN())return r.NaN.clone();if(n.eq(1))return r.ONE.clone();if(o.neq(r.ONE)&&(i=i.add(o.slog(n))),i.isInfi()&&i.sign>0)return n.gte(s)?r.POSITIVE_INFINITY.clone():(t=this.log().neg()).lambertw().div(t);if(i.lte(-2))return r.NaN.clone();if(n.isZero())return i.isZero()?r.NaN.clone():i.gte(u/2)||i.toNumber()%2==0?r.ZERO.clone():r.ONE.clone();if(n.eq(r.ONE))return i.eq(r.ONE.neg())?r.NaN.clone():r.ONE.clone();if(i.eq(r.ONE.neg()))return r.ZERO.clone();if(i.eq(r.ZERO))return r.ONE.clone();if(i.eq(r.ONE))return n;if(i.eq(2))return n.pow(n);if(n.eq(2)){if(i.eq(3))return r.fromNumber(16);if(i.eq(4))return r.fromNumber(65536)}var l=n.max(i);if(l.gt(r.PENTATED_MSI))return l;if(l.gt(r.TETRATED_MSI)||i.gt(u)){if(this.lt(s))return(t=n.ln().neg()).lambertw().div(t);var c=n.slog(10).add(i);return c.setOperator(c.getOperator(2)+1,2),c.normalize(),c}for(var f=i.toNumber(),g=Math.floor(f),h=n.pow(f-g),y=r.NaN,p=0,m=r.E_MSI.clone();0!==g&&h.lt(m)&&p<100;++p)if(g>0){if(h=n.pow(h),y.eq(h)){g=0;break}y=h,--g}else{if(h=h.log(n),y.eq(h)){g=0;break}y=h,++g}return(100==p||this.lt(s))&&(g=0),h.setOperator(h.getOperator(1)+g,1),h.normalize(),h}},{key:"slog",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10,t=this.clone(),a=new r(e);if(t.isInfiNaN())return t;if(a.isNaN())return a;if(a.isInfi())return r.ZERO.clone();if(t.isZero())return r.ONE.clone();if(t.eq(r.ONE))return r.ZERO.clone();if(t.eq(a))return r.ONE.clone();if(a.lt(s)){var n=a.tetrate(1/0);if(t.eq(n))return r.POSITIVE_INFINITY.clone();if(t.gt(n))return r.NaN.clone()}if(t.max(a).gt(r.PENTATED_MSI))return t.gt(a)?t:r.ZERO.clone();if(t.max(a).gt(r.TETRATED_MSI)&&t.gt(a))return t.setOperator(t.getOperator(2)-1,2),t.normalize(),t.sub(t.getOperator(1));if(t.lt(r.ZERO.clone()))return a.pow(t).sub(2);var i=0,o=t.getOperator(1)-a.getOperator(1);if(o>3){var u=o-3;i+=u,t.setOperator(t.getOperator(1)-u,1)}for(var l=0;l<100;++l)if(t.lt(r.ZERO))t=r.pow(e,t),--i;else{if(t.lte(1))return new r(i+t.toNumber()-1);++i,t=r.log(t,e)}return t.gt(10)?new r(i):r.NaN.clone()}},{key:"ssqrt",value:function(){var e=this.clone();if(e.lt(1/s))return r.NaN.clone();if(!e.isFinite())return e;if(e.gt(r.TETRATED_MSI))return e;if(e.gt(r.EE_MSI))return e.setOperator(e.getOperator(1)-1,1),e;var t=e.ln();return t.div(t.lambertw())}},{key:"iteratedlog",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10,a=this.clone(),n=new r(t),i=new r(e);return i.isZero()?a:i.eq(r.ONE)?a.log(n):n.tetrate(a.slog(n).sub(i))}},{key:"arrow",value:function(e){var t=this.clone(),a=new r(e);return!a.isInt()||a.lt(r.ZERO)?(console.warn("The arrow is <0 or not a integer, the returned function will return NaN."),function(){return r.NaN.clone()}):a.eq(0)?function(r){return t.mul(r)}:a.eq(1)?function(r){return t.pow(r)}:a.eq(2)?function(r){return t.tetrate(r)}:function(e,n){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,o=new r(e),l=new r(n),s=r.arrowFuncMap.get("".concat(t.toString()," ").concat(a.toString()," ").concat(o.toString()," ").concat(i));if(s)return s.clone();var c=function(){var e;if(t.isNaN()||o.isNaN()||l.isNaN())return r.NaN.clone();if(o.lt(r.ZERO))return r.NaN.clone();if(t.eq(r.ZERO))return o.eq(r.ONE)?r.ZERO.clone():r.NaN.clone();if(l.neq(r.ONE)&&(o=o.add(l.anyarrow_log(a)(t))),t.eq(r.ONE))return r.ONE.clone();if(o.eq(r.ZERO))return r.ONE.clone();if(o.eq(r.ONE))return t.clone();if(a.gt(r.MSI))return(e=a.clone()).setOperator(e.getOperator(1/0)+1,1/0),e;var n=a.toNumber();if(o.eq(2))return t.arrow(n-1)(t,l,i+1);if(t.max(o).gt(r.arrowMSI(n+1)))return t.max(o);if(t.gt(r.arrowMSI(n))||o.gt(u)){t.gt(r.arrowMSI(n))?((e=t.clone()).setOperator(e.getOperator(n)-1,n),e.normalize()):e=t.gt(r.arrowMSI(n-1))?new r(t.getOperator(n-1)):r.ZERO;var s=e.add(o);return s.setOperator(s.getOperator(n)+1,n),s.normalize(),s}if(i>=r.maxOps+10)return new r({small:!1,sign:1,layer:0,array:[f(10,0),f(1,n)]});var c=o.toNumber(),g=Math.floor(c),h=a.sub(r.ONE);e=t.arrow(h)(c-g,l,i+1);for(var y=0,p=r.arrowMSI(n-1);0!==g&&e.lt(p)&&y<100;y++)g>0&&(e=t.arrow(h)(e,l,i+1),--g);return 100==y&&(g=0),e.setOperator(e.getOperator(n-1)+g,n-1),e.normalize(),e}();return i<r.maxOps+10&&r.arrowFuncMap.set("".concat(t.toString()," ").concat(a.toString()," ").concat(o.toString()," ").concat(i),c.clone()),c}}},{key:"anyarrow_log",value:function(e){var t=this.clone(),a=new r(e),n=a.toNumber();if(a.gt(u))throw new Error("[PowiainaNum 0.2 error]Not implemented");return!a.isInt()||a.lt(0)?function(){return r.NaN.clone()}:a.eq(0)?function(r){return t.div(r)}:a.eq(1)?function(r){return t.log(r)}:a.eq(2)?function(r){return t.slog(r)}:t.isInfiNaN()?function(){return t}:function(e){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=new r(e);if(i.isNaN())return i;if(i.isInfi())return r.ZERO.clone();if(t.isZero())return r.ONE.clone();if(t.eq(r.ONE))return r.ZERO.clone();if(t.eq(i))return r.ONE.clone();if(t.max(i).gt(r.arrowMSI(n+1)))return t.gt(i)?t:r.ZERO.clone();if(t.max(i).gt(r.arrowMSI(n))&&t.gt(i))return t.setOperator(t.getOperator(n)-1,n),t.normalize(),t.sub(t.getOperator(n-1));if(t.lt(r.ZERO.clone()))return r.NaN.clone();var o=0,u=t.getOperator(n)-i.getOperator(n);if(u>3){var l=u-3;o+=l,t.setOperator(t.getOperator(n)-l,n)}for(var s=0;s<100;++s)if(t.lt(r.ZERO))t=t.arrow(n-1)(e),--o;else{if(t.lte(1))return new r(o+t.toNumber()-1);++o,t=t.anyarrow_log(n-1)(e,a+1)}return t.gt(10)?new r(o):r.NaN.clone()}}},{key:"arrow_height_inverse",value:function(r){return this.anyarrow_log(r)}},{key:"chain",value:function(r,e){return this.arrow(e)(r)}},{key:"pentate",value:function(r){return this.arrow(3)(r)}},{key:"hexate",value:function(r){return this.arrow(4)(r)}},{key:"penta_log",value:function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10;return this.anyarrow_log(3)(r)}},{key:"expansion",value:function(e){var t,a=new r(e),n=this.clone();if(a.lt(r.ZERO)||!a.isInt())return r.NaN.clone();if(a.eq(r.ONE))return this.clone();if(this.eq(r.ONE))return r.ONE.clone();if(!this.isInt())return r.NaN.clone();if(this.eq(2))return new r(4);if(a.eq(0))return r.ONE.clone();if(n.gt("10{1,2}".concat(u))||a.gt(u)){n.gt("10{1,2}".concat(u))?((t=n.clone()).setOperator(t.getOperator(1,2)-1,1,2),t.normalize()):t=n.gt("10{".concat(u,"}10"))?new r(n.getOperator(1/0)):r.ZERO;var i=t.add(a);return i.setOperator(i.getOperator(1,2)+1,1,2),i.normalize(),i}var o,l=a.toNumber()-1;for(t=n.clone(),o=0;0!==l&&t.lt(u)&&o<100;++o)l>0&&(t=n.arrow(t)(n),--l);return 100==o&&(l=0),t.setOperator(t.getOperator(1/0)+l,1/0),t.normalize(),t}},{key:"expansionArrow",value:function(e){var t=new r(e),a=this.clone();if(t.lt(0)||!t.isInt()||t.isNaN()||this.isNaN())return function(){return r.NaN.clone()};if(t.eq(0))return function(r){return a.arrow(r)(a)};if(t.eq(1))return function(r){return a.expansion(r)};var n=t;return function(e){var t,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=new r(e);if(a.isNaN()||o.isNaN())return r.NaN.clone();if(o.lt(r.ZERO))return r.NaN.clone();if(a.eq(r.ZERO))return o.eq(r.ONE)?r.ZERO.clone():r.NaN.clone();if(a.eq(r.ONE))return r.ONE.clone();if(o.eq(r.ZERO))return r.ONE.clone();if(o.eq(r.ONE))return a.clone();if(n.gt(r.MSI))return(t=n.clone()).setOperator(t.getOperator(1/0,2)+1,1/0,2),t;var l=n.toNumber();if(o.eq(2))return a.expansionArrow(l-1)(a,i+1);if(a.max(o).gt("10{".concat(l+1,",2}").concat(u)))return a.max(o);if(a.gt("10{".concat(l,",2}").concat(u))||o.gt(u)){a.gt("10{".concat(l,",2}").concat(u))?((t=a.clone()).setOperator(t.getOperator(l,2)-1,l,2),t.normalize()):t=a.gt("10{".concat(l-1,",2}").concat(u))?new r(a.getOperator(l-1,2)):r.ZERO;var s=t.add(o);return s.setOperator(s.getOperator(l,2)+1,l,2),s.normalize(),s}if(i>=r.maxOps+10)return new r({small:!1,sign:1,layer:0,array:[f(10,0),f(1,l,2)]});var c=o.toNumber(),g=Math.floor(c),h=n.sub(r.ONE);t=a.expansionArrow(h)(c-g,i+1);for(var y=0,p=new r("10{".concat(l-1,",2}").concat(u));0!==g&&t.lt(p)&&y<100;y++)g>0&&(t=a.expansionArrow(h)(t,i+1),--g);return 100==y&&(g=0),t.setOperator(t.getOperator(l-1,2)+g,l-1,2),t.normalize(),t}}},{key:"multiExpansion",value:function(r){return this.expansionArrow(2)(r)}},{key:"powerExpansion",value:function(r){return this.expansionArrow(3)(r)}},{key:"explosion",value:function(e){return r.BEAF(this,e,1,3)}},{key:"megotion",value:function(e){return r.BEAF(this,e,1,1,2)}},{key:"powiaination",value:function(e){return r.BEAF(this,e,1,1,1,2)}},{key:"abs",value:function(){var r=this.clone();return r.sign<0&&(r.sign*=-1),r}},{key:"clampMin",value:function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];return r.max.apply(r,[this].concat(t))}},{key:"clampMax",value:function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];return r.min.apply(r,[this].concat(t))}},{key:"clamp",value:function(r,e){return this.max(r).min(e)}},{key:"max",value:function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];return r.max.apply(r,[this].concat(t))}},{key:"min",value:function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];return r.min.apply(r,[this].concat(t))}},{key:"maxabs",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var i=t.map((function(e){return new r(e).abs()}));return r.max.apply(r,[this.abs()].concat(a(i)))}},{key:"minabs",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var i=t.map((function(e){return new r(e).abs()}));return r.min.apply(r,[this.abs()].concat(a(i)))}},{key:"cmpabs",value:function(e){var t=new r(e).abs();return this.abs().cmp(t)}},{key:"compare",value:function(e){var t=new r(e);if(this.isNaN()||t.isNaN())return 2;if(this.sign<t.sign)return-1;if(this.sign>t.sign)return 1;var a=-1==this.sign&&-1==t.sign;if(this.small&&!t.small)return-1*(a?-1:1);if(t.small&&!this.small)return 1*(a?-1:1);var n=1;this.small&&t.small&&(n*=-1),a&&(n*=-1);for(var i=0,o=0;this.array.length-1-o>=0&&t.array.length-1-o>=0;o++){var u=this.array[this.array.length-1-o],l=t.array[t.array.length-1-o],s=g([u.megota,u.expans,u.arrow,u.repeat],[l.megota,l.expans,l.arrow,l.repeat]);if(1==s){i=1;break}if(-1==s){i=-1;break}}return i*n+1-1}},{key:"cmp",value:function(r){return this.compare(r)}},{key:"eq",value:function(r){return 0===this.cmp(r)}},{key:"neq",value:function(r){return 0!==this.cmp(r)}},{key:"lt",value:function(r){return-1===this.cmp(r)}},{key:"lte",value:function(r){return this.cmp(r)<=0}},{key:"gt",value:function(r){return 1==this.cmp(r)}},{key:"gte",value:function(r){var e=this.cmp(r);return 0==e||1==e}},{key:"eq_tolerance",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-7,a=new r(e);return this.sub(a).lte(this.max(a).mul(t))}},{key:"sin",value:function(){var e=this.clone();if(e.isneg())return e.neg().sin().neg();var t=e.mod(7074237752028440);return r.fromNumber(Math.sin(t.toNumber()))}},{key:"cos",value:function(){return this.sub(Math.PI/2).sin()}},{key:"tan",value:function(){return this.sin().div(this.cos())}},{key:"cot",value:function(){return this.cos().div(this.sin())}},{key:"sec",value:function(){return this.cos().rec()}},{key:"csc",value:function(){return this.sin().rec()}},{key:"neg",value:function(){var r=this.clone();return r.sign*=-1,r.normalize(),r}},{key:"rec",value:function(){var r=this.clone();return r.small=!r.small,r}},{key:"floor",value:function(){if(this.isInt())return this.clone();if(this.small)return 1==this.sign?r.ZERO.clone():r.ONE.neg().clone();var e=this.abs();return e.array[0].repeat=Math[1==this.sign?"floor":"ceil"](e.getOperator(0)),e}},{key:"ceil",value:function(){if(this.isInt())return this.clone();if(this.small)return 1==this.sign?r.ONE.clone():r.ZERO.clone();var e=this.abs();return e.array[0].repeat=Math[1==this.sign?"ceil":"floor"](e.getOperator(0)),e.sign=this.sign,e}},{key:"round",value:function(){if(this.isInt())return this.clone();if(this.small)return 1==this.sign?this.rec().lte(2)?r.ONE.clone():r.ZERO.clone():this.abs().rec().lte(2)?r.ZERO.clone():r.ONE.neg().clone();var e=this.abs();return e.array[0].repeat=Math.round(e.array[0].repeat),e.sign=this.sign,e}},{key:"trunc",value:function(){var r=this.clone();return r.gte(0)?r.floor():r.ceil()}},{key:"isNaN",value:function(r){function e(){return r.apply(this,arguments)}return e.toString=function(){return r.toString()},e}((function(){return isNaN(this.getOperator(0))}))},{key:"isZero",value:function(){return Boolean(this.small&&!isFinite(this.getOperator(0)))}},{key:"isFinite",value:function(r){function e(){return r.apply(this,arguments)}return e.toString=function(){return r.toString()},e}((function(){return Boolean(this.small||isFinite(this.getOperator(0)))&&!this.isNaN()}))},{key:"isInfi",value:function(){return this.rec().isZero()}},{key:"isInfiNaN",value:function(){return this.isInfi()||this.isNaN()}},{key:"isInt",value:function(){return!!this.isZero()||(!(this.small||!Number.isInteger(this.getOperator(0)))||!!this.abs().gte(u/2))}},{key:"ispos",value:function(){return this.sign>0}},{key:"isneg",value:function(){return this.sign<0}},{key:"normalize",value:function(){for(var e=!0,t=this,a=0;a<this.array.length;a++)if(this.array[a].repeat==1/0)return this.array=[{arrow:0,expans:1,megota:1,repeat:1/0}],this.layer=0,this;for(var n=1;n<t.array.length;++n){var i=t.array[n];if(null!==i.arrow&&void 0!==i.arrow||(i.arrow=0),null!==i.expans&&void 0!==i.expans||(i.expans=1),null!==i.megota&&void 0!==i.megota||(i.megota=1),isNaN(i.arrow)||isNaN(i.repeat)||isNaN(i.expans)||isNaN(i.megota))return t.array=[f(NaN,0,1,1)],t;if(!isFinite(i.repeat)||!isFinite(i.megota))return t.array=[f(1/0,0,1,1)],t;Number.isInteger(i.arrow)||(i.arrow=Math.floor(i.arrow)),Number.isInteger(i.repeat)||(i.repeat=Math.floor(i.repeat)),Number.isInteger(i.expans)||(i.expans=Math.floor(i.expans)),Number.isInteger(i.megota)||(i.megota=Math.floor(i.megota))}t.array.length||(t.small=!t.small,t.array=[f(1/0)]);do{for(e=!1,this.array.sort(d),n=1;n<t.array.length-1;++n)t.array[n].arrow==t.array[n+1].arrow&&t.array[n].expans==t.array[n+1].expans&&t.array[n].megota==t.array[n+1].megota&&(t.array[n].repeat+=t.array[n+1].repeat,t.array.splice(n+1,1),--n,e=!0);for(n=1;n<t.array.length;++n)0===t.array[n].arrow||0!==t.array[n].repeat&&null!==t.array[n].repeat&&void 0!==t.array[n].repeat?0==t.array[n].arrow&&t.array[n].expans>=2&&(t.array[n].arrow=1/0,t.array[n].valuereplaced=0,t.array[n].expans=t.array[n].expans-1):(t.array.splice(n,1),--n);for(t.array.length>r.maxOps&&t.array.splice(1,t.array.length-r.maxOps),this.array.length>=2&&1==this.array[1].arrow&&this.array[1].repeat>=1&&this.array[0].repeat<l&&(this.setOperator(this.array[1].repeat-1,1),this.setOperator(Math.pow(10,this.array[0].repeat),0),e=!0),this.getOperator(0)>u&&isFinite(this.getOperator(0))&&(this.setOperator(this.getOperator(1)+1,1),this.setOperator(Math.log10(this.getOperator(0)),0),e=!0),this.array[this.array.length-1].megota>u?(this.layer++,this.array=[f(this.array[this.array.length-1].megota)],e=!0):this.layer&&1==this.array.length&&0===this.array[0].arrow&&(this.layer--,this.array=[f(10),f(1,10,10,this.array[0].repeat)],e=!0),1==this.array.length&&this.array[0].repeat<1&&(this.array[0].repeat=1/this.array[0].repeat,this.small=!this.small,e=!0),this.array.length>=2&&this.array[1].arrow>=u&&(this.array[0].repeat=this.array[1].arrow,this.array[1]=f(1,1/0,this.array[1].expans,this.array[1].megota));t.array.length>=2&&1==t.array[0].repeat&&t.array[1].repeat;)t.array[1].repeat>1?t.array[1].repeat--:t.array.splice(1,1),t.array[0].repeat=10,e=!0;t.array.length>=2&&t.array.length<r.maxOps&&t.array[0].repeat<u&&t.array[1].arrow>=2&&t.array[1].repeat>1&&isFinite(t.array[1].arrow)&&(t.array[1].repeat--,t.array.splice(1,0,f(t.array[0].repeat-1,t.array[1].arrow-1,t.array[1].expans,t.array[1].megota)),t.array[0].repeat=10,e=!0),t.array.length>=2&&t.array[0].repeat<u&&t.array[1].arrow>=2&&1==t.array[1].repeat&&isFinite(t.array[1].arrow)&&(t.array.splice(1,1,f(t.array[0].repeat-1,t.array[1].arrow-1,t.array[1].expans,t.array[1].megota)),t.array[0].repeat=10,e=!0),t.array.length>=2&&t.array[1].repeat>u&&t.array[1].arrow!==1/0&&(t.array[1].arrow++,t.array[0].repeat=t.array[1].repeat,t.array[1].repeat=1,e=!0),t.array.length>=2&&t.array[1].repeat>u&&t.array[1].arrow===1/0&&(t.array[1].arrow=1,t.array[1].expans++,t.array[0].repeat=t.array[1].repeat,t.array[1].repeat=1,e=!0)}while(e);return this}},{key:"getOperatorIndex",value:function(r){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,a=0;a<this.array.length;a++){var n=g([this.array[a].megota,this.array[a].expans,this.array[a].arrow],[t,e,r]);if(0==n)return a;if(1==n)return a-.5}return this.array.length-.5}},{key:"getOperator",value:function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,a=this.getOperatorIndex(r,e,t);return this.array[a]?this.array[a].repeat:0}},{key:"setOperator",value:function(r,e){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,n=this.getOperatorIndex(e,t,a);return this.array[n]?(this.array[n].repeat=r,!1):(this.array.splice(Math.ceil(n),0,{arrow:e,expans:t,megota:a,valuereplaced:t===1/0?1:e==1/0?0:-1,repeat:r}),!0)}},{key:"clone",value:function(){var e=new r;return e.resetFromObject(this),e}},{key:"resetFromObject",value:function(r){this.array=[];for(var e=0;e<r.array.length;e++)this.array[e]={arrow:r.array[e].arrow,expans:r.array[e].expans,megota:r.array[e].megota,repeat:r.array[e].repeat,valuereplaced:r.array[e].valuereplaced};return this.small=r.small,this.sign=r.sign,this.layer=r.layer,this}},{key:"toNumber",value:function(){return-1==this.sign?-this.neg().toNumber():this.small?1/this.rec().toNumber():this.array.length>2?1/0:1==this.array.length?this.array[0].repeat:2==this.array.length&&1==this.array[1].arrow&&1==this.array[1].expans&&1==this.array[1].megota&&1==this.array[1].repeat?Math.pow(10,this.getOperator(0)):NaN}},{key:"toString",value:function(){if(this.isNaN())return"NaN";if(-1==this.sign)return"-".concat(this.neg().toString());if(this.small)return this.isZero()?"0":"/".concat(this.rec().toString());if(this.isInfi())return"Infinity";var r="";this.layer?this.layer<3?r+="P".repeat(this.layer):r+="P^"+this.layer+" ":r+="";for(var e=this.array.length-1;e>=0;e--){var t=this.array[e],a="10{".concat(t.arrow===1/0?"!":t.arrow).concat(t.expans>1||t.megota>1?",".concat(t.expans===1/0?"!":t.expans):"").concat(t.megota>1?",".concat(t.megota):"","}");a=1==t.arrow&&1==t.expans&&1==t.megota&&t.repeat<5?"e".repeat(t.repeat):0==t.arrow&&1==t.expans&&1==t.megota?t.repeat.toString():t.repeat>1?"(".concat(a,")^").concat(t.repeat," "):"".concat(a),r+="".concat(a)}return r}},{key:"toJSON",value:function(){return"PN"+this.toString()}},{key:"arr01",get:function(){for(var r=[0],e=0;e<this.array.length;e++)0==e?r[0]=this.array[e].repeat:(r[e]=[0,0,0,0],r[e][0]=this.array[e].arrow==1/0?"x":this.array[e].arrow,r[e][1]=this.array[e].repeat,r[e][2]=this.array[e].expans==1/0?"x":this.array[e].expans,r[e][3]=this.array[e].megota);return r}}],[{key:"add",value:function(e,t){return new r(e).add(t)}},{key:"sub",value:function(e,t){return new r(e).sub(t)}},{key:"mul",value:function(e,t){return new r(e).mul(t)}},{key:"div",value:function(e,t){return new r(e).div(t)}},{key:"pow",value:function(e,t){return new r(e).pow(t)}},{key:"root",value:function(e,t){return new r(e).root(t)}},{key:"sqrt",value:function(e){return new r(e).sqrt()}},{key:"cbrt",value:function(e){return new r(e).cbrt()}},{key:"log10",value:function(e){return new r(e).log10()}},{key:"log",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Math.E;return new r(e).log(t)}},{key:"pLog10",value:function(e){return new r(e).pLog10()}},{key:"exp",value:function(e){return new r(e).pow_base(Math.E)}},{key:"factorial",value:function(e){return new r(e).factorial()}},{key:"gamma",value:function(e){return new r(e).gamma()}},{key:"lambertw",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return new r(e).lambertw(t)}},{key:"tetrate",value:function(e,t){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;return new r(e).tetrate(t,a)}},{key:"tetrate_10",value:function(e){return r.fromNumber(10).tetrate(e)}},{key:"arrowMSI",value:function(e){return new r("10{".concat(e,"}").concat(u))}},{key:"hyper",value:function(e){var t=new r(e);return t.eq(0)?function(e,t){return new r(t).eq(0)?new r(e):new r(e).add(1)}:t.eq(1)?r.add:t.eq(2)?r.mul:t.eq(3)?r.pow:function(e,a){return new r(e).arrow(t.sub(2))(a)}}},{key:"expansion",value:function(e,t){return new r(e).expansion(t)}},{key:"multiExpansion",value:function(e,t){return new r(e).multiExpansion(t)}},{key:"powerExpansion",value:function(e,t){return new r(e).powerExpansion(t)}},{key:"BEAF",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1,l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:1,s=arguments.length>6&&void 0!==arguments[6]?arguments[6]:0,c=new r(e),g=new r(t);function h(e){var t;return new r(null!==(t=[n,i,o,l][e])&&void 0!==t?t:1)}if(c.eq(1))return new r(1);if(g.eq(1))return new r(c);if(g.isZero())return new r(1);if(c.lt(0))return r.NaN.clone();if(new r(l).gte(3))return r.POSITIVE_INFINITY.clone();if(h(0).eq(1)&&h(1).eq(1)&&h(2).eq(1))return c.pow(g);if(h(0).eq(2)&&h(1).eq(1)&&h(2).eq(1)&&h(3).eq(1))return c.tetrate(g);if(h(1).eq(1)&&h(2).eq(1)&&h(3).eq(1))return c.arrow(h(0))(g);if(h(1).eq(2)&&h(2).eq(1)&&h(3).eq(1))return c.expansionArrow(h(0))(g);var y=h(0).toNumber(),p=h(1),m=h(2),N=h(3);if(N.eq(2)){if(1!=y)return r.POSITIVE_INFINITY.clone();if(p.neq(1))return r.POSITIVE_INFINITY.clone();if(m.neq(1))return r.POSITIVE_INFINITY.clone();if(g.gte(u))return r.POSITIVE_INFINITY.clone();var v=new r(10);return v.layer=g.toNumber(),v.normalize(),v}function w(r,e,t){return 0==r&&e>1?[1/0,e-1,t]:0==r&&1==e&&t>1?[1,1/0,t-1]:[r,e,t]}if(m.gt(u)){var b=new r(m);return b.layer++,b.normalize(),b}function O(r){return isFinite(r)?r.toString():"!"}function E(r,e,t){return"10{".concat(O(r),",").concat(O(e),",").concat(t,"}").concat(u)}var I=c.clone(),d=new r(h(0)),x=function(s){var h,y,N=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;console.log("".concat("-".repeat(N)," {").concat(e,",").concat(t,",").concat(n,",").concat(i,",").concat(o,"}"));var v,b=new r(s);if(I.isNaN()||b.isNaN())return r.NaN.clone();if(b.lt(r.ZERO))return r.NaN.clone();if(I.eq(r.ZERO))return b.eq(r.ONE)?r.ZERO.clone():r.NaN.clone();if(I.eq(r.ONE))return r.ONE.clone();if(b.eq(r.ZERO))return r.ONE.clone();if(b.eq(r.ONE))return I.clone();if(d.eq(0))return r.BEAF(I,I,g,p.sub(1),m,l,N+1);if(m.eq(0))return r.BEAF(I,I,I,I,p,new r(l).sub(1),N+1);if(p.gt(u))return(v=new r(p)).setOperator(v.getOperator(1,1/0,m.toNumber())+1,1,1/0,m.toNumber()),v;if(d.gt(r.MSI))return(v=d.clone()).setOperator(v.getOperator(1/0,p.toNumber(),m.toNumber())+1,1/0,p.toNumber(),m.toNumber()),v;var O=d.toNumber();if(b.eq(2))return r.BEAF(I,I,O-1,p,m,l,N+1);if(I.max(b).gt(E(O+1,p.toNumber(),m.toNumber())))return I.max(b);if(I.gt(E(O,p.toNumber(),m.toNumber()))||b.gt(u)){I.gt(E(O,p.toNumber(),m.toNumber()))?((v=I.clone()).setOperator(v.getOperator(O,p.toNumber(),m.toNumber())-1,O,p.toNumber(),m.toNumber()),v.normalize()):v=I.gt(E.apply(void 0,a(w(O-1,p.toNumber(),m.toNumber()))))?new r(I.getOperator.apply(I,a(w(O-1,p.toNumber(),m.toNumber())))):r.ZERO;var x=v.add(b);return x.setOperator(x.getOperator(O,p.toNumber(),m.toNumber())+1,O,p.toNumber(),m.toNumber()),x.normalize(),x}if(N>=r.maxOps+10)return new r({small:!1,sign:1,layer:0,array:[f(10,0),f(1,O,p.toNumber(),m.toNumber())]});var M=b.toNumber(),k=Math.floor(M),q=d.sub(r.ONE);v=r.BEAF(I,M-k,q.toNumber(),p,m,l,N+1);for(var T=0,S=new r(E.apply(void 0,a(w(O-1,p.toNumber(),m.toNumber()))));0!==k&&v.lt(S)&&T<100;T++)k>0&&(v=r.BEAF(c,v,q.toNumber(),p,m,l,N+1),--k);return 100==T&&(k=0),(h=v).setOperator.apply(h,[(y=v).getOperator.apply(y,a(w(O-1,p.toNumber(),m.toNumber())))+k].concat(a(w(O-1,p.toNumber(),m.toNumber())))),v.normalize(),v}(g,s);return console.log("".concat("-".repeat(s)," = ").concat(x)),x}},{key:"abs",value:function(e){return new r(e).abs()}},{key:"max",value:function(){for(var e=r.NEGATIVE_INFINITY,t=arguments.length,a=new Array(t),n=0;n<t;n++)a[n]=arguments[n];for(var i=0;i<a.length;i++)e.lt(a[i])&&(e=new r(a[i]).clone());return e}},{key:"min",value:function(){for(var e=r.POSITIVE_INFINITY,t=arguments.length,a=new Array(t),n=0;n<t;n++)a[n]=arguments[n];for(var i=0;i<a.length;i++)e.gt(a[i])&&(e=new r(a[i]).clone());return e}},{key:"clampMin",value:function(){return r.max.apply(r,arguments)}},{key:"clampMax",value:function(){return r.min.apply(r,arguments)}},{key:"sign",value:function(e){return new r(e).sign}},{key:"isNaN",value:function(e){return new r(e).isNaN()}},{key:"fromNumber",value:function(e){var t=new r;if(e<0)t.sign=-1;else{if(0==e)return t.sign=0,t.small=!0,t.array=[f(1/0,0)],t;e>0&&(t.sign=1)}var a=Math.abs(e);return a==1/0?t.array=[f(1/0,0)]:a>=11102230246251568e-32&&a<1?(t.small=!0,t.array=[f(1/a,0)]):a<11102230246251568e-32?(t.small=!0,t.array=[f(-Math.log10(a),0),f(1,1)]):a<=u?t.array=[f(a,0)]:(t.setOperator(Math.log10(a),0),t.array=[f(Math.log10(a),0),f(1,1)]),t}},{key:"fromString",value:function(e){var t,a,n,i,o,s,g,y=new r;if(e.startsWith("PN")&&(e=e.substring(2)),!isNaN(Number(e))){var p=Number(e),m=!1;if(0==p?/^((0)|(0*\.0+e\d+)|(0*\.0*))$/.test(e)&&(m=!0):m=!0,!m){var N=e.search(/e/),v=e.substring((-1==N?e.length:N)+1),w=e.substring(0,-1==N?void 0:N),b=[0,0];if(b[1]=Number(v||"0"),Number(w)>=1){var O=w.length>=17?h(w):Math.log10(Number(w)),E=O-(Math.floor(O)-1);b[0]=Math.pow(10,E),b[1]+=E}else{var I=(g=w.match(/^0\.(0*)[1-9]/))?g[1].length:0;w=(w=w.substring(w.search(/[1-9]/))).charAt(0)+"."+w.substring(1),I+=1,b[0]=Number(w),b[1]+=-I}return r.pow(10,-b[1]-1).mul(10*Math.pow(b[0],-1)).rec()}if(isFinite(p)&&m)return y=r.fromNumber(Number(e))}if(-1!==e.indexOf("l")&&-1!==e.indexOf("s")&&-1!==e.indexOf("a")){var d=function(r){var e=r.match(/l(\d+)\s+s(\d+)\s+a(\[.*\])/);try{if(e)return{lValue:parseInt(e[1]),sValue:parseInt(e[2]),array:JSON.parse(e[3])}}catch(r){return null}return null}(e);if(!d||0!==d.sValue&&1!==d.sValue&&-1!==d.sValue)throw"[PowiainaNum 0.2 error]malformed input: "+e;return(y=r.fromObject(d.array)).layer=d.lValue,y.sign=d.sValue,y.small=!1,y.normalize(),y}if(e=e.replace(/\(e\^(\d+)\)/g,"(10^)^$1 ").replace(/(\d+)\x20*PT/g,"(10^)^$1 "),!c.test(e))throw"[PowiainaNum 0.2 error]malformed input: "+e;var x=!1,M=!1;if("-"==e[0]||"+"==e[0]){var k=e.search(/[^-\+]/);x=(null!==(a=null===(t=e.substring(0,k).match(/-/g))||void 0===t?void 0:t.length)&&void 0!==a?a:0)%2==1,e=e.substring(k)}if("/"==e[0]){k=e.search(/[^\/]/);M=(null!==(i=null===(n=e.substring(0,k).match(/\//g))||void 0===n?void 0:n.length)&&void 0!==i?i:0)%2==1,e=e.substring(k)}if("NaN"==e)y.array=[f(NaN)];else if("Infinity"==e)y.array=[f(1/0)];else{var q,T,S,_;for(y.sign=1,y.array=[f(0)],"P"==e[0]&&("^"==e[1]?(q=e.substring(2).search(/[^0-9]/)+2,y.layer=Number(e.substring(2,q)),e=e.substring(q+1)):(q=e.search(/[^P]/),y.layer=q,e=e.substring(q)));e&&/^(\(?10[\^\{])/.test(e);){var F,A,Z;if("("==e[0]&&(e=e.substring(1)),"^"==e[2])F=q=e.substring(2).search(/[^\^]/),T=q+2;else{q=e.indexOf("}");var R=e.substring(3,q).split(",");F=Number("!"==R[0]?1/0:R[0]),A=Number(null!==(o="!"==R[1]?1/0:R[1])&&void 0!==o?o:1),Z=Number(null!==(s=R[2])&&void 0!==s?s:1),T=q+1}")"==(e=e.substring(T))[0]?(q=e.indexOf(" "),S=Number(e.substring(2,q)),e=e.substring(q+1)):S=1,1==F&&1==A&&1==Z?y.array.length>=2&&1==y.array[1].arrow?y.array[1].repeat+=S:y.array.splice(1,0,f(S,1,A,Z)):2==F&&1==A&&1==Z?(q=y.array.length>=2&&1==y.array[1].arrow?y.array[1].repeat:0,(T=y.array[0].repeat)>=1e10&&++q,T>=10&&++q,y.array[0].repeat=q,y.array.length>=2&&1==y.array[1].arrow&&y.array.splice(1,1),_=y.getOperatorIndex(2),Number.isInteger(_)?y.array[_].repeat+=S:y.array.splice(Math.ceil(_),0,f(S,2,A,Z))):isFinite(F)?(q=y.getOperator(F-1),(T=y.getOperator(F-2))>=10&&++q,_=y.getOperatorIndex(F),y.array.splice(1,Math.ceil(_)-1),y.array[0].repeat=q,Number.isInteger(_)?y.array[1].repeat+=S:y.array.splice(1,0,f(S,F,A,Z))):y.array.splice(1,0,f(S,F,A,Z))}q=e.split(/[Ee]/),T=[y.array[0].repeat,0],S=1;for(var P=q.length-1;P>=0;--P){T[0]<l&&0===T[1]?T[0]=Math.pow(10,S*T[0]):-1==S?(0===T[1]?T[0]=Math.pow(10,S*T[0]):1==T[1]&&T[0]<=Math.log10(Number.MAX_VALUE)?T[0]=Math.pow(10,S*Math.pow(10,T[0])):T[0]=0,T[1]=0):T[1]++;var V=q[P].indexOf("."),Y=-1==V?q[P].length:V;0===T[1]?Y>=17?(T[0]=Math.log10(T[0])+h(q[P].substring(0,Y)),T[1]=1):q[P]&&(T[0]*=Number(q[P])):(_=Y>=17?h(q[P].substring(0,Y)):q[P]?Math.log10(Number(q[P])):0,1==T[1]?T[0]+=_:2==T[1]&&T[0]<l+Math.log10(_)&&(T[0]+=Math.log10(1+Math.pow(10,Math.log10(_)-T[0])))),T[0]<l&&T[1]?(T[0]=Math.pow(10,T[0]),T[1]--):T[0]>u&&(T[0]=Math.log10(T[0]),T[1]++)}y.array[0].repeat=T[0],T[1]&&(y.array.length>=2&&1==y.array[1].arrow&&1==y.array[1].expans&&1==y.array[1].megota?y.array[1].repeat+=T[1]:y.array.splice(1,0,f(T[1],1,1,1)))}return x&&(y.sign*=-1),M&&(y.small=!y.small),y.normalize(),y.normalize(),y}},{key:"fromObject",value:function(e){var t=new r;if(t.array=[],function(r){if(!Array.isArray(r))return!1;for(var e=0;e<r.length;e++){var t=r[e];if(!Array.isArray(t))return!1;if(!m(t))return!1;if(!N(t))return!1}return!0}(e)){for(var a=0;a<e.length;a++)t.array[a]={arrow:e[a][0],expans:1,megota:1,repeat:e[a][1]};return t.small=!1,t.sign=1,t.layer=0,t}if(function(r){if(!Array.isArray(r))return!1;if("number"!=typeof r[0])return!1;for(var e=1;e<r.length;e++){var t=r[e];if(!Array.isArray(t))return!1;if(!w(t))return!1;if(!b(t)&&!O(t)&&!E(t))return!1}return!0}(e)){var n=e;t.array[0]=f(n[0]);for(var i=1;i<n.length;i++){var o=n[i];t.array[1]=f(o[1],v(o[0]),v(o[2]),o[3])}return t.small=!1,t.sign=1,t.layer=0,t}for(var u=0;u<e.array.length;u++)t.array[u]={arrow:e.array[u].arrow,expans:e.array[u].expans,megota:e.array[u].megota,repeat:e.array[u].repeat,valuereplaced:e.array[u].valuereplaced};return t.small=e.small,t.sign=e.sign,t.layer=e.layer,t}}])}();o=Symbol.toStringTag,M.ZERO=new M({array:[{arrow:0,expans:1,megota:1,repeat:1/0}],small:!0,layer:0,sign:0}),M.ONE=new M({array:[{arrow:0,expans:1,megota:1,repeat:1}],small:!1,layer:0,sign:1}),M.MSI=new M(u),M.MSI_REC=((x=new M(u)).small=!0,x),M.E_MSI=new M({array:[{arrow:0,expans:1,megota:1,repeat:u},{arrow:1,expans:1,megota:1,repeat:1}],small:!1,layer:0,sign:1}),M.EE_MSI=new M({array:[{arrow:0,expans:1,megota:1,repeat:u},{arrow:1,expans:1,megota:1,repeat:2}],small:!1,layer:0,sign:1}),M.E_MSI_REC=new M({array:[{arrow:0,expans:1,megota:1,repeat:u},{arrow:1,expans:1,megota:1,repeat:1}],small:!0,layer:0,sign:1}),M.TETRATED_MSI=new M({array:[{arrow:0,expans:1,megota:1,repeat:1e10},{arrow:1,expans:1,megota:1,repeat:u-2}],small:!1,layer:0,sign:1}),M.PENTATED_MSI=new M({array:[{arrow:0,expans:1,megota:1,repeat:10},{arrow:2,expans:1,megota:1,repeat:u-1}],small:!1,layer:0,sign:1}),M.TRITRI=new M({small:!1,layer:0,sign:1,array:[f(3638334640023.7783,0,1,1),f(7625587484984,1,1,1)]}),M.GRAHAMS_NUMBER=new M("(10{!})^63 10^^^(10^)^7625597484984 3638334640023.7783"),M.POSITIVE_INFINITY=new M(1/0),M.NEGATIVE_INFINITY=new M(-1/0),M.NaN=new M({array:[{arrow:0,expans:1,megota:1,repeat:NaN}],small:!1,layer:0,sign:0}),M.E=new M(Math.E),M.LN2=new M(Math.LN2),M.LN10=new M(Math.LN10),M.LOG2E=new M(Math.LOG2E),M.LOG10E=new M(Math.LOG10E),M.PI=new M(Math.PI),M.SQRT1_2=new M(Math.SQRT1_2),M.SQRT2=new M(Math.SQRT2),M.maxOps=100,M.POW_2_44_MOD_PI=1.701173079953,M.arrowFuncMap=new Map,r.arraySortFunction=d,r.default=M,r.mergeSameArrays=function(r){for(var e=1;e<r.array.length-1;++e)r.array[e].arrow==r.array[e+1].arrow&&r.array[e].expans==r.array[e+1].expans&&r.array[e].megota==r.array[e+1].megota&&(r.array[e].repeat+=r.array[e+1].repeat,r.array.splice(e+1,1),--e)},Object.defineProperty(r,"__esModule",{value:!0})}));
package/dist/index.d.ts CHANGED
@@ -11,6 +11,10 @@ interface IPowiainaNum {
11
11
  sign: -1 | 0 | 1;
12
12
  layer: number;
13
13
  }
14
+ type PowiainaNumArray01X = [
15
+ number,
16
+ ...([number, number, number, number] | ["x", number, number, number] | [number, number, "x", number])[]
17
+ ];
14
18
  type ExpantaNumArray = [number, number][];
15
19
  export type PowiainaNumSource = number | string | IPowiainaNum | PowiainaNum | ExpantaNumArray;
16
20
  export declare function arraySortFunction(a: Operator, b: Operator): 0 | 1 | -1;
@@ -297,11 +301,11 @@ export default class PowiainaNum implements IPowiainaNum {
297
301
  */
298
302
  toJSON(): string;
299
303
  static fromString(input: string): PowiainaNum;
300
- static fromObject(powlikeObject: IPowiainaNum | ExpantaNumArray): PowiainaNum;
304
+ static fromObject(powlikeObject: IPowiainaNum | ExpantaNumArray | PowiainaNumArray01X): PowiainaNum;
301
305
  /**
302
306
  * A property array value for version 0.1.x PowiainaNum.
303
307
  */
304
- get arr01(): [number, ...([number, number, number, number] | ["x", number, number, number] | [number, number, "x", number])[]];
308
+ get arr01(): PowiainaNumArray01X;
305
309
  /**
306
310
  * Zero
307
311
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powiaina_num.js",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "A JavaScript library that handles arithmetic for numbers as large as {10,9e15,1,1,1,2}.",
5
5
  "type": "module",
6
6
  "main": "dist/PowiainaNum.cjs.js",