diff --git a/dist/game/eMath.game.js b/dist/game/eMath.game.js index cc84dca..c7a6ed4 100644 --- a/dist/game/eMath.game.js +++ b/dist/game/eMath.game.js @@ -5511,7 +5511,7 @@ var import_reflect_metadata = require("reflect-metadata"); var import_class_transformer2 = require("class-transformer"); // src/classes/numericalAnalysis.ts -var DEFAULT_ITERATIONS = 35; +var DEFAULT_ITERATIONS = 30; var DEFAULT_TOLERANCE = 1e-3; function equalsTolerance(a, b, tolerance, config) { config = Object.assign({}, { @@ -5566,7 +5566,8 @@ function inverseFunctionApprox(f, n, mode = "geometric", iterations = DEFAULT_IT const midValue = f(mid); if (equalsTolerance(lowerBound, upperBound, tolerance, { verbose: false, mode: "geometric" })) { break; - } else if (midValue.lt(n)) { + } + if (midValue.lt(n)) { lowerBound = mid; } else { upperBound = mid; @@ -5658,16 +5659,6 @@ function calculateUpgrade(value, upgrade, start, end = Infinity, mode, iteration const maxLevelAffordableActual = maxLevelAffordable.sub(start).add(1).max(0); return [maxLevelAffordableActual, cost]; } -function decimalToJSONString(n) { - n = E(n); - return `${n.sign}/${n.mag}/${n.layer}`; -} -function upgradeToCacheNameSum(start, end) { - return `sum/${decimalToJSONString(start)}/${decimalToJSONString(end)}}`; -} -function upgradeToCacheNameEL(level) { - return `el/${decimalToJSONString(level)}`; -} var UpgradeData = class { /** * Constructs a new upgrade object with an initial level of 1 (or the provided level) @@ -5688,7 +5679,7 @@ __decorateClass([ var UpgradeStatic = class _UpgradeStatic { static { /** The default size of the cache. Should be one less than a power of 2. */ - this.cacheSize = 63; + this.cacheSize = 15; } /** @returns The data of the upgrade. */ get data() { @@ -5711,7 +5702,7 @@ var UpgradeStatic = class _UpgradeStatic { * Constructs a new static upgrade object. * @param init - The upgrade object to initialize. * @param dataPointer - A function or reference that returns the pointer of the data / frontend. - * @param cacheSize - The size of the cache. Should be one less than a power of 2. See {@link cache} + * @param cacheSize - The size of the cache. Should be one less than a power of 2. See {@link cache}. Set to `0` to disable caching. */ constructor(init, dataPointer, cacheSize) { const data = typeof dataPointer === "function" ? dataPointer() : dataPointer; @@ -5727,33 +5718,51 @@ var UpgradeStatic = class _UpgradeStatic { this.el = init.el; this.defaultLevel = init.level ?? E(1); } - getCached(type, start, end) { - if (type === "sum") { - return this.cache.get(upgradeToCacheNameSum(start, end ?? E(0))); - } else { - return this.cache.get(upgradeToCacheNameEL(start)); - } - } - setCached(type, start, endOrStart, costSum) { - const data = type === "sum" ? { - id: this.id, - el: false, - start: E(start), - end: E(endOrStart), - cost: E(costSum) - } : { - id: this.id, - el: true, - level: E(start), - cost: E(endOrStart) - }; - if (type === "sum") { - this.cache.set(upgradeToCacheNameSum(start, endOrStart), data); - } else { - this.cache.set(upgradeToCacheNameEL(start), data); - } - return data; - } + // /** + // * Gets the cached data of the upgrade. + // * @param type - The type of the cache. "sum" or "el" + // * @param start - The starting level of the upgrade. + // * @param end - The ending level or quantity to reach for the upgrade. + // * @returns The data of the upgrade. + // */ + // public getCached (type: "sum", start: ESource, end: ESource): UpgradeCachedSum | undefined; + // public getCached (type: "el", start: ESource): UpgradeCachedEL | undefined; + // public getCached (type: "sum" | "el", start: ESource, end?: ESource): UpgradeCachedEL | UpgradeCachedSum | undefined { + // if (type === "sum") { + // return this.cache.get(upgradeToCacheNameSum(start, end ?? E(0))); + // } else { + // return this.cache.get(upgradeToCacheNameEL(start)); + // } + // } + // /** + // * Sets the cached data of the upgrade. + // * @param type - The type of the cache. "sum" or "el" + // * @param start - The starting level of the upgrade. + // * @param end - The ending level or quantity to reach for the upgrade. + // * @param cost - The cost of the upgrade. + // */ + // public setCached(type: "sum", start: ESource, end: ESource, cost: ESource): UpgradeCachedSum; + // public setCached(type: "el", level: ESource, cost: ESource): UpgradeCachedEL; + // public setCached (type: "sum" | "el", start: ESource, endOrStart: ESource, costSum?: ESource): UpgradeCachedEL | UpgradeCachedSum { + // const data = type === "sum" ? { + // id: this.id, + // el: false, + // start: E(start), + // end: E(endOrStart), + // cost: E(costSum), + // } : { + // id: this.id, + // el: true, + // level: E(start), + // cost: E(endOrStart), + // }; + // if (type === "sum") { + // this.cache.set(upgradeToCacheNameSum(start, endOrStart), data as UpgradeCachedSum); + // } else { + // this.cache.set(upgradeToCacheNameEL(start), data as UpgradeCachedEL); + // } + // return data as UpgradeCachedEL | UpgradeCachedSum; + // } }; // src/classes/Currency.ts @@ -6572,7 +6581,7 @@ var DataManager = class { const hasedData = (0, import_md5.default)(`${this.gameRef.config.name.id}/${JSON.stringify(gameDataString)}`); let version; try { - version = "8.3.0"; + version = "8.4.0"; } catch (error) { version = "8.3.0"; } diff --git a/dist/game/eMath.game.min.js b/dist/game/eMath.game.min.js index 053685c..93b588a 100644 --- a/dist/game/eMath.game.min.js +++ b/dist/game/eMath.game.min.js @@ -1,4 +1,4 @@ -"use strict";(function(At,at){var Ct=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],at);else if(typeof module=="object"&&module.exports)module.exports=at();else{var ft=at(),Tt=Ct?exports:At;for(var Ot in ft)Tt[Ot]=ft[Ot]}})(typeof self<"u"?self:exports,()=>{var At={},at={exports:At},Ct=Object.create,ft=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,Ot=Object.getOwnPropertyNames,ze=Object.getPrototypeOf,Ye=Object.prototype.hasOwnProperty,bt=(t,e)=>function(){return e||(0,t[Ot(t)[0]])((e={exports:{}}).exports,e),e.exports},Rt=(t,e)=>{for(var r in e)ft(t,r,{get:e[r],enumerable:!0})},Qt=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ot(e))!Ye.call(t,n)&&n!==r&&ft(t,n,{get:()=>e[n],enumerable:!(i=Tt(e,n))||i.enumerable});return t},ot=(t,e,r)=>(r=t!=null?Ct(ze(t)):{},Qt(e||!t||!t.__esModule?ft(r,"default",{value:t,enumerable:!0}):r,t)),Ze=t=>Qt(ft({},"__esModule",{value:!0}),t),lt=(t,e,r,i)=>{for(var n=i>1?void 0:i?Tt(e,r):e,s=t.length-1,c;s>=0;s--)(c=t[s])&&(n=(i?c(e,r,n):c(n))||n);return i&&n&&ft(e,r,n),n},ct=bt({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var i=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:p(),n=s(e);typeof i.Reflect<"u"&&(n=s(i.Reflect,n)),r(n,i),typeof i.Reflect>"u"&&(i.Reflect=e);function s(l,v){return function(f,u){Object.defineProperty(l,f,{configurable:!0,writable:!0,value:u}),v&&v(f,u)}}function c(){try{return Function("return this;")()}catch{}}function y(){try{return(0,eval)("(function() { return this; })()")}catch{}}function p(){return c()||y()}})(function(r,i){var n=Object.prototype.hasOwnProperty,s=typeof Symbol=="function",c=s&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",y=s&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",p=typeof Object.create=="function",l={__proto__:[]}instanceof Array,v=!p&&!l,f={create:p?function(){return Jt(Object.create(null))}:l?function(){return Jt({__proto__:null})}:function(){return Jt({})},has:v?function(d,b){return n.call(d,b)}:function(d,b){return b in d},get:v?function(d,b){return n.call(d,b)?d[b]:void 0}:function(d,b){return d[b]}},u=Object.getPrototypeOf(Function),h=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:qr(),g=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:Br(),w=typeof WeakMap=="function"?WeakMap:Dr(),I=s?Symbol.for("@reflect-metadata:registry"):void 0,k=Lr(),F=kr(k);function a(d,b,O,C){if(j(O)){if(!xe(d))throw new TypeError;if(!Le(b))throw new TypeError;return tt(d,b)}else{if(!xe(d))throw new TypeError;if(!J(b))throw new TypeError;if(!J(C)&&!j(C)&&!_t(C))throw new TypeError;return _t(C)&&(C=void 0),O=ut(O),nt(d,b,O,C)}}r("decorate",a);function S(d,b){function O(C,R){if(!J(C))throw new TypeError;if(!j(R)&&!Fr(R))throw new TypeError;qt(d,b,C,R)}return O}r("metadata",S);function m(d,b,O,C){if(!J(O))throw new TypeError;return j(C)||(C=ut(C)),qt(d,b,O,C)}r("defineMetadata",m);function A(d,b,O){if(!J(b))throw new TypeError;return j(O)||(O=ut(O)),W(d,b,O)}r("hasMetadata",A);function _(d,b,O){if(!J(b))throw new TypeError;return j(O)||(O=ut(O)),Z(d,b,O)}r("hasOwnMetadata",_);function M(d,b,O){if(!J(b))throw new TypeError;return j(O)||(O=ut(O)),X(d,b,O)}r("getMetadata",M);function T(d,b,O){if(!J(b))throw new TypeError;return j(O)||(O=ut(O)),dt(d,b,O)}r("getOwnMetadata",T);function E(d,b){if(!J(d))throw new TypeError;return j(b)||(b=ut(b)),Bt(d,b)}r("getMetadataKeys",E);function G(d,b){if(!J(d))throw new TypeError;return j(b)||(b=ut(b)),Dt(d,b)}r("getOwnMetadataKeys",G);function H(d,b,O){if(!J(b))throw new TypeError;if(j(O)||(O=ut(O)),!J(b))throw new TypeError;j(O)||(O=ut(O));var C=It(b,O,!1);return j(C)?!1:C.OrdinaryDeleteMetadata(d,b,O)}r("deleteMetadata",H);function tt(d,b){for(var O=d.length-1;O>=0;--O){var C=d[O],R=C(b);if(!j(R)&&!_t(R)){if(!Le(R))throw new TypeError;b=R}}return b}function nt(d,b,O,C){for(var R=d.length-1;R>=0;--R){var Q=d[R],et=Q(b,O,C);if(!j(et)&&!_t(et)){if(!J(et))throw new TypeError;C=et}}return C}function W(d,b,O){var C=Z(d,b,O);if(C)return!0;var R=Xt(b);return _t(R)?!1:W(d,R,O)}function Z(d,b,O){var C=It(b,O,!1);return j(C)?!1:Fe(C.OrdinaryHasOwnMetadata(d,b,O))}function X(d,b,O){var C=Z(d,b,O);if(C)return dt(d,b,O);var R=Xt(b);if(!_t(R))return X(d,R,O)}function dt(d,b,O){var C=It(b,O,!1);if(!j(C))return C.OrdinaryGetOwnMetadata(d,b,O)}function qt(d,b,O,C){var R=It(O,C,!0);R.OrdinaryDefineOwnMetadata(d,b,O,C)}function Bt(d,b){var O=Dt(d,b),C=Xt(d);if(C===null)return O;var R=Bt(C,b);if(R.length<=0)return O;if(O.length<=0)return R;for(var Q=new g,et=[],$=0,x=O;$=0&&x=this._keys.length?(this._index=-1,this._keys=b,this._values=b):this._index++,{value:P,done:!1}}return{value:void 0,done:!0}},$.prototype.throw=function(x){throw this._index>=0&&(this._index=-1,this._keys=b,this._values=b),x},$.prototype.return=function(x){return this._index>=0&&(this._index=-1,this._keys=b,this._values=b),{value:x,done:!0}},$}(),C=function(){function $(){this._keys=[],this._values=[],this._cacheKey=d,this._cacheIndex=-2}return Object.defineProperty($.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),$.prototype.has=function(x){return this._find(x,!1)>=0},$.prototype.get=function(x){var P=this._find(x,!1);return P>=0?this._values[P]:void 0},$.prototype.set=function(x,P){var q=this._find(x,!0);return this._values[q]=P,this},$.prototype.delete=function(x){var P=this._find(x,!1);if(P>=0){for(var q=this._keys.length,B=P+1;B>>8,f[u*2+1]=g%256}return f},decompressFromUint8Array:function(l){if(l==null)return p.decompress(l);for(var v=new Array(l.length/2),f=0,u=v.length;f>1}else{for(h=1,u=0;u>1}a--,a==0&&(a=Math.pow(2,m),m++),delete w[F]}else for(h=g[F],u=0;u>1;a--,a==0&&(a=Math.pow(2,m),m++),g[k]=S++,F=String(I)}if(F!==""){if(Object.prototype.hasOwnProperty.call(w,F)){if(F.charCodeAt(0)<256){for(u=0;u>1}else{for(h=1,u=0;u>1}a--,a==0&&(a=Math.pow(2,m),m++),delete w[F]}else for(h=g[F],u=0;u>1;a--,a==0&&(a=Math.pow(2,m),m++)}for(h=2,u=0;u>1;for(;;)if(_=_<<1,M==v-1){A.push(f(_));break}else M++;return A.join("")},decompress:function(l){return l==null?"":l==""?null:p._decompress(l.length,32768,function(v){return l.charCodeAt(v)})},_decompress:function(l,v,f){var u=[],h,g=4,w=4,I=3,k="",F=[],a,S,m,A,_,M,T,E={val:f(0),position:v,index:1};for(a=0;a<3;a+=1)u[a]=a;for(m=0,_=Math.pow(2,2),M=1;M!=_;)A=E.val&E.position,E.position>>=1,E.position==0&&(E.position=v,E.val=f(E.index++)),m|=(A>0?1:0)*M,M<<=1;switch(h=m){case 0:for(m=0,_=Math.pow(2,8),M=1;M!=_;)A=E.val&E.position,E.position>>=1,E.position==0&&(E.position=v,E.val=f(E.index++)),m|=(A>0?1:0)*M,M<<=1;T=i(m);break;case 1:for(m=0,_=Math.pow(2,16),M=1;M!=_;)A=E.val&E.position,E.position>>=1,E.position==0&&(E.position=v,E.val=f(E.index++)),m|=(A>0?1:0)*M,M<<=1;T=i(m);break;case 2:return""}for(u[3]=T,S=T,F.push(T);;){if(E.index>l)return"";for(m=0,_=Math.pow(2,I),M=1;M!=_;)A=E.val&E.position,E.position>>=1,E.position==0&&(E.position=v,E.val=f(E.index++)),m|=(A>0?1:0)*M,M<<=1;switch(T=m){case 0:for(m=0,_=Math.pow(2,8),M=1;M!=_;)A=E.val&E.position,E.position>>=1,E.position==0&&(E.position=v,E.val=f(E.index++)),m|=(A>0?1:0)*M,M<<=1;u[w++]=i(m),T=w-1,g--;break;case 1:for(m=0,_=Math.pow(2,16),M=1;M!=_;)A=E.val&E.position,E.position>>=1,E.position==0&&(E.position=v,E.val=f(E.index++)),m|=(A>0?1:0)*M,M<<=1;u[w++]=i(m),T=w-1,g--;break;case 2:return F.join("")}if(g==0&&(g=Math.pow(2,I),I++),u[T])k=u[T];else if(T===w)k=S+S.charAt(0);else return null;F.push(k),u[w++]=S+k.charAt(0),g--,S=k,g==0&&(g=Math.pow(2,I),I++)}}};return p}();typeof define=="function"&&define.amd?define(function(){return r}):typeof e<"u"&&e!=null?e.exports=r:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return r})}}),Ve=bt({"node_modules/crypt/crypt.js"(t,e){(function(){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i={rotl:function(n,s){return n<>>32-s},rotr:function(n,s){return n<<32-s|n>>>s},endian:function(n){if(n.constructor==Number)return i.rotl(n,8)&16711935|i.rotl(n,24)&4278255360;for(var s=0;s0;n--)s.push(Math.floor(Math.random()*256));return s},bytesToWords:function(n){for(var s=[],c=0,y=0;c>>5]|=n[c]<<24-y%32;return s},wordsToBytes:function(n){for(var s=[],c=0;c>>5]>>>24-c%32&255);return s},bytesToHex:function(n){for(var s=[],c=0;c>>4).toString(16)),s.push((n[c]&15).toString(16));return s.join("")},hexToBytes:function(n){for(var s=[],c=0;c>>6*(3-p)&63)):s.push("=");return s.join("")},base64ToBytes:function(n){n=n.replace(/[^A-Z0-9+\/]/ig,"");for(var s=[],c=0,y=0;c>>6-y*2);return s}};e.exports=i})()}}),Kt=bt({"node_modules/charenc/charenc.js"(t,e){var r={utf8:{stringToBytes:function(i){return r.bin.stringToBytes(unescape(encodeURIComponent(i)))},bytesToString:function(i){return decodeURIComponent(escape(r.bin.bytesToString(i)))}},bin:{stringToBytes:function(i){for(var n=[],s=0;s>>24)&16711935|(l[w]<<24|l[w]>>>8)&4278255360;l[v>>>5]|=128<>>9<<4)+14]=v;for(var I=c._ff,k=c._gg,F=c._hh,a=c._ii,w=0;w>>0,u=u+m>>>0,h=h+A>>>0,g=g+_>>>0}return r.endian([f,u,h,g])};c._ff=function(y,p,l,v,f,u,h){var g=y+(p&l|~p&v)+(f>>>0)+h;return(g<>>32-u)+p},c._gg=function(y,p,l,v,f,u,h){var g=y+(p&v|l&~v)+(f>>>0)+h;return(g<>>32-u)+p},c._hh=function(y,p,l,v,f,u,h){var g=y+(p^l^v)+(f>>>0)+h;return(g<>>32-u)+p},c._ii=function(y,p,l,v,f,u,h){var g=y+(l^(p|~v))+(f>>>0)+h;return(g<>>32-u)+p},c._blocksize=16,c._digestsize=16,e.exports=function(y,p){if(y==null)throw new Error("Illegal argument "+y);var l=r.wordsToBytes(c(y,p));return p&&p.asBytes?l:p&&p.asString?s.bytesToString(l):r.bytesToHex(l)}})()}}),te={};Rt(te,{eMath:()=>Ar}),at.exports=Ze(te);var Gr=ot(ct()),Ur=ot(ct()),ee={};Rt(ee,{Attribute:()=>kt,AttributeStatic:()=>ye,Boost:()=>zt,BoostObject:()=>Nt,Currency:()=>yt,CurrencyStatic:()=>ve,DEFAULT_ITERATIONS:()=>xt,E:()=>L,FORMATS:()=>yr,FormatTypeList:()=>ir,Grid:()=>wr,GridCell:()=>be,LRUCache:()=>jt,ListNode:()=>re,UpgradeData:()=>vt,UpgradeStatic:()=>pe,calculateSum:()=>Zt,calculateSumApprox:()=>de,calculateSumLoop:()=>he,calculateUpgrade:()=>me,decimalToJSONString:()=>Lt,equalsTolerance:()=>ce,inverseFunctionApprox:()=>Yt,roundingBase:()=>br,upgradeToCacheNameEL:()=>Ht});var $r=ot(ct()),jt=class{constructor(t){this.map=new Map,this.first=void 0,this.last=void 0,this.maxSize=t}get size(){return this.map.size}get(t){let e=this.map.get(t);if(e!==void 0)return e!==this.first&&(e===this.last?(this.last=e.prev,this.last.next=void 0):(e.prev.next=e.next,e.next.prev=e.prev),e.next=this.first,this.first.prev=e,this.first=e),e.value}set(t,e){if(this.maxSize<1)return;if(this.map.has(t))throw new Error("Cannot update existing keys in the cache");let r=new re(t,e);for(this.first===void 0?(this.first=r,this.last=r):(r.next=this.first,this.first.prev=r,this.first=r),this.map.set(t,r);this.map.size>this.maxSize;){let i=this.last;this.map.delete(i.key),this.last=i.prev,this.last.next=void 0}}},re=class{constructor(t,e){this.next=void 0,this.prev=void 0,this.key=t,this.value=e}},U;(function(t){t[t.PLAIN_TO_CLASS=0]="PLAIN_TO_CLASS",t[t.CLASS_TO_PLAIN=1]="CLASS_TO_PLAIN",t[t.CLASS_TO_CLASS=2]="CLASS_TO_CLASS"})(U||(U={}));var Je=function(){function t(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return t.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},t.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.findTransformMetadatas=function(e,r,i){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?i===U.CLASS_TO_CLASS||i===U.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?i===U.CLASS_TO_PLAIN:!0})},t.prototype.findExcludeMetadata=function(e,r){return this.findMetadata(this._excludeMetadatas,e,r)},t.prototype.findExposeMetadata=function(e,r){return this.findMetadata(this._exposeMetadatas,e,r)},t.prototype.findExposeMetadataByCustomName=function(e,r){return this.getExposedMetadatas(e).find(function(i){return i.options&&i.options.name===r})},t.prototype.findTypeMetadata=function(e,r){return this.findMetadata(this._typeMetadatas,e,r)},t.prototype.getStrategy=function(e){var r=this._excludeMetadatas.get(e),i=r&&r.get(void 0),n=this._exposeMetadatas.get(e),s=n&&n.get(void 0);return i&&s||!i&&!s?"none":i?"excludeAll":"exposeAll"},t.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},t.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},t.prototype.getExposedProperties=function(e,r){return this.getExposedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===U.CLASS_TO_CLASS||r===U.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===U.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===U.CLASS_TO_CLASS||r===U.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===U.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var i=e.get(r),n;i&&(n=Array.from(i.values()).filter(function(f){return f.propertyName!==void 0}));for(var s=[],c=0,y=this.getAncestors(r);c0&&(c=c.filter(function(f){return!l.includes(f)})),this.options.version!==void 0&&(c=c.filter(function(f){var u=rt.findExposeMetadata(e,f);return!u||!u.options?!0:n.checkVersion(u.options.since,u.options.until)})),this.options.groups&&this.options.groups.length?c=c.filter(function(f){var u=rt.findExposeMetadata(e,f);return!u||!u.options?!0:n.checkGroups(u.options.groups)}):c=c.filter(function(f){var u=rt.findExposeMetadata(e,f);return!u||!u.options||!u.options.groups||!u.options.groups.length})}return this.options.excludePrefixes&&this.options.excludePrefixes.length&&(c=c.filter(function(v){return n.options.excludePrefixes.every(function(f){return v.substr(0,f.length)!==f})})),c=c.filter(function(v,f,u){return u.indexOf(v)===f}),c},t.prototype.checkVersion=function(e,r){var i=!0;return i&&e&&(i=this.options.version>=e),i&&r&&(i=this.options.versionNumber.MAX_SAFE_INTEGER)&&(A="\u03C9");let M=t.log(a,8e3).toNumber();if(m.equals(0))return A;if(m.gt(0)&&m.lte(3)){let G=[];for(let H=0;HNumber.MAX_SAFE_INTEGER)&&(A="\u03C9");let M=t.log(a,8e3).toNumber();if(m.equals(0))return A;if(m.gt(0)&&m.lte(2)){let G=[];for(let H=0;H118?e.elemental.beyondOg(_):e.elemental.config.element_lists[a-1][A]},beyondOg(a){let S=Math.floor(Math.log10(a)),m=["n","u","b","t","q","p","h","s","o","e"],A="";for(let _=S;_>=0;_--){let M=Math.floor(a/Math.pow(10,_))%10;A==""?A=m[M].toUpperCase():A+=m[M]}return A},abbreviationLength(a){return a==1?1:Math.pow(Math.floor(a/2)+1,2)*2},getAbbreviationAndValue(a){let S=a.log(118).toNumber(),m=Math.floor(S)+1,A=e.elemental.abbreviationLength(m),_=S-m+1,M=Math.floor(_*A),T=e.elemental.getAbbreviation(m,_),E=new t(118).pow(m+M/A-1);return[T,E]},formatElementalPart(a,S){return S.eq(1)?a:`${S} ${a}`},format(a,S=2){if(a.gt(new t(118).pow(new t(118).pow(new t(118).pow(4)))))return"e"+e.elemental.format(a.log10(),S);let m=a.log(118),_=m.log(118).log(118).toNumber(),M=Math.max(4-_*2,1),T=[];for(;m.gte(1)&&T.length=M)return T.map(G=>e.elemental.formatElementalPart(G[0],G[1])).join(" + ");let E=new t(118).pow(m).toFixed(T.length===1?3:S);return T.length===0?E:T.length===1?`${E} \xD7 ${e.elemental.formatElementalPart(T[0][0],T[0][1])}`:`${E} \xD7 (${T.map(G=>e.elemental.formatElementalPart(G[0],G[1])).join(" + ")})`}},old_sc:{format(a,S){a=new t(a);let m=a.log10().floor();if(m.lt(9))return m.lt(3)?a.toFixed(S):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let _=a.slog();return(_.gte(1e9)?"":new t(10).pow(_.sub(_.floor())).toFixed(4))+"F"+e.old_sc.format(_.floor(),0)}let A=a.div(new t(10).pow(m));return(m.log10().gte(9)?"":A.toFixed(4))+"e"+e.old_sc.format(m,0)}}},eng:{format(a,S=2){a=new t(a);let m=a.log10().floor();if(m.lt(9))return m.lt(3)?a.toFixed(S):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let _=a.slog();return(_.gte(1e9)?"":new t(10).pow(_.sub(_.floor())).toFixed(4))+"F"+e.eng.format(_.floor(),0)}let A=a.div(new t(1e3).pow(m.div(3).floor()));return(m.log10().gte(9)?"":A.toFixed(new t(4).sub(m.sub(m.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(m.div(3).floor().mul(3),0)}}},mixed_sc:{format(a,S,m=9){a=new t(a);let A=a.log10().floor();return A.lt(303)&&A.gte(m)?p(a,S,m,"st"):p(a,S,m,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(a,S=2,m){a=new t(a);let A=a.max(1).log10().max(1).log(r.log10()).floor();if(A.lte(0))return p(a,S,m,"sc");a=new t(10).pow(a.max(1).log10().div(r.log10().pow(A)).sub(A.gte(1)?1:0));let _=A.div(10).floor(),M=A.toNumber()%10-1;return p(a,Math.max(4,S),m,"sc")+" "+(_.gte(1)?"meta"+(_.gte(2)?"^"+p(_,0,m,"sc"):"")+"-":"")+(isNaN(M)?"nanity":e.layer.layers[M])}},standard:{tier1(a){return mt[0][0][a%10]+mt[0][1][Math.floor(a/10)%10]+mt[0][2][Math.floor(a/100)]},tier2(a){let S=a%10,m=Math.floor(a/10)%10,A=Math.floor(a/100)%10,_="";return a<10?mt[1][0][a]:(m==1&&S==0?_+="Vec":_+=mt[1][1][S]+mt[1][2][m],_+=mt[1][3][A],_)}},inf:{format(a,S,m){a=new t(a);let A=0,_=new t(Number.MAX_VALUE),M=["","\u221E","\u03A9","\u03A8","\u028A"],T=["","","m","mm","mmm"];for(;a.gte(_);)a=a.log(_),A++;return A==0?p(a,S,m,"sc"):a.gte(3)?T[A]+M[A]+"\u03C9^"+p(a.sub(1),S,m,"sc"):a.gte(2)?T[A]+"\u03C9"+M[A]+"-"+p(_.pow(a.sub(2)),S,m,"sc"):T[A]+M[A]+"-"+p(_.pow(a.sub(1)),S,m,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(a,S=new t(1e15),m=!1,A=9){if(a=new t(a),S=new t(S).div(1e3),a.lt(S.mul(1e3)))return"";let{alphabet:_}=e.alphabet.config,M=_.length,T=a.log(1e3).sub(S.log(1e3)).floor(),E=T.add(1).log(M+1).ceil(),G="",H=(tt,nt)=>{let W=tt,Z="";for(let X=0;X=M)return"\u03C9";Z=_[dt]+Z,W=W.sub(1).div(M).floor()}return Z};if(E.lt(A))G=H(T,E);else{let tt=E.sub(A).add(1),nt=T.div(t.pow(M+1,tt.sub(1))).floor();G=`${H(nt,new t(A))}(${tt.gt("1e9")?tt.format():tt.format(0)})`}return G},format(a,S=2,m=9,A="mixed_sc",_=new t(1e15),M=!1,T){if(a=new t(a),_=new t(_).div(1e3),a.lt(_.mul(1e3)))return p(a,S,m,A);let E=e.alphabet.getAbbreviation(a,_,M,T),G=a.div(t.pow(1e3,a.log(1e3).floor()));return`${E.length>(T??9)+2?"":G.toFixed(S)+" "}${E}`}}},r=new t(2).pow(1024),i="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",n="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function s(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":i[parseInt(S,10)]).join("")}function c(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":n[parseInt(S,10)]).join("")}function y(a,S=2,m=9,A="st"){return p(a,S,m,A)}function p(a,S=2,m=9,A="mixed_sc"){a=new t(a);let _=a.lt(0)?"-":"";if(a.mag==1/0)return _+"Infinity";if(Number.isNaN(a.mag))return _+"NaN";if(a.lt(0)&&(a=a.mul(-1)),a.eq(0))return a.toFixed(S);let M=a.log10().floor();switch(A){case"sc":case"scientific":if(a.log10().lt(Math.min(-S,0))&&S>1){let T=a.log10().ceil(),E=a.div(T.eq(-1)?new t(.1):new t(10).pow(T)),G=T.mul(-1).max(1).log10().gte(9);return _+(G?"":E.toFixed(2))+"e"+p(T,0,m,"mixed_sc")}else if(M.lt(m)){let T=Math.max(Math.min(S-M.toNumber(),S),0);return _+(T>0?a.toFixed(T):a.toFixed(T).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(a.gte("eeee10")){let G=a.slog();return(G.gte(1e9)?"":new t(10).pow(G.sub(G.floor())).toFixed(2))+"F"+p(G.floor(),0)}let T=a.div(new t(10).pow(M)),E=M.log10().gte(9);return _+(E?"":T.toFixed(2))+"e"+p(M,0,m,"mixed_sc")}case"st":case"standard":{let T=a.log(1e3).floor();if(T.lt(1))return _+a.toFixed(Math.max(Math.min(S-M.toNumber(),S),0));let E=T.mul(3),G=T.log10().floor();if(G.gte(3e3))return"e"+p(M,S,m,"st");let H="";if(T.lt(4))H=["","K","M","B"][Math.round(T.toNumber())];else{let W=Math.floor(T.log(1e3).toNumber());for(W<100&&(W=Math.max(W-1,0)),T=T.sub(1).div(new t(10).pow(W*3));T.gt(0);){let Z=T.div(1e3).floor(),X=T.sub(Z.mul(1e3)).floor().toNumber();X>0&&(X==1&&!W&&(H="U"),W&&(H=e.standard.tier2(W)+(H?"-"+H:"")),X>1&&(H=e.standard.tier1(X)+H)),T=Z,W++}}let tt=a.div(new t(10).pow(E)),nt=S===2?new t(2).sub(M.sub(E)).add(1).toNumber():S;return _+(G.gte(10)?"":tt.toFixed(nt)+" ")+H}default:return e[A]||console.error('Invalid format type "',A,'"'),_+e[A].format(a,S,m)}}function l(a,S,m="mixed_sc",A,_){a=new t(a),S=new t(S);let M=a.add(S),T,E=M.div(a);return E.gte(10)&&a.gte(1e100)?(E=E.log10().mul(20),T="(+"+p(E,A,_,m)+" OoMs/sec)"):T="(+"+p(S,A,_,m)+"/sec)",T}function v(a,S=2,m="s"){return a=new t(a),a.gte(86400)?p(a.div(86400).floor(),0,12,"sc")+":"+v(a.mod(86400),S,"d"):a.gte(3600)||m=="d"?(a.div(3600).gte(10)||m!="d"?"":"0")+p(a.div(3600).floor(),0,12,"sc")+":"+v(a.mod(3600),S,"h"):a.gte(60)||m=="h"?(a.div(60).gte(10)||m!="h"?"":"0")+p(a.div(60).floor(),0,12,"sc")+":"+v(a.mod(60),S,"m"):(a.gte(10)||m!="m"?"":"0")+p(a,S,12,"sc")}function f(a,S=!1,m=0,A=9,_="mixed_sc"){let M=Dt=>p(Dt,m,A,_);a=new t(a);let T=a.mul(1e3).mod(1e3).floor(),E=a.mod(60).floor(),G=a.div(60).mod(60).floor(),H=a.div(3600).mod(24).floor(),tt=a.div(86400).mod(365.2425).floor(),nt=a.div(31556952).floor(),W=nt.eq(1)?" year":" years",Z=tt.eq(1)?" day":" days",X=H.eq(1)?" hour":" hours",dt=G.eq(1)?" minute":" minutes",qt=E.eq(1)?" second":" seconds",Bt=T.eq(1)?" millisecond":" milliseconds";return`${nt.gt(0)?M(nt)+W+", ":""}${tt.gt(0)?M(tt)+Z+", ":""}${H.gt(0)?M(H)+X+", ":""}${G.gt(0)?M(G)+dt+", ":""}${E.gt(0)?M(E)+qt+",":""}${S&&T.gt(0)?" "+M(T)+Bt:""}`.replace(/,([^,]*)$/,"$1").trim()}function u(a){return a=new t(a),p(new t(1).sub(a).mul(100))+"%"}function h(a){return a=new t(a),p(a.mul(100))+"%"}function g(a,S=2){return a=new t(a),a.gte(1)?"\xD7"+a.format(S):"/"+a.pow(-1).format(S)}function w(a,S,m=10){return t.gte(a,10)?t.pow(m,t.log(a,m).pow(S)):new t(a)}function I(a,S=0){a=new t(a);let m=(T=>T.map((E,G)=>({name:E.name,altName:E.altName,value:t.pow(1e3,new t(G).add(1))})))([{name:"K",altName:"Kilo"},{name:"M",altName:"Mega"},{name:"G",altName:"Giga"},{name:"T",altName:"Tera"},{name:"P",altName:"Peta"},{name:"E",altName:"Exa"},{name:"Z",altName:"Zetta"},{name:"Y",altName:"Yotta"},{name:"R",altName:"Ronna"},{name:"Q",altName:"Quetta"}]),A="",_=a.lte(0)?0:t.min(t.log(a,1e3).sub(1),m.length-1).floor().toNumber(),M=m[_];if(_===0)switch(S){case 1:A="";break;case 2:case 0:default:A=a.format();break}switch(S){case 1:A=M.name;break;case 2:A=a.divide(M.value).format();break;case 3:A=M.altName;break;case 0:default:A=`${a.divide(M.value).format()} ${M.name}`;break}return A}function k(a,S=!1){return`${I(a,2)} ${I(a,1)}eV${S?"/c^2":""}`}let F={...e,toSubscript:s,toSuperscript:c,formatST:y,format:p,formatGain:l,formatTime:v,formatTimeLong:f,formatReduction:u,formatPercent:h,formatMult:g,expMult:w,metric:I,ev:k};return{FORMATS:e,formats:F}}var Ut=17,sr=9e15,ar=Math.log10(9e15),or=1/9e15,ur=308,lr=-324,ae=5,fr=1023,cr=!0,hr=!1,dr=function(){let t=[];for(let r=lr+1;r<=ur;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),gt=[2,Math.E,3,4,5,6,7,8,9,10],mr=[[1,1.0891180521811203,1.1789767925673957,1.2701455431742086,1.3632090180450092,1.4587818160364217,1.5575237916251419,1.6601571006859253,1.767485818836978,1.8804192098842727,2],[1,1.1121114330934079,1.231038924931609,1.3583836963111375,1.4960519303993531,1.6463542337511945,1.8121385357018724,1.996971324618307,2.2053895545527546,2.4432574483385254,Math.E],[1,1.1187738849693603,1.2464963939368214,1.38527004705667,1.5376664685821402,1.7068895236551784,1.897001227148399,2.1132403089001035,2.362480153784171,2.6539010333870774,3],[1,1.1367350847096405,1.2889510672956703,1.4606478703324786,1.6570295196661111,1.8850062585672889,2.1539465047453485,2.476829779693097,2.872061932789197,3.3664204535587183,4],[1,1.1494592900767588,1.319708228183931,1.5166291280087583,1.748171114438024,2.0253263297298045,2.3636668498288547,2.7858359149579424,3.3257226212448145,4.035730287722532,5],[1,1.159225940787673,1.343712473580932,1.5611293155111927,1.8221199554561318,2.14183924486326,2.542468319282638,3.0574682501653316,3.7390572020926873,4.6719550537360774,6],[1,1.1670905356972596,1.3632807444991446,1.5979222279405536,1.8842640123816674,2.2416069644878687,2.69893426559423,3.3012632110403577,4.121250340630164,5.281493033448316,7],[1,1.1736630594087796,1.379783782386201,1.6292821855668218,1.9378971836180754,2.3289975651071977,2.8384347394720835,3.5232708454565906,4.478242031114584,5.868592169644505,8],[1,1.1793017514670474,1.394054150657457,1.65664127441059,1.985170999970283,2.4069682290577457,2.9647310119960752,3.7278665320924946,4.814462547283592,6.436522247411611,9],[1,1.1840100246247336,1.4061375836156955,1.6802272208863964,2.026757028388619,2.4770056063449646,3.080525271755482,3.9191964192627284,5.135152840833187,6.989961179534715,10]],gr=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],N=function(e){return o.fromValue_noAlloc(e)},D=function(t,e,r){return o.fromComponents(t,e,r)},Y=function(e,r,i){return o.fromComponents_noNormalize(e,r,i)},ht=function(e,r){let i=r+1,n=Math.ceil(Math.log10(Math.abs(e))),s=Math.round(e*Math.pow(10,i-n))*Math.pow(10,n-i);return parseFloat(s.toFixed(Math.max(i-n,0)))},$t=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},pr=function(t){if(!isFinite(t))return t;if(t<-50)return t===Math.trunc(t)?Number.NEGATIVE_INFINITY:0;let e=1;for(;t<10;)e=e*t,++t;t-=1;let r=.9189385332046727;r=r+(t+.5)*Math.log(t),r=r-t;let i=t*t,n=t;return r=r+1/(12*n),n=n*i,r=r+1/(360*n),n=n*i,r=r+1/(1260*n),n=n*i,r=r+1/(1680*n),n=n*i,r=r+1/(1188*n),n=n*i,r=r+691/(360360*n),n=n*i,r=r+7/(1092*n),n=n*i,r=r+3617/(122400*n),Math.exp(r)/e},vr=.36787944117144233,oe=.5671432904097838,ue=function(t,e=1e-10){let r,i;if(!Number.isFinite(t)||t===0)return t;if(t===1)return oe;t<10?r=0:r=Math.log(t)-Math.log(Math.log(t));for(let n=0;n<100;++n){if(i=(t*Math.exp(-r)+r*r)/(r+1),Math.abs(i-r).5?1:-1;if(Math.random()*20<1)return Y(e,0,1);let r=Math.floor(Math.random()*(t+1)),i=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(i=Math.trunc(i));let n=Math.pow(10,i);return Math.random()>.9&&(n=Math.trunc(n)),D(e,r,n)}static affordGeometricSeries_core(t,e,r,i){let n=e.mul(r.pow(i));return o.floor(t.div(n).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,i){return e.mul(r.pow(i)).mul(o.sub(1,r.pow(t))).div(o.sub(1,r))}static affordArithmeticSeries_core(t,e,r,i){let s=e.add(i.mul(r)).sub(r.div(2)),c=s.pow(2);return s.neg().add(c.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let n=e.add(i.mul(r));return t.div(2).mul(n.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.sign==1?(this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY):this.sign==-1&&(this.mag=Number.NEGATIVE_INFINITY,this.layer=Number.NEGATIVE_INFINITY),this;if(this.layer===0&&this.mag=sr)return this.layer+=1,this.mag=e*Math.log10(t),this;for(;t0;)this.layer-=1,this.layer===0?this.mag=Math.pow(10,this.mag):(this.mag=e*Math.pow(10,t),t=Math.abs(this.mag),e=Math.sign(this.mag));return this.layer===0&&(this.mag<0?(this.mag=-this.mag,this.sign=-this.sign):this.mag===0&&(this.sign=0)),(Number.isNaN(this.sign)||Number.isNaN(this.layer)||Number.isNaN(this.mag))&&(this.sign=Number.NaN,this.layer=Number.NaN,this.mag=Number.NaN),this}fromComponents(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this.normalize(),this}fromComponents_noNormalize(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this}fromMantissaExponent(t,e){return this.layer=1,this.sign=Math.sign(t),t=Math.abs(t),this.mag=e+Math.log10(t),this.normalize(),this}fromMantissaExponent_noNormalize(t,e){return this.fromMantissaExponent(t,e),this}fromDecimal(t){return this.sign=t.sign,this.layer=t.layer,this.mag=t.mag,this}fromNumber(t){return this.mag=Math.abs(t),this.sign=Math.sign(t),this.layer=0,this.normalize(),this}fromString(t,e=!1){let r=t,i=o.fromStringCache.get(r);if(i!==void 0)return this.fromDecimal(i);cr?t=t.replace(",",""):hr&&(t=t.replace(",","."));let n=t.split("^^^");if(n.length===2){let w=parseFloat(n[0]),I=parseFloat(n[1]),k=n[1].split(";"),F=1;if(k.length===2&&(F=parseFloat(k[1]),isFinite(F)||(F=1)),isFinite(w)&&isFinite(I)){let a=o.pentate(w,I,F,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}}let s=t.split("^^");if(s.length===2){let w=parseFloat(s[0]),I=parseFloat(s[1]),k=s[1].split(";"),F=1;if(k.length===2&&(F=parseFloat(k[1]),isFinite(F)||(F=1)),isFinite(w)&&isFinite(I)){let a=o.tetrate(w,I,F,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}}let c=t.split("^");if(c.length===2){let w=parseFloat(c[0]),I=parseFloat(c[1]);if(isFinite(w)&&isFinite(I)){let k=o.pow(w,I);return this.sign=k.sign,this.layer=k.layer,this.mag=k.mag,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}}t=t.trim().toLowerCase();let y,p,l=t.split("pt");if(l.length===2){y=10,p=parseFloat(l[0]),l[1]=l[1].replace("(",""),l[1]=l[1].replace(")","");let w=parseFloat(l[1]);if(isFinite(w)||(w=1),isFinite(y)&&isFinite(p)){let I=o.tetrate(y,p,w,e);return this.sign=I.sign,this.layer=I.layer,this.mag=I.mag,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}}if(l=t.split("p"),l.length===2){y=10,p=parseFloat(l[0]),l[1]=l[1].replace("(",""),l[1]=l[1].replace(")","");let w=parseFloat(l[1]);if(isFinite(w)||(w=1),isFinite(y)&&isFinite(p)){let I=o.tetrate(y,p,w,e);return this.sign=I.sign,this.layer=I.layer,this.mag=I.mag,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}}if(l=t.split("f"),l.length===2){y=10,l[0]=l[0].replace("(",""),l[0]=l[0].replace(")","");let w=parseFloat(l[0]);if(l[1]=l[1].replace("(",""),l[1]=l[1].replace(")",""),p=parseFloat(l[1]),isFinite(w)||(w=1),isFinite(y)&&isFinite(p)){let I=o.tetrate(y,p,w,e);return this.sign=I.sign,this.layer=I.layer,this.mag=I.mag,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}}let v=t.split("e"),f=v.length-1;if(f===0){let w=parseFloat(t);if(isFinite(w))return this.fromNumber(w),o.fromStringCache.size>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}else if(f===1){let w=parseFloat(t);if(isFinite(w)&&w!==0)return this.fromNumber(w),o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}let u=t.split("e^");if(u.length===2){this.sign=1,u[0].charAt(0)=="-"&&(this.sign=-1);let w="";for(let I=0;I=43&&k<=57||k===101)w+=u[1].charAt(I);else return this.layer=parseFloat(w),this.mag=parseFloat(u[1].substr(I+1)),this.normalize(),o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}}if(f<1)return this.sign=0,this.layer=0,this.mag=0,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this;let h=parseFloat(v[0]);if(h===0)return this.sign=0,this.layer=0,this.mag=0,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this;let g=parseFloat(v[v.length-1]);if(f>=2){let w=parseFloat(v[v.length-2]);isFinite(w)&&(g*=Math.sign(w),g+=$t(w))}if(!isFinite(h))this.sign=v[0]==="-"?-1:1,this.layer=f,this.mag=g;else if(f===1)this.sign=Math.sign(h),this.layer=1,this.mag=g+Math.log10(Math.abs(h));else if(this.sign=Math.sign(h),this.layer=f,f===2){let w=o.mul(D(1,2,g),N(h));return this.sign=w.sign,this.layer=w.layer,this.mag=w.mag,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}else this.mag=g;return this.normalize(),o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}fromValue(t){return t instanceof o?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.NEGATIVE_INFINITY&&this.layer===Number.NEGATIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:ht(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:ht(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=ae?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):ht(this.m,t)+"e"+ht(this.e,t):this.layer===1?ht(this.m,t)+"e"+ht(this.e,t):this.layer<=ae?(this.sign===-1?"-":"")+"e".repeat(this.layer)+ht(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+ht(this.mag,t)}abs(){return Y(this.sign===0?0:1,this.layer,this.mag)}neg(){return Y(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?o.dZero:this.layer===0?D(this.sign,0,Math.round(this.mag)):this}floor(){return this.mag<0?this.sign===-1?o.dNegOne:o.dZero:this.sign===-1?this.neg().ceil().neg():this.layer===0?D(this.sign,0,Math.floor(this.mag)):this}ceil(){return this.mag<0?this.sign===1?o.dOne:o.dZero:this.sign===-1?this.neg().floor().neg():this.layer===0?D(this.sign,0,Math.ceil(this.mag)):this}trunc(){return this.mag<0?o.dZero:this.layer===0?D(this.sign,0,Math.trunc(this.mag)):this}add(t){let e=N(t);if(!Number.isFinite(this.layer))return this;if(!Number.isFinite(e.layer)||this.sign===0)return e;if(e.sign===0)return this;if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return Y(0,0,0);let r,i;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(o.cmpabs(this,e)>0?(r=this,i=e):(r=e,i=this),r.layer===0&&i.layer===0)return o.fromNumber(r.sign*r.mag+i.sign*i.mag);let n=r.layer*Math.sign(r.mag),s=i.layer*Math.sign(i.mag);if(n-s>=2)return r;if(n===0&&s===-1){if(Math.abs(i.mag-Math.log10(r.mag))>Ut)return r;{let c=Math.pow(10,Math.log10(r.mag)-i.mag),y=i.sign+r.sign*c;return D(Math.sign(y),1,i.mag+Math.log10(Math.abs(y)))}}if(n===1&&s===0){if(Math.abs(r.mag-Math.log10(i.mag))>Ut)return r;{let c=Math.pow(10,r.mag-Math.log10(i.mag)),y=i.sign+r.sign*c;return D(Math.sign(y),1,Math.log10(i.mag)+Math.log10(Math.abs(y)))}}if(Math.abs(r.mag-i.mag)>Ut)return r;{let c=Math.pow(10,r.mag-i.mag),y=i.sign+r.sign*c;return D(Math.sign(y),1,i.mag+Math.log10(Math.abs(y)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(N(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=N(t);if(!Number.isFinite(this.layer))return this;if(!Number.isFinite(e.layer))return e;if(this.sign===0||e.sign===0)return Y(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return Y(this.sign*e.sign,0,1);let r,i;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=this,i=e):(r=e,i=this),r.layer===0&&i.layer===0)return o.fromNumber(r.sign*i.sign*r.mag*i.mag);if(r.layer>=3||r.layer-i.layer>=2)return D(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return D(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return D(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let n=D(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(D(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return D(r.sign*i.sign,n.layer+1,n.sign*n.mag)}if(r.layer===2&&i.layer===2){let n=D(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(D(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return D(r.sign*i.sign,n.layer+1,n.sign*n.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=N(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?o.dNaN:this.layer===0?D(this.sign,0,1/this.mag):D(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=N(t).abs();if(e.eq(o.dZero))return o.dZero;let r=this.toNumber(),i=e.toNumber();return isFinite(r)&&isFinite(i)&&r!=0&&i!=0?new o(r%i):this.sub(e).eq(this)?o.dZero:e.sub(this).eq(e)?this:this.sign==-1?this.abs().mod(e).neg():this.sub(this.div(e).floor().mul(e))}modulo(t){return this.mod(t)}modular(t){return this.mod(t)}cmp(t){let e=N(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,i=e.mag>0?e.layer:-e.layer;return r>i?1:re.mag?1:this.mag0?e:this}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=N(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=N(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let i=this.mag,n=r.mag;return this.layer>r.layer&&(n=$t(n)),this.layer0?D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):D(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?o.dNaN:this.layer>0?D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):D(this.sign,0,Math.log10(this.mag))}log(t){return t=N(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?o.dNaN:this.layer===0&&t.layer===0?D(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):o.div(this.log10(),t.log10())}log2(){return this.sign<=0?o.dNaN:this.layer===0?D(this.sign,0,Math.log2(this.mag)):this.layer===1?D(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?D(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?o.dNaN:this.layer===0?D(this.sign,0,Math.log(this.mag)):this.layer===1?D(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?D(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=N(t),r=this,i=e;if(r.sign===0)return i.eq(0)?Y(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(i.sign===0)return Y(1,0,1);if(i.sign===1&&i.layer===0&&i.mag===1)return r;let n=r.absLog10().mul(i).pow10();return this.sign===-1?Math.abs(i.toNumber()%2)%2===1?n.neg():Math.abs(i.toNumber()%2)%2===0?n:o.dNaN:n}pow10(){if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return o.dNaN;let t=this;if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return D(1,0,e);if(t.sign===0)return o.dOne;t=Y(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?D(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?D(-t.sign,t.layer+1,-t.mag):o.dOne}pow_base(t){return N(t).pow(this)}root(t){let e=N(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?o.exp(o.mul(this,o.ln(this).sub(1))):o.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(Y(1,0,24)))return o.fromNumber(pr(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,i=t,n=12*i,s=1/n,c=e+s;if(c===e||(e=c,i=i*r,n=360*i,s=1/n,c=e-s,c===e))return o.exp(e);e=c,i=i*r,n=1260*i;let y=1/n;return e=e+y,i=i*r,n=1680*i,y=1/n,e=e-y,o.exp(e)}else return this.layer===1?o.exp(o.mul(this,o.ln(this).sub(1))):o.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?o.dOne:this.layer===0&&this.mag<=709.7?o.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?D(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?D(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):D(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return o.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return D(1,2,Math.log10(this.mag)-.3010299956639812);{let t=o.div(Y(this.sign,this.layer-1,this.mag),Y(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=Y(1,0,1),r=!1){if(t===1)return o.pow(this,e);if(t===0)return new o(e);if(this.eq(o.dOne))return o.dOne;if(this.eq(-1))return o.pow(this,e);if(t===Number.POSITIVE_INFINITY){let s=this.toNumber();if(s<=1.444667861009766&&s>=.06598803584531254){if(s>1.444667861009099)return o.fromNumber(Math.E);let c=o.ln(this).neg();return c.lambertw().div(c)}else return s>1.444667861009766?o.fromNumber(Number.POSITIVE_INFINITY):o.dNaN}if(this.eq(o.dZero)){let s=Math.abs((t+1)%2);return s>1&&(s=2-s),o.fromNumber(s)}if(t<0)return o.iteratedlog(e,this,-t,r);e=N(e);let i=t;t=Math.trunc(t);let n=i-t;if(this.gt(o.dZero)&&this.lte(1.444667861009766)&&(i>1e4||!r)){t=Math.min(1e4,t);for(let s=0;s1e4){let s=this.pow(e);return i<=1e4||Math.ceil(i)%2==0?e.mul(1-n).add(s.mul(n)):e.mul(n).add(s.mul(1-n))}return e}n!==0&&(e.eq(o.dOne)?this.gt(10)||r?e=this.pow(n):(e=o.fromNumber(o.tetrate_critical(this.toNumber(),n)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(n,r):e=e.layeradd(n,this,r));for(let s=0;s3)return Y(e.sign,e.layer+(t-s-1),e.mag);if(s>1e4)return e}return e}iteratedexp(t=2,e=Y(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return o.tetrate(t,-e,this,r);t=N(t);let i=o.fromDecimal(this),n=e;e=Math.trunc(e);let s=n-e;if(i.layer-t.layer>3){let c=Math.min(e,i.layer-t.layer-3);e-=c,i.layer-=c}for(let c=0;c1e4)return i}return s>0&&s<1&&(t.eq(10)?i=i.layeradd10(-s,r):i=i.layeradd(-s,t,r)),i}slog(t=10,e=100,r=!1){let i=.001,n=!1,s=!1,c=this.slog_internal(t,r).toNumber();for(let y=1;y1&&s!=l&&(n=!0),s=l,n?i/=2:i*=2,i=Math.abs(i)*(l?-1:1),c+=i,i===0)break}return o.fromNumber(c)}slog_internal(t=10,e=!1){if(t=N(t),t.lte(o.dZero)||t.eq(o.dOne))return o.dNaN;if(t.lt(o.dOne))return this.eq(o.dOne)?o.dZero:this.eq(o.dZero)?o.dNegOne:o.dNaN;if(this.mag<0||this.eq(o.dZero))return o.dNegOne;let r=0,i=o.fromDecimal(this);if(i.layer-t.layer>3){let n=i.layer-t.layer-3;r+=n,i.layer-=n}for(let n=0;n<100;++n)if(i.lt(o.dZero))i=o.pow(t,i),r-=1;else{if(i.lte(o.dOne))return e?o.fromNumber(r+i.toNumber()-1):o.fromNumber(r+o.slog_critical(t.toNumber(),i.toNumber()));r+=1,i=o.log(i,t)}return o.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:o.critical_section(t,e,gr)}static tetrate_critical(t,e){return o.critical_section(t,e,mr)}static critical_section(t,e,r,i=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let n=0,s=0;for(let y=0;yt){let p=(t-gt[y])/(gt[y+1]-gt[y]);n=r[y][Math.floor(e)]*(1-p)+r[y+1][Math.floor(e)]*p,s=r[y][Math.ceil(e)]*(1-p)+r[y+1][Math.ceil(e)]*p;break}let c=e-Math.floor(e);return n<=0||s<=0?n*(1-c)+s*c:Math.pow(t,Math.log(n)/Math.log(t)*(1-c)+Math.log(s)/Math.log(t)*c)}layeradd10(t,e=!1){t=o.fromValue_noAlloc(t).toNumber();let r=o.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let i=Math.trunc(t);t-=i,r.layer+=i}if(t<=-1){let i=Math.trunc(t);if(t-=i,r.layer+=i,r.layer<0)for(let n=0;n<100;++n){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let n=this.slog(e).toNumber()+t;return n>=0?o.tetrate(e,n,o.dOne,r):Number.isFinite(n)?n>=-1?o.log(o.tetrate(e,n+1,o.dOne,r),e):o.log(o.log(o.tetrate(e,n+2,o.dOne,r),e),e):o.dNaN}lambertw(){if(this.lt(-.3678794411710499))throw Error("lambertw is unimplemented for results less than -1, sorry!");if(this.mag<0)return o.fromNumber(ue(this.toNumber()));if(this.layer===0)return o.fromNumber(ue(this.sign*this.mag));if(this.layer===1)return le(this);if(this.layer===2)return le(this);if(this.layer>=3)return Y(this.sign,this.layer-1,this.mag);throw"Unhandled behavior in lambertw()"}ssqrt(){return this.linear_sroot(2)}linear_sroot(t){if(t==1)return this;if(this.eq(o.dInf))return o.dInf;if(!this.isFinite())return o.dNaN;if(t>0&&t<1)return this.root(t);if(t>-2&&t<-1)return o.fromNumber(t).add(2).pow(this.recip());if(t<=0)return o.dNaN;if(t==Number.POSITIVE_INFINITY){let e=this.toNumber();return evr?this.pow(this.recip()):o.dNaN}if(this.eq(1))return o.dOne;if(this.lt(0))return o.dNaN;if(this.lte("1ee-16"))return t%2==1?this:o.dNaN;if(this.gt(1)){let e=o.dTen;this.gte(o.tetrate(10,t,1,!0))&&(e=this.iteratedlog(10,t-1,!0)),t<=1&&(e=this.root(t));let r=o.dZero,i=e.layer,n=e.iteratedlog(10,i,!0),s=n,c=n.div(2),y=!0;for(;y;)c=r.add(n).div(2),o.iteratedexp(10,i,c,!0).tetrate(t,1,!0).gt(this)?n=c:r=c,c.eq(s)?y=!1:s=c;return o.iteratedexp(10,i,c,!0)}else{let e=1,r=D(1,10,1),i=D(1,10,1),n=D(1,10,1),s=D(1,1,-16),c=o.dZero,y=D(1,10,1),p=s.pow10().recip(),l=o.dZero,v=p,f=p,u=Math.ceil(t)%2==0,h=0,g=D(1,10,1),w=!1,I=o.dZero,k=!1;for(;e<4;){if(e==2){if(u)break;n=D(1,10,1),s=r,e=3,y=D(1,10,1),g=D(1,10,1)}for(w=!1;s.neq(n);){if(I=s,s.pow10().recip().tetrate(t,1,!0).eq(1)&&s.pow10().recip().lt(.4))p=s.pow10().recip(),v=s.pow10().recip(),f=s.pow10().recip(),l=o.dZero,h=-1,e==3&&(g=s);else if(s.pow10().recip().tetrate(t,1,!0).eq(s.pow10().recip())&&!u&&s.pow10().recip().lt(.4))p=s.pow10().recip(),v=s.pow10().recip(),f=s.pow10().recip(),l=o.dZero,h=0;else if(s.pow10().recip().tetrate(t,1,!0).eq(s.pow10().recip().mul(2).tetrate(t,1,!0)))p=s.pow10().recip(),v=o.dZero,f=p.mul(2),l=p,u?h=-1:h=0;else{for(c=s.mul(12e-17),p=s.pow10().recip(),v=s.add(c).pow10().recip(),l=p.sub(v),f=p.add(l);v.tetrate(t,1,!0).eq(p.tetrate(t,1,!0))||f.tetrate(t,1,!0).eq(p.tetrate(t,1,!0))||v.gte(p)||f.lte(p);)c=c.mul(2),v=s.add(c).pow10().recip(),l=p.sub(v),f=p.add(l);if((e==1&&f.tetrate(t,1,!0).gt(p.tetrate(t,1,!0))&&v.tetrate(t,1,!0).gt(p.tetrate(t,1,!0))||e==3&&f.tetrate(t,1,!0).lt(p.tetrate(t,1,!0))&&v.tetrate(t,1,!0).lt(p.tetrate(t,1,!0)))&&(g=s),f.tetrate(t,1,!0).lt(p.tetrate(t,1,!0)))h=-1;else if(u)h=1;else if(e==3&&s.gt_tolerance(r,1e-8))h=0;else{for(;v.tetrate(t,1,!0).eq_tolerance(p.tetrate(t,1,!0),1e-8)||f.tetrate(t,1,!0).eq_tolerance(p.tetrate(t,1,!0),1e-8)||v.gte(p)||f.lte(p);)c=c.mul(2),v=s.add(c).pow10().recip(),l=p.sub(v),f=p.add(l);f.tetrate(t,1,!0).sub(p.tetrate(t,1,!0)).lt(p.tetrate(t,1,!0).sub(v.tetrate(t,1,!0)))?h=0:h=1}}if(h==-1&&(k=!0),e==1&&h==1||e==3&&h!=0)if(n.eq(D(1,10,1)))s=s.mul(2);else{let m=!1;if(w&&(h==1&&e==1||h==-1&&e==3)&&(m=!0),s=s.add(n).div(2),m)break}else if(n.eq(D(1,10,1)))n=s,s=s.div(2);else{let m=!1;if(w&&(h==1&&e==1||h==-1&&e==3)&&(m=!0),n=n.sub(y),s=s.sub(y),m)break}if(n.sub(s).div(2).abs().gt(y.mul(1.5))&&(w=!0),y=n.sub(s).div(2).abs(),s.gt("1e18")||s.eq(I))break}if(s.gt("1e18")||!k||g==D(1,10,1))break;e==1?r=g:e==3&&(i=g),e++}n=r,s=D(1,1,-18);let F=s,a=o.dZero,S=!0;for(;S;)if(n.eq(D(1,10,1))?a=s.mul(2):a=n.add(s).div(2),o.pow(10,a).recip().tetrate(t,1,!0).gt(this)?s=a:n=a,a.eq(F)?S=!1:F=a,s.gt("1e18"))return o.dNaN;if(a.eq_tolerance(r,1e-15)){if(i.eq(D(1,10,1)))return o.dNaN;for(n=D(1,10,1),s=i,F=s,a=o.dZero,S=!0;S;)if(n.eq(D(1,10,1))?a=s.mul(2):a=n.add(s).div(2),o.pow(10,a).recip().tetrate(t,1,!0).gt(this)?s=a:n=a,a.eq(F)?S=!1:F=a,s.gt("1e18"))return o.dNaN;return a.pow10().recip()}else return a.pow10().recip()}}pentate(t=2,e=Y(1,0,1),r=!1){e=N(e);let i=t;t=Math.trunc(t);let n=i-t;n!==0&&(e.eq(o.dOne)?(++t,e=o.fromNumber(n)):this.eq(10)?e=e.layeradd10(n,r):e=e.layeradd(n,this,r));for(let s=0;s10)return e}return e}sin(){return this.mag<0?this:this.layer===0?o.fromNumber(Math.sin(this.sign*this.mag)):Y(0,0,0)}cos(){return this.mag<0?o.dOne:this.layer===0?o.fromNumber(Math.cos(this.sign*this.mag)):Y(0,0,0)}tan(){return this.mag<0?this:this.layer===0?o.fromNumber(Math.tan(this.sign*this.mag)):Y(0,0,0)}asin(){return this.mag<0?this:this.layer===0?o.fromNumber(Math.asin(this.sign*this.mag)):Y(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?o.fromNumber(Math.acos(this.toNumber())):this.layer===0?o.fromNumber(Math.acos(this.sign*this.mag)):Y(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?this:this.layer===0?o.fromNumber(Math.atan(this.sign*this.mag)):o.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return o.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return o.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?Y(Number.NaN,Number.NaN,Number.NaN):o.ln(this.add(1).div(o.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?this:this.root(o.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,i){return new o(t).add(new o(e).minus(new o(t)).times(new o(r)).times(new o(i)))}clone(){return this}static clone(t){return o.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=i.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(i=i.sub(t).div(e).add(t))),i}static softcap(t,e,r,i){return new o(t).softcap(e,r,i)}scale(t,e,r,i=!1){t=new o(t),e=new o(e);let n=this.clone();return n.gte(t)&&([0,"pow"].includes(r)&&(n=i?n.mul(t.pow(e.sub(1))).root(e):n.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(n=i?n.div(t).max(1).log(e).add(t):o.pow(e,n.sub(t)).mul(t))),n}static scale(t,e,r,i,n=!1){return new o(t).scale(e,r,i,n)}format(t=2,e=9,r="mixed_sc"){return pt.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return pt.format(new o(t),e,r,i)}formatST(t=2,e=9,r="st"){return pt.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return pt.format(new o(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return pt.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,n){return pt.formatGain(new o(t),e,r,i,n)}toRoman(t=5e3){t=new o(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),i={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},n="";for(let s of Object.keys(i)){let c=Math.floor(r/i[s]);r-=c*i[s],n+=s.repeat(c)}return n}static toRoman(t,e){return new o(t).toRoman(e)}static random(t=0,e=1){return t=new o(t),e=new o(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new o(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new o(Math.random()).lt(t)}};o.dZero=Y(0,0,0),o.dOne=Y(1,0,1),o.dNegOne=Y(-1,0,1),o.dTwo=Y(1,0,2),o.dTen=Y(1,0,10),o.dNaN=Y(Number.NaN,Number.NaN,Number.NaN),o.dInf=Y(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),o.dNegInf=Y(-1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),o.dNumberMax=D(1,0,Number.MAX_VALUE),o.dNumberMin=D(1,0,Number.MIN_VALUE),o.fromStringCache=new jt(fr),lt([Et()],o.prototype,"sign",2),lt([Et()],o.prototype,"mag",2),lt([Et()],o.prototype,"layer",2),o=lt([rr()],o);var{formats:pt,FORMATS:yr}=nr(o);o.formats=pt;var L=(()=>{let t=e=>new o(e);return Object.getOwnPropertyNames(o).filter(e=>!Object.getOwnPropertyNames(class{}).includes(e)).forEach(e=>{t[e]=o[e]}),t})(),Nt=class{get desc(){return this.description}get description(){return this.descriptionFn()}constructor(t){this.id=t.id,this.name=t.name??"",this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>"",this.value=t.value,this.order=t.order??99}},zt=class{constructor(t=1,e){this.addBoost=this.setBoost.bind(this),e=e?Array.isArray(e)?e:[e]:void 0,this.baseEffect=L(t),this.boostArray=[],e&&e.forEach(r=>{this.boostArray.push(new Nt(r))})}getBoosts(t,e){let r=[],i=[];for(let n=0;nf),l=n,v=this.getBoosts(s,!0);v[0][0]?this.boostArray[v[1][0]]=new Nt({id:s,name:c,description:y,value:p,order:l}):this.boostArray.push(new Nt({id:s,name:c,description:y,value:p,order:l}))}else{t=Array.isArray(t)?t:[t];for(let s of t){let c=this.getBoosts(s.id,!0);c[0][0]?this.boostArray[c[1][0]]=new Nt(s):this.boostArray.push(new Nt(s))}}}calculate(t=this.baseEffect){let e=L(t),r=this.boostArray;r=r.sort((i,n)=>i.order-n.order);for(let i of r)e=i.value(e);return e}},zr=ot(ct()),xt=35,fe=.001;function ce(t,e,r,i){i=Object.assign({},{verbose:!1,mode:"geometric"},i),t=L(t),e=L(e),r=L(r);let n,s;return i.mode==="geometric"?(n=t.sub(e).abs().div(t.abs().add(e.abs()).div(2)),s=n.lte(r)):(n=t.sub(e).abs(),s=n.lte(r)),(i.verbose===!0||i.verbose==="onlyOnFail"&&!s)&&console.log({a:t,b:e,tolerance:r,config:i,diff:n,result:s}),s}function Yt(t,e,r="geometric",i=xt,n=fe){let s=L(1),c=L(e);if(t(c).eq(0))return{value:L(0),lowerBound:L(0),upperBound:L(0)};if(t(c).lt(e))return console.warn("The function is not monotonically increasing. (f(n) < n)"),{value:c,lowerBound:c,upperBound:c};for(let p=0;pe.cost(g.add(r)),u=L.min(i,Yt(f,t,n,s).value.floor()),h=L(0);return[u,h]}let p=Yt(f=>Zt(e.cost,f,r),t,n,s).value.floor().min(r.add(y).sub(1)),l=Zt(e.cost,p,r);return[p.sub(r).add(1).max(0),l]}function Lt(t){return t=L(t),`${t.sign}/${t.mag}/${t.layer}`}function ge(t,e){return`sum/${Lt(t)}/${Lt(e)}}`}function Ht(t){return`el/${Lt(t)}`}var vt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?L(t.level):L(1)}};lt([Et()],vt.prototype,"id",2),lt([Ft(()=>o)],vt.prototype,"level",2);var pe=class je{static{this.cacheSize=63}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn()}get level(){return((this??{data:{level:L(1)}}).data??{level:L(1)}).level}set level(e){this.data.level=L(e)}constructor(e,r,i){let n=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>n,this.cache=new jt(i??je.cacheSize),this.id=e.id,this.name=e.name??e.id,this.descriptionFn=e.description?typeof e.description=="function"?e.description:()=>e.description:()=>"",this.cost=e.cost,this.costBulk=e.costBulk,this.maxLevel=e.maxLevel,this.effect=e.effect,this.el=e.el,this.defaultLevel=e.level??L(1)}getCached(e,r,i){return e==="sum"?this.cache.get(ge(r,i??L(0))):this.cache.get(Ht(r))}setCached(e,r,i,n){let s=e==="sum"?{id:this.id,el:!1,start:L(r),end:L(i),cost:L(n)}:{id:this.id,el:!0,level:L(r),cost:L(i)};return e==="sum"?this.cache.set(ge(r,i),s):this.cache.set(Ht(r),s),s}},Yr=ot(ct()),yt=class{constructor(){this.value=L(0),this.upgrades={}}};lt([Ft(()=>o)],yt.prototype,"value",2),lt([Ft(()=>vt)],yt.prototype,"upgrades",2);var ve=class{get pointer(){return this.pointerFn()}get value(){return this.pointer.value}set value(t){this.pointer.value=t}constructor(t=new yt,e,r={defaultVal:L(0),defaultBoost:L(1)}){this.defaultVal=r.defaultVal,this.defaultBoost=r.defaultBoost,this.pointerFn=typeof t=="function"?t:()=>t,this.boost=new zt(this.defaultBoost),this.pointer.value=this.defaultVal,this.upgrades={},e&&this.addUpgrade(e)}onLoadData(){for(let t of Object.values(this.upgrades))t.effect?.(t.level,t,this)}reset(t=!0,e=!0,r=!0){if(t&&(this.value=this.defaultVal),e)for(let i of Object.values(this.upgrades))i.level=L(i.defaultLevel),r&&i.effect?.(i.level,i,this)}gain(t=1e3){let e=this.boost.calculate().mul(L(t).div(1e3));return this.pointer.value=this.pointer.value.add(e),e}pointerAddUpgrade(t){let e=new vt(t);return this.pointer.upgrades[e.id]=e,e}pointerGetUpgrade(t){return this.pointer.upgrades[t]??null}getUpgrade(t){return this.upgrades[t]??null}addUpgrade(t,e=!0){Array.isArray(t)||(t=[t]);let r={};for(let i of t){let n=this.pointerAddUpgrade(i),s=new pe(i,()=>this.pointerGetUpgrade(i.id));s.effect&&e&&s.effect(s.level,s,this),r[i.id]=s,this.upgrades[i.id]=s}return Object.values(r)}updateUpgrade(t,e){let r=this.getUpgrade(t);r!==null&&(r.name=e.name??r.name,r.cost=e.cost??r.cost,r.maxLevel=e.maxLevel??r.maxLevel,r.effect=e.effect??r.effect)}calculateUpgrade(t,e=1/0,r,i){let n=this.getUpgrade(t);return n===null?(console.warn(`Upgrade "${t}" not found.`),[L(0),L(0)]):(e=n.level.add(e),n.maxLevel!==void 0&&(e=L.min(e,n.maxLevel)),me(this.value,n,n.level,e,r,i))}getNextCost(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),L(0);let s=this.calculateUpgrade(t,e,r,i)[0];return n.cost(n.level.add(s))}getNextCostMax(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),L(0);let s=this.calculateUpgrade(t,e,r,i);return n.cost(n.level.add(s[0])).add(s[1])}buyUpgrade(t,e,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),!1;let[s,c]=this.calculateUpgrade(t,e,r,i);return s.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(c),n.level=n.level.add(s),n.effect?.(n.level,n,this),!0)}},Zr=ot(ct()),kt=class{constructor(t=0){this.value=L(t)}};lt([Ft(()=>o)],kt.prototype,"value",2);var ye=class{get pointer(){return this.pointerFn()}constructor(t,e=!0,r=0){this.initial=L(r),t??=new kt(this.initial),this.pointerFn=typeof t=="function"?t:()=>t,this.boost=e?new zt(this.initial):null}update(){console.warn("AttributeStatic.update is deprecated and will be removed in the future. The value is automatically updated when accessed."),this.boost&&(this.pointer.value=this.boost.calculate())}get value(){return this.boost&&(this.pointer.value=this.boost.calculate()),this.pointer.value}set value(t){if(this.boost)throw new Error("Cannot set value of attributeStatic when boost is enabled.");this.pointer.value=t}},be=class{constructor(t,e,r){this.x=t,this.y=e,this.properties=r??{}}setValue(t,e){return this.properties[t]=e,e}getValue(t){return this.properties[t]}},wr=class{constructor(t,e,r){this.xSize=t,this.ySize=e,this.cells=[];for(let i=0;iPt,DataManager:()=>Ae,EventManager:()=>_e,EventTypes:()=>Ne,Game:()=>Sr,GameAttribute:()=>Ie,GameCurrency:()=>Oe,GameReset:()=>Ce,KeyManager:()=>Me,gameDefaultConfig:()=>Te,keys:()=>Nr});var Hr=ot(ct()),Pt=class{constructor(t){this.configOptionTemplate=t}parse(t){if(typeof t>"u")return this.configOptionTemplate;function e(r,i){for(let n in i)typeof r[n]>"u"?r[n]=i[n]:typeof r[n]=="object"&&typeof i[n]=="object"&&!Array.isArray(r[n])&&!Array.isArray(i[n])&&(r[n]=e(r[n],i[n]));return r}return e(t,this.configOptionTemplate)}get options(){return this.configOptionTemplate}},Mr={autoAddInterval:!0,fps:30},Nr="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ".split("").concat(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]),Me=class Ge{constructor(e){if(this.addKeys=this.addKey.bind(this),this.keysPressed=[],this.binds=[],this.tickers=[],this.config=Ge.configManager.parse(e),this.config.autoAddInterval){let r=this.config.fps?this.config.fps:30;this.tickerInterval=setInterval(()=>{for(let i of this.tickers)i(1e3/r)},1e3/r)}typeof document>"u"||(this.tickers.push(r=>{for(let i of this.binds)(typeof i.onDownContinuous<"u"||typeof i.fn<"u")&&this.isPressing(i.id)&&(i.onDownContinuous?.(r),i.fn?.(r))}),document.addEventListener("keydown",r=>{this.logKey(r,!0),this.onAll("down",r.key)}),document.addEventListener("keyup",r=>{this.logKey(r,!1),this.onAll("up",r.key)}),document.addEventListener("keypress",r=>{this.onAll("press",r.key)}))}static{this.configManager=new Pt(Mr)}changeFps(e){this.config.fps=e,this.tickerInterval&&(clearInterval(this.tickerInterval),this.tickerInterval=setInterval(()=>{for(let r of this.tickers)r(1e3/e)},1e3/e))}logKey(e,r){let i=e.key;r&&!this.keysPressed.includes(i)?this.keysPressed.push(i):!r&&this.keysPressed.includes(i)&&this.keysPressed.splice(this.keysPressed.indexOf(i),1)}onAll(e,r){for(let i of this.binds)if(i.key===r)switch(e){case"down":i.onDown?.();break;case"press":default:i.onPress?.();break;case"up":i.onUp?.();break}}isPressing(e){for(let r of this.binds)if(r.id===e)return this.keysPressed.includes(r.key);return!1}getBind(e){return this.binds.find(r=>r.id===e)}addKey(e,r,i){e=typeof e=="string"?[{id:e,name:e,key:r??"",fn:i}]:e,e=Array.isArray(e)?e:[e];for(let n of e){n.id=n.id??n.name;let s=this.getBind(n.id);if(s){Object.assign(s,n);continue}this.binds.push(n)}}},Ne=(t=>(t.interval="interval",t.timeout="timeout",t))(Ne||{}),_r={autoAddInterval:!0,fps:30},_e=class Ue{constructor(e){if(this.addEvent=this.setEvent.bind(this),this.config=Ue.configManager.parse(e),this.events={},this.config.autoAddInterval){let r=this.config.fps??30;this.tickerInterval=setInterval(()=>{this.tickerFunction()},1e3/r)}}static{this.configManager=new Pt(_r)}tickerFunction(){let e=Date.now();for(let r of Object.values(this.events))switch(r.type){case"interval":if(e-r.intervalLast>=r.delay){let i=e-r.intervalLast;r.callbackFn(i),r.intervalLast=e}break;case"timeout":{let i=e-r.timeCreated;e-r.timeCreated>=r.delay&&(r.callbackFn(i),delete this.events[r.name])}break}}changeFps(e){this.config.fps=e,this.tickerInterval&&(clearInterval(this.tickerInterval),this.tickerInterval=setInterval(()=>{this.tickerFunction()},1e3/e))}timeWarp(e){for(let r of Object.values(this.events))switch(r.type){case"interval":r.intervalLast-=e;break;case"timeout":r.timeCreated-=e;break}}setEvent(e,r,i,n){this.events[e]=(()=>{switch(r){case"interval":return{name:e,type:r,delay:typeof i=="number"?i:i.toNumber(),callbackFn:n,timeCreated:Date.now(),intervalLast:Date.now()};case"timeout":default:return{name:e,type:r,delay:typeof i=="number"?i:i.toNumber(),callbackFn:n,timeCreated:Date.now()}}})()}removeEvent(e){delete this.events[e]}},Vr=ot(ct()),Se=ot(He()),Vt=ot(Xe()),Ae=class{constructor(t){this.data={},this.static={},this.eventsOnLoad=[],this.gameRef=typeof t=="function"?t():t}addEventOnLoad(t){this.eventsOnLoad.push(t)}setData(t,e){typeof this.data[t]>"u"&&this.normalData&&console.warn("After initializing data, you should not add new properties to data."),this.data[t]=e;let r=()=>this.data;return{get value(){return r()[t]},set value(i){r()[t]=i},setValue(i){r()[t]=i}}}getData(t){return this.data[t]}setStatic(t,e){return typeof this.static[t]>"u"&&this.normalData&&console.warn("After initializing data, you should not add new properties to staticData."),this.static[t]=e,this.static[t]}getStatic(t){return this.static[t]}init(){this.normalData=this.data,this.normalDataPlain=Gt(this.data)}compileDataRaw(t=this.data){let e=Gt(t),r=(0,Vt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(e)}`),i;try{i="8.3.0"}catch{i="8.3.0"}return[{hash:r,game:{title:this.gameRef.config.name.title,id:this.gameRef.config.name.id,version:this.gameRef.config.name.version},emath:{version:i}},e]}compileData(t=this.data){let e=JSON.stringify(this.compileDataRaw(t));return(0,Se.compressToBase64)(e)}decompileData(t=window.localStorage.getItem(`${this.gameRef.config.name.id}-data`)){if(!t)return null;let e;try{return e=JSON.parse((0,Se.decompressFromBase64)(t)),e}catch(r){if(r instanceof SyntaxError)console.error(`Failed to decompile data (corrupted) "${t}":`,r);else throw r;return null}}validateData(t){let[e,r]=t;if(typeof e=="string")return(0,Vt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`)===e;let i=e.hash,n=(0,Vt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`);return i===n}resetData(t=!1){if(!this.normalData)throw new Error("dataManager.resetData(): You must call init() before writing to data.");this.data=this.normalData,this.saveData(),t&&window.location.reload()}saveData(t=this.compileData()){if(!t)throw new Error("dataManager.saveData(): Data to save is empty.");if(!window.localStorage)throw new Error("dataManager.saveData(): Local storage is not supported. You can use compileData() instead to implement a custom save system.");window.localStorage.setItem(`${this.gameRef.config.name.id}-data`,t)}exportData(){let t=this.compileData();if(prompt("Download save data?:",t)!=null){let e=new Blob([t],{type:"text/plain"}),r=document.createElement("a");r.href=URL.createObjectURL(e),r.download=`${this.gameRef.config.name.id}-data.txt`,r.textContent=`Download ${this.gameRef.config.name.id}-data.txt file`,document.body.appendChild(r),r.click(),document.body.removeChild(r)}}parseData(t=this.decompileData(),e=!0){if((!this.normalData||!this.normalDataPlain)&&e)throw new Error("dataManager.parseData(): You must call init() before writing to data.");if(!t)return null;let[,r]=t;function i(v){return typeof v=="object"&&v?.constructor===Object}let n=(v,f)=>Object.prototype.hasOwnProperty.call(v,f);function s(v,f,u){if(!v||!f||!u)throw new Error("dataManager.deepMerge(): Missing arguments.");let h=u;for(let g in v)if(n(v,g)&&!n(u,g)&&(h[g]=v[g]),f[g]instanceof yt){let w=v[g],I=u[g];if(Array.isArray(I.upgrades)){let k=I.upgrades;I.upgrades={};for(let F of k)I.upgrades[F.id]=F}I.upgrades={...w.upgrades,...I.upgrades},h[g]=I}else i(v[g])&&i(u[g])&&(h[g]=s(v[g],f[g],u[g]));return h}let c=e?s(this.normalDataPlain,this.normalData,r):r,y=Object.getOwnPropertyNames(new vt({id:"",level:L(0)}));function p(v,f){let u=se(v,f);if(u instanceof yt)for(let h in u.upgrades){let g=u.upgrades[h];if(!g||!y.every(w=>Object.getOwnPropertyNames(g).includes(w))){delete u.upgrades[h];continue}u.upgrades[h]=se(vt,g)}if(!u)throw new Error(`Failed to convert ${v.name} to class instance.`);return u}function l(v,f){if(!v||!f)throw new Error("dataManager.plainToInstanceRecursive(): Missing arguments.");let u=f;for(let h in v){if(f[h]===void 0){console.warn(`Missing property "${h}" in loaded data.`);continue}if(!i(f[h]))continue;let g=v[h].constructor;if(g===Object){u[h]=l(v[h],f[h]);continue}u[h]=p(g,f[h])}return u}return c=l(this.normalData,c),c}loadData(t=this.decompileData()){if(t=typeof t=="string"?this.decompileData(t):t,!t)return null;let e=this.validateData([t[0],Gt(t[1])]),r=this.parseData(t);if(!r)return null;this.data=r;for(let i of this.eventsOnLoad)i();return e}},Oe=class{get data(){return this.dataPointer()}get static(){return this.staticPointer()}constructor(t,e,r,i){this.dataPointer=typeof t=="function"?t:()=>t,this.staticPointer=typeof e=="function"?e:()=>e,this.game=r,this.name=i,this.game.dataManager.addEventOnLoad(()=>{this.static.onLoadData()})}get value(){return this.data.value}},Ie=class{constructor(t,e,r){this.data=typeof t=="function"?t():t,this.static=typeof e=="function"?e():e,this.game=r}get value(){return this.static.value}set value(t){this.data.value=t}},Ce=class{constructor(t,e){this.currenciesToReset=Array.isArray(t)?t:[t],this.extender=Array.isArray(e)?e:e?[e]:[],this.id=Symbol()}reset(){this.onReset?.(this),this.currenciesToReset.forEach(t=>{t.static.reset()}),this.extender.forEach(t=>{t.id!==this.id&&t.reset()})}},Te={mode:"production",name:{title:"",id:"",version:"0.0.0"},settings:{framerate:30},initIntervalBasedManagers:!0},Sr=class $e{static{this.configManager=new Pt(Te)}constructor(e){this.config=$e.configManager.parse(e),this.dataManager=new Ae(this),this.keyManager=new Me({autoAddInterval:this.config.initIntervalBasedManagers,fps:this.config.settings.framerate}),this.eventManager=new _e({autoAddInterval:this.config.initIntervalBasedManagers,fps:this.config.settings.framerate}),this.tickers=[]}init(){this.dataManager.init()}changeFps(e){this.keyManager.changeFps(e),this.eventManager.changeFps(e)}addCurrency(e,r=[]){return this.dataManager.setData(e,{currency:new yt}),this.dataManager.setStatic(e,{currency:new ve(()=>this.dataManager.getData(e).currency,r)}),new Oe(()=>this.dataManager.getData(e).currency,()=>this.dataManager.getStatic(e).currency,this,e)}addAttribute(e,r=!0,i=0){return this.dataManager.setData(e,new kt(i)),this.dataManager.setStatic(e,new ye(this.dataManager.getData(e),r,i)),new Ie(this.dataManager.getData(e),this.dataManager.getStatic(e),this)}addReset(e,r){return new Ce(e,r)}},Ar={...ee,...we};if(typeof at.exports=="object"&&typeof At=="object"){var Or=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,n)&&n!==r&&Object.defineProperty(t,n,{get:()=>e[n],enumerable:!(i=Object.getOwnPropertyDescriptor(e,n))||i.enumerable});return t};at.exports=Or(at.exports,At)}return at.exports}); +"use strict";(function(At,at){var Ct=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],at);else if(typeof module=="object"&&module.exports)module.exports=at();else{var ft=at(),Et=Ct?exports:At;for(var Ot in ft)Et[Ot]=ft[Ot]}})(typeof self<"u"?self:exports,()=>{var At={},at={exports:At},Ct=Object.create,ft=Object.defineProperty,Et=Object.getOwnPropertyDescriptor,Ot=Object.getOwnPropertyNames,Ue=Object.getPrototypeOf,$e=Object.prototype.hasOwnProperty,bt=(t,e)=>function(){return e||(0,t[Ot(t)[0]])((e={exports:{}}).exports,e),e.exports},Dt=(t,e)=>{for(var r in e)ft(t,r,{get:e[r],enumerable:!0})},Xt=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ot(e))!$e.call(t,n)&&n!==r&&ft(t,n,{get:()=>e[n],enumerable:!(i=Et(e,n))||i.enumerable});return t},ot=(t,e,r)=>(r=t!=null?Ct(Ue(t)):{},Xt(e||!t||!t.__esModule?ft(r,"default",{value:t,enumerable:!0}):r,t)),ze=t=>Xt(ft({},"__esModule",{value:!0}),t),lt=(t,e,r,i)=>{for(var n=i>1?void 0:i?Et(e,r):e,s=t.length-1,c;s>=0;s--)(c=t[s])&&(n=(i?c(e,r,n):c(n))||n);return i&&n&&ft(e,r,n),n},ct=bt({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var i=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:p(),n=s(e);typeof i.Reflect<"u"&&(n=s(i.Reflect,n)),r(n,i),typeof i.Reflect>"u"&&(i.Reflect=e);function s(l,v){return function(f,u){Object.defineProperty(l,f,{configurable:!0,writable:!0,value:u}),v&&v(f,u)}}function c(){try{return Function("return this;")()}catch{}}function y(){try{return(0,eval)("(function() { return this; })()")}catch{}}function p(){return c()||y()}})(function(r,i){var n=Object.prototype.hasOwnProperty,s=typeof Symbol=="function",c=s&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",y=s&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",p=typeof Object.create=="function",l={__proto__:[]}instanceof Array,v=!p&&!l,f={create:p?function(){return Wt(Object.create(null))}:l?function(){return Wt({__proto__:null})}:function(){return Wt({})},has:v?function(d,b){return n.call(d,b)}:function(d,b){return b in d},get:v?function(d,b){return n.call(d,b)?d[b]:void 0}:function(d,b){return d[b]}},u=Object.getPrototypeOf(Function),h=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:Pr(),g=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:qr(),w=typeof WeakMap=="function"?WeakMap:Br(),I=s?Symbol.for("@reflect-metadata:registry"):void 0,L=xr(),F=Lr(L);function a(d,b,O,C){if(j(O)){if(!Te(d))throw new TypeError;if(!Fe(b))throw new TypeError;return tt(d,b)}else{if(!Te(d))throw new TypeError;if(!J(b))throw new TypeError;if(!J(C)&&!j(C)&&!_t(C))throw new TypeError;return _t(C)&&(C=void 0),O=ut(O),nt(d,b,O,C)}}r("decorate",a);function S(d,b){function O(C,R){if(!J(C))throw new TypeError;if(!j(R)&&!Tr(R))throw new TypeError;Pt(d,b,C,R)}return O}r("metadata",S);function m(d,b,O,C){if(!J(O))throw new TypeError;return j(C)||(C=ut(C)),Pt(d,b,O,C)}r("defineMetadata",m);function A(d,b,O){if(!J(b))throw new TypeError;return j(O)||(O=ut(O)),W(d,b,O)}r("hasMetadata",A);function _(d,b,O){if(!J(b))throw new TypeError;return j(O)||(O=ut(O)),Z(d,b,O)}r("hasOwnMetadata",_);function M(d,b,O){if(!J(b))throw new TypeError;return j(O)||(O=ut(O)),X(d,b,O)}r("getMetadata",M);function E(d,b,O){if(!J(b))throw new TypeError;return j(O)||(O=ut(O)),dt(d,b,O)}r("getOwnMetadata",E);function T(d,b){if(!J(d))throw new TypeError;return j(b)||(b=ut(b)),qt(d,b)}r("getMetadataKeys",T);function G(d,b){if(!J(d))throw new TypeError;return j(b)||(b=ut(b)),Bt(d,b)}r("getOwnMetadataKeys",G);function H(d,b,O){if(!J(b))throw new TypeError;if(j(O)||(O=ut(O)),!J(b))throw new TypeError;j(O)||(O=ut(O));var C=It(b,O,!1);return j(C)?!1:C.OrdinaryDeleteMetadata(d,b,O)}r("deleteMetadata",H);function tt(d,b){for(var O=d.length-1;O>=0;--O){var C=d[O],R=C(b);if(!j(R)&&!_t(R)){if(!Fe(R))throw new TypeError;b=R}}return b}function nt(d,b,O,C){for(var R=d.length-1;R>=0;--R){var Q=d[R],et=Q(b,O,C);if(!j(et)&&!_t(et)){if(!J(et))throw new TypeError;C=et}}return C}function W(d,b,O){var C=Z(d,b,O);if(C)return!0;var R=Vt(b);return _t(R)?!1:W(d,R,O)}function Z(d,b,O){var C=It(b,O,!1);return j(C)?!1:Ee(C.OrdinaryHasOwnMetadata(d,b,O))}function X(d,b,O){var C=Z(d,b,O);if(C)return dt(d,b,O);var R=Vt(b);if(!_t(R))return X(d,R,O)}function dt(d,b,O){var C=It(b,O,!1);if(!j(C))return C.OrdinaryGetOwnMetadata(d,b,O)}function Pt(d,b,O,C){var R=It(O,C,!0);R.OrdinaryDefineOwnMetadata(d,b,O,C)}function qt(d,b){var O=Bt(d,b),C=Vt(d);if(C===null)return O;var R=qt(C,b);if(R.length<=0)return O;if(O.length<=0)return R;for(var Q=new g,et=[],$=0,x=O;$=0&&x=this._keys.length?(this._index=-1,this._keys=b,this._values=b):this._index++,{value:k,done:!1}}return{value:void 0,done:!0}},$.prototype.throw=function(x){throw this._index>=0&&(this._index=-1,this._keys=b,this._values=b),x},$.prototype.return=function(x){return this._index>=0&&(this._index=-1,this._keys=b,this._values=b),{value:x,done:!0}},$}(),C=function(){function $(){this._keys=[],this._values=[],this._cacheKey=d,this._cacheIndex=-2}return Object.defineProperty($.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),$.prototype.has=function(x){return this._find(x,!1)>=0},$.prototype.get=function(x){var k=this._find(x,!1);return k>=0?this._values[k]:void 0},$.prototype.set=function(x,k){var q=this._find(x,!0);return this._values[q]=k,this},$.prototype.delete=function(x){var k=this._find(x,!1);if(k>=0){for(var q=this._keys.length,B=k+1;B>>8,f[u*2+1]=g%256}return f},decompressFromUint8Array:function(l){if(l==null)return p.decompress(l);for(var v=new Array(l.length/2),f=0,u=v.length;f>1}else{for(h=1,u=0;u>1}a--,a==0&&(a=Math.pow(2,m),m++),delete w[F]}else for(h=g[F],u=0;u>1;a--,a==0&&(a=Math.pow(2,m),m++),g[L]=S++,F=String(I)}if(F!==""){if(Object.prototype.hasOwnProperty.call(w,F)){if(F.charCodeAt(0)<256){for(u=0;u>1}else{for(h=1,u=0;u>1}a--,a==0&&(a=Math.pow(2,m),m++),delete w[F]}else for(h=g[F],u=0;u>1;a--,a==0&&(a=Math.pow(2,m),m++)}for(h=2,u=0;u>1;for(;;)if(_=_<<1,M==v-1){A.push(f(_));break}else M++;return A.join("")},decompress:function(l){return l==null?"":l==""?null:p._decompress(l.length,32768,function(v){return l.charCodeAt(v)})},_decompress:function(l,v,f){var u=[],h,g=4,w=4,I=3,L="",F=[],a,S,m,A,_,M,E,T={val:f(0),position:v,index:1};for(a=0;a<3;a+=1)u[a]=a;for(m=0,_=Math.pow(2,2),M=1;M!=_;)A=T.val&T.position,T.position>>=1,T.position==0&&(T.position=v,T.val=f(T.index++)),m|=(A>0?1:0)*M,M<<=1;switch(h=m){case 0:for(m=0,_=Math.pow(2,8),M=1;M!=_;)A=T.val&T.position,T.position>>=1,T.position==0&&(T.position=v,T.val=f(T.index++)),m|=(A>0?1:0)*M,M<<=1;E=i(m);break;case 1:for(m=0,_=Math.pow(2,16),M=1;M!=_;)A=T.val&T.position,T.position>>=1,T.position==0&&(T.position=v,T.val=f(T.index++)),m|=(A>0?1:0)*M,M<<=1;E=i(m);break;case 2:return""}for(u[3]=E,S=E,F.push(E);;){if(T.index>l)return"";for(m=0,_=Math.pow(2,I),M=1;M!=_;)A=T.val&T.position,T.position>>=1,T.position==0&&(T.position=v,T.val=f(T.index++)),m|=(A>0?1:0)*M,M<<=1;switch(E=m){case 0:for(m=0,_=Math.pow(2,8),M=1;M!=_;)A=T.val&T.position,T.position>>=1,T.position==0&&(T.position=v,T.val=f(T.index++)),m|=(A>0?1:0)*M,M<<=1;u[w++]=i(m),E=w-1,g--;break;case 1:for(m=0,_=Math.pow(2,16),M=1;M!=_;)A=T.val&T.position,T.position>>=1,T.position==0&&(T.position=v,T.val=f(T.index++)),m|=(A>0?1:0)*M,M<<=1;u[w++]=i(m),E=w-1,g--;break;case 2:return F.join("")}if(g==0&&(g=Math.pow(2,I),I++),u[E])L=u[E];else if(E===w)L=S+S.charAt(0);else return null;F.push(L),u[w++]=S+L.charAt(0),g--,S=L,g==0&&(g=Math.pow(2,I),I++)}}};return p}();typeof define=="function"&&define.amd?define(function(){return r}):typeof e<"u"&&e!=null?e.exports=r:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return r})}}),Ze=bt({"node_modules/crypt/crypt.js"(t,e){(function(){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i={rotl:function(n,s){return n<>>32-s},rotr:function(n,s){return n<<32-s|n>>>s},endian:function(n){if(n.constructor==Number)return i.rotl(n,8)&16711935|i.rotl(n,24)&4278255360;for(var s=0;s0;n--)s.push(Math.floor(Math.random()*256));return s},bytesToWords:function(n){for(var s=[],c=0,y=0;c>>5]|=n[c]<<24-y%32;return s},wordsToBytes:function(n){for(var s=[],c=0;c>>5]>>>24-c%32&255);return s},bytesToHex:function(n){for(var s=[],c=0;c>>4).toString(16)),s.push((n[c]&15).toString(16));return s.join("")},hexToBytes:function(n){for(var s=[],c=0;c>>6*(3-p)&63)):s.push("=");return s.join("")},base64ToBytes:function(n){n=n.replace(/[^A-Z0-9+\/]/ig,"");for(var s=[],c=0,y=0;c>>6-y*2);return s}};e.exports=i})()}}),Jt=bt({"node_modules/charenc/charenc.js"(t,e){var r={utf8:{stringToBytes:function(i){return r.bin.stringToBytes(unescape(encodeURIComponent(i)))},bytesToString:function(i){return decodeURIComponent(escape(r.bin.bytesToString(i)))}},bin:{stringToBytes:function(i){for(var n=[],s=0;s>>24)&16711935|(l[w]<<24|l[w]>>>8)&4278255360;l[v>>>5]|=128<>>9<<4)+14]=v;for(var I=c._ff,L=c._gg,F=c._hh,a=c._ii,w=0;w>>0,u=u+m>>>0,h=h+A>>>0,g=g+_>>>0}return r.endian([f,u,h,g])};c._ff=function(y,p,l,v,f,u,h){var g=y+(p&l|~p&v)+(f>>>0)+h;return(g<>>32-u)+p},c._gg=function(y,p,l,v,f,u,h){var g=y+(p&v|l&~v)+(f>>>0)+h;return(g<>>32-u)+p},c._hh=function(y,p,l,v,f,u,h){var g=y+(p^l^v)+(f>>>0)+h;return(g<>>32-u)+p},c._ii=function(y,p,l,v,f,u,h){var g=y+(l^(p|~v))+(f>>>0)+h;return(g<>>32-u)+p},c._blocksize=16,c._digestsize=16,e.exports=function(y,p){if(y==null)throw new Error("Illegal argument "+y);var l=r.wordsToBytes(c(y,p));return p&&p.asBytes?l:p&&p.asString?s.bytesToString(l):r.bytesToHex(l)}})()}}),Qt={};Dt(Qt,{eMath:()=>Sr}),at.exports=ze(Qt);var jr=ot(ct()),Gr=ot(ct()),Kt={};Dt(Kt,{Attribute:()=>Lt,AttributeStatic:()=>pe,Boost:()=>$t,BoostObject:()=>Nt,Currency:()=>yt,CurrencyStatic:()=>ge,DEFAULT_ITERATIONS:()=>xt,E:()=>P,FORMATS:()=>pr,FormatTypeList:()=>er,Grid:()=>br,GridCell:()=>ve,LRUCache:()=>Rt,ListNode:()=>te,UpgradeData:()=>vt,UpgradeStatic:()=>me,calculateSum:()=>Yt,calculateSumApprox:()=>ce,calculateSumLoop:()=>fe,calculateUpgrade:()=>he,decimalToJSONString:()=>de,equalsTolerance:()=>le,inverseFunctionApprox:()=>zt,roundingBase:()=>vr,upgradeToCacheNameEL:()=>yr});var Ur=ot(ct()),Rt=class{constructor(t){this.map=new Map,this.first=void 0,this.last=void 0,this.maxSize=t}get size(){return this.map.size}get(t){let e=this.map.get(t);if(e!==void 0)return e!==this.first&&(e===this.last?(this.last=e.prev,this.last.next=void 0):(e.prev.next=e.next,e.next.prev=e.prev),e.next=this.first,this.first.prev=e,this.first=e),e.value}set(t,e){if(this.maxSize<1)return;if(this.map.has(t))throw new Error("Cannot update existing keys in the cache");let r=new te(t,e);for(this.first===void 0?(this.first=r,this.last=r):(r.next=this.first,this.first.prev=r,this.first=r),this.map.set(t,r);this.map.size>this.maxSize;){let i=this.last;this.map.delete(i.key),this.last=i.prev,this.last.next=void 0}}},te=class{constructor(t,e){this.next=void 0,this.prev=void 0,this.key=t,this.value=e}},U;(function(t){t[t.PLAIN_TO_CLASS=0]="PLAIN_TO_CLASS",t[t.CLASS_TO_PLAIN=1]="CLASS_TO_PLAIN",t[t.CLASS_TO_CLASS=2]="CLASS_TO_CLASS"})(U||(U={}));var We=function(){function t(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return t.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},t.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.findTransformMetadatas=function(e,r,i){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?i===U.CLASS_TO_CLASS||i===U.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?i===U.CLASS_TO_PLAIN:!0})},t.prototype.findExcludeMetadata=function(e,r){return this.findMetadata(this._excludeMetadatas,e,r)},t.prototype.findExposeMetadata=function(e,r){return this.findMetadata(this._exposeMetadatas,e,r)},t.prototype.findExposeMetadataByCustomName=function(e,r){return this.getExposedMetadatas(e).find(function(i){return i.options&&i.options.name===r})},t.prototype.findTypeMetadata=function(e,r){return this.findMetadata(this._typeMetadatas,e,r)},t.prototype.getStrategy=function(e){var r=this._excludeMetadatas.get(e),i=r&&r.get(void 0),n=this._exposeMetadatas.get(e),s=n&&n.get(void 0);return i&&s||!i&&!s?"none":i?"excludeAll":"exposeAll"},t.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},t.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},t.prototype.getExposedProperties=function(e,r){return this.getExposedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===U.CLASS_TO_CLASS||r===U.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===U.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===U.CLASS_TO_CLASS||r===U.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===U.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var i=e.get(r),n;i&&(n=Array.from(i.values()).filter(function(f){return f.propertyName!==void 0}));for(var s=[],c=0,y=this.getAncestors(r);c0&&(c=c.filter(function(f){return!l.includes(f)})),this.options.version!==void 0&&(c=c.filter(function(f){var u=rt.findExposeMetadata(e,f);return!u||!u.options?!0:n.checkVersion(u.options.since,u.options.until)})),this.options.groups&&this.options.groups.length?c=c.filter(function(f){var u=rt.findExposeMetadata(e,f);return!u||!u.options?!0:n.checkGroups(u.options.groups)}):c=c.filter(function(f){var u=rt.findExposeMetadata(e,f);return!u||!u.options||!u.options.groups||!u.options.groups.length})}return this.options.excludePrefixes&&this.options.excludePrefixes.length&&(c=c.filter(function(v){return n.options.excludePrefixes.every(function(f){return v.substr(0,f.length)!==f})})),c=c.filter(function(v,f,u){return u.indexOf(v)===f}),c},t.prototype.checkVersion=function(e,r){var i=!0;return i&&e&&(i=this.options.version>=e),i&&r&&(i=this.options.versionNumber.MAX_SAFE_INTEGER)&&(A="\u03C9");let M=t.log(a,8e3).toNumber();if(m.equals(0))return A;if(m.gt(0)&&m.lte(3)){let G=[];for(let H=0;HNumber.MAX_SAFE_INTEGER)&&(A="\u03C9");let M=t.log(a,8e3).toNumber();if(m.equals(0))return A;if(m.gt(0)&&m.lte(2)){let G=[];for(let H=0;H118?e.elemental.beyondOg(_):e.elemental.config.element_lists[a-1][A]},beyondOg(a){let S=Math.floor(Math.log10(a)),m=["n","u","b","t","q","p","h","s","o","e"],A="";for(let _=S;_>=0;_--){let M=Math.floor(a/Math.pow(10,_))%10;A==""?A=m[M].toUpperCase():A+=m[M]}return A},abbreviationLength(a){return a==1?1:Math.pow(Math.floor(a/2)+1,2)*2},getAbbreviationAndValue(a){let S=a.log(118).toNumber(),m=Math.floor(S)+1,A=e.elemental.abbreviationLength(m),_=S-m+1,M=Math.floor(_*A),E=e.elemental.getAbbreviation(m,_),T=new t(118).pow(m+M/A-1);return[E,T]},formatElementalPart(a,S){return S.eq(1)?a:`${S} ${a}`},format(a,S=2){if(a.gt(new t(118).pow(new t(118).pow(new t(118).pow(4)))))return"e"+e.elemental.format(a.log10(),S);let m=a.log(118),_=m.log(118).log(118).toNumber(),M=Math.max(4-_*2,1),E=[];for(;m.gte(1)&&E.length=M)return E.map(G=>e.elemental.formatElementalPart(G[0],G[1])).join(" + ");let T=new t(118).pow(m).toFixed(E.length===1?3:S);return E.length===0?T:E.length===1?`${T} \xD7 ${e.elemental.formatElementalPart(E[0][0],E[0][1])}`:`${T} \xD7 (${E.map(G=>e.elemental.formatElementalPart(G[0],G[1])).join(" + ")})`}},old_sc:{format(a,S){a=new t(a);let m=a.log10().floor();if(m.lt(9))return m.lt(3)?a.toFixed(S):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let _=a.slog();return(_.gte(1e9)?"":new t(10).pow(_.sub(_.floor())).toFixed(4))+"F"+e.old_sc.format(_.floor(),0)}let A=a.div(new t(10).pow(m));return(m.log10().gte(9)?"":A.toFixed(4))+"e"+e.old_sc.format(m,0)}}},eng:{format(a,S=2){a=new t(a);let m=a.log10().floor();if(m.lt(9))return m.lt(3)?a.toFixed(S):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let _=a.slog();return(_.gte(1e9)?"":new t(10).pow(_.sub(_.floor())).toFixed(4))+"F"+e.eng.format(_.floor(),0)}let A=a.div(new t(1e3).pow(m.div(3).floor()));return(m.log10().gte(9)?"":A.toFixed(new t(4).sub(m.sub(m.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(m.div(3).floor().mul(3),0)}}},mixed_sc:{format(a,S,m=9){a=new t(a);let A=a.log10().floor();return A.lt(303)&&A.gte(m)?p(a,S,m,"st"):p(a,S,m,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(a,S=2,m){a=new t(a);let A=a.max(1).log10().max(1).log(r.log10()).floor();if(A.lte(0))return p(a,S,m,"sc");a=new t(10).pow(a.max(1).log10().div(r.log10().pow(A)).sub(A.gte(1)?1:0));let _=A.div(10).floor(),M=A.toNumber()%10-1;return p(a,Math.max(4,S),m,"sc")+" "+(_.gte(1)?"meta"+(_.gte(2)?"^"+p(_,0,m,"sc"):"")+"-":"")+(isNaN(M)?"nanity":e.layer.layers[M])}},standard:{tier1(a){return mt[0][0][a%10]+mt[0][1][Math.floor(a/10)%10]+mt[0][2][Math.floor(a/100)]},tier2(a){let S=a%10,m=Math.floor(a/10)%10,A=Math.floor(a/100)%10,_="";return a<10?mt[1][0][a]:(m==1&&S==0?_+="Vec":_+=mt[1][1][S]+mt[1][2][m],_+=mt[1][3][A],_)}},inf:{format(a,S,m){a=new t(a);let A=0,_=new t(Number.MAX_VALUE),M=["","\u221E","\u03A9","\u03A8","\u028A"],E=["","","m","mm","mmm"];for(;a.gte(_);)a=a.log(_),A++;return A==0?p(a,S,m,"sc"):a.gte(3)?E[A]+M[A]+"\u03C9^"+p(a.sub(1),S,m,"sc"):a.gte(2)?E[A]+"\u03C9"+M[A]+"-"+p(_.pow(a.sub(2)),S,m,"sc"):E[A]+M[A]+"-"+p(_.pow(a.sub(1)),S,m,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(a,S=new t(1e15),m=!1,A=9){if(a=new t(a),S=new t(S).div(1e3),a.lt(S.mul(1e3)))return"";let{alphabet:_}=e.alphabet.config,M=_.length,E=a.log(1e3).sub(S.log(1e3)).floor(),T=E.add(1).log(M+1).ceil(),G="",H=(tt,nt)=>{let W=tt,Z="";for(let X=0;X=M)return"\u03C9";Z=_[dt]+Z,W=W.sub(1).div(M).floor()}return Z};if(T.lt(A))G=H(E,T);else{let tt=T.sub(A).add(1),nt=E.div(t.pow(M+1,tt.sub(1))).floor();G=`${H(nt,new t(A))}(${tt.gt("1e9")?tt.format():tt.format(0)})`}return G},format(a,S=2,m=9,A="mixed_sc",_=new t(1e15),M=!1,E){if(a=new t(a),_=new t(_).div(1e3),a.lt(_.mul(1e3)))return p(a,S,m,A);let T=e.alphabet.getAbbreviation(a,_,M,E),G=a.div(t.pow(1e3,a.log(1e3).floor()));return`${T.length>(E??9)+2?"":G.toFixed(S)+" "}${T}`}}},r=new t(2).pow(1024),i="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",n="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function s(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":i[parseInt(S,10)]).join("")}function c(a){return a.toFixed(0).split("").map(S=>S==="-"?"\u208B":n[parseInt(S,10)]).join("")}function y(a,S=2,m=9,A="st"){return p(a,S,m,A)}function p(a,S=2,m=9,A="mixed_sc"){a=new t(a);let _=a.lt(0)?"-":"";if(a.mag==1/0)return _+"Infinity";if(Number.isNaN(a.mag))return _+"NaN";if(a.lt(0)&&(a=a.mul(-1)),a.eq(0))return a.toFixed(S);let M=a.log10().floor();switch(A){case"sc":case"scientific":if(a.log10().lt(Math.min(-S,0))&&S>1){let E=a.log10().ceil(),T=a.div(E.eq(-1)?new t(.1):new t(10).pow(E)),G=E.mul(-1).max(1).log10().gte(9);return _+(G?"":T.toFixed(2))+"e"+p(E,0,m,"mixed_sc")}else if(M.lt(m)){let E=Math.max(Math.min(S-M.toNumber(),S),0);return _+(E>0?a.toFixed(E):a.toFixed(E).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(a.gte("eeee10")){let G=a.slog();return(G.gte(1e9)?"":new t(10).pow(G.sub(G.floor())).toFixed(2))+"F"+p(G.floor(),0)}let E=a.div(new t(10).pow(M)),T=M.log10().gte(9);return _+(T?"":E.toFixed(2))+"e"+p(M,0,m,"mixed_sc")}case"st":case"standard":{let E=a.log(1e3).floor();if(E.lt(1))return _+a.toFixed(Math.max(Math.min(S-M.toNumber(),S),0));let T=E.mul(3),G=E.log10().floor();if(G.gte(3e3))return"e"+p(M,S,m,"st");let H="";if(E.lt(4))H=["","K","M","B"][Math.round(E.toNumber())];else{let W=Math.floor(E.log(1e3).toNumber());for(W<100&&(W=Math.max(W-1,0)),E=E.sub(1).div(new t(10).pow(W*3));E.gt(0);){let Z=E.div(1e3).floor(),X=E.sub(Z.mul(1e3)).floor().toNumber();X>0&&(X==1&&!W&&(H="U"),W&&(H=e.standard.tier2(W)+(H?"-"+H:"")),X>1&&(H=e.standard.tier1(X)+H)),E=Z,W++}}let tt=a.div(new t(10).pow(T)),nt=S===2?new t(2).sub(M.sub(T)).add(1).toNumber():S;return _+(G.gte(10)?"":tt.toFixed(nt)+" ")+H}default:return e[A]||console.error('Invalid format type "',A,'"'),_+e[A].format(a,S,m)}}function l(a,S,m="mixed_sc",A,_){a=new t(a),S=new t(S);let M=a.add(S),E,T=M.div(a);return T.gte(10)&&a.gte(1e100)?(T=T.log10().mul(20),E="(+"+p(T,A,_,m)+" OoMs/sec)"):E="(+"+p(S,A,_,m)+"/sec)",E}function v(a,S=2,m="s"){return a=new t(a),a.gte(86400)?p(a.div(86400).floor(),0,12,"sc")+":"+v(a.mod(86400),S,"d"):a.gte(3600)||m=="d"?(a.div(3600).gte(10)||m!="d"?"":"0")+p(a.div(3600).floor(),0,12,"sc")+":"+v(a.mod(3600),S,"h"):a.gte(60)||m=="h"?(a.div(60).gte(10)||m!="h"?"":"0")+p(a.div(60).floor(),0,12,"sc")+":"+v(a.mod(60),S,"m"):(a.gte(10)||m!="m"?"":"0")+p(a,S,12,"sc")}function f(a,S=!1,m=0,A=9,_="mixed_sc"){let M=Bt=>p(Bt,m,A,_);a=new t(a);let E=a.mul(1e3).mod(1e3).floor(),T=a.mod(60).floor(),G=a.div(60).mod(60).floor(),H=a.div(3600).mod(24).floor(),tt=a.div(86400).mod(365.2425).floor(),nt=a.div(31556952).floor(),W=nt.eq(1)?" year":" years",Z=tt.eq(1)?" day":" days",X=H.eq(1)?" hour":" hours",dt=G.eq(1)?" minute":" minutes",Pt=T.eq(1)?" second":" seconds",qt=E.eq(1)?" millisecond":" milliseconds";return`${nt.gt(0)?M(nt)+W+", ":""}${tt.gt(0)?M(tt)+Z+", ":""}${H.gt(0)?M(H)+X+", ":""}${G.gt(0)?M(G)+dt+", ":""}${T.gt(0)?M(T)+Pt+",":""}${S&&E.gt(0)?" "+M(E)+qt:""}`.replace(/,([^,]*)$/,"$1").trim()}function u(a){return a=new t(a),p(new t(1).sub(a).mul(100))+"%"}function h(a){return a=new t(a),p(a.mul(100))+"%"}function g(a,S=2){return a=new t(a),a.gte(1)?"\xD7"+a.format(S):"/"+a.pow(-1).format(S)}function w(a,S,m=10){return t.gte(a,10)?t.pow(m,t.log(a,m).pow(S)):new t(a)}function I(a,S=0){a=new t(a);let m=(E=>E.map((T,G)=>({name:T.name,altName:T.altName,value:t.pow(1e3,new t(G).add(1))})))([{name:"K",altName:"Kilo"},{name:"M",altName:"Mega"},{name:"G",altName:"Giga"},{name:"T",altName:"Tera"},{name:"P",altName:"Peta"},{name:"E",altName:"Exa"},{name:"Z",altName:"Zetta"},{name:"Y",altName:"Yotta"},{name:"R",altName:"Ronna"},{name:"Q",altName:"Quetta"}]),A="",_=a.lte(0)?0:t.min(t.log(a,1e3).sub(1),m.length-1).floor().toNumber(),M=m[_];if(_===0)switch(S){case 1:A="";break;case 2:case 0:default:A=a.format();break}switch(S){case 1:A=M.name;break;case 2:A=a.divide(M.value).format();break;case 3:A=M.altName;break;case 0:default:A=`${a.divide(M.value).format()} ${M.name}`;break}return A}function L(a,S=!1){return`${I(a,2)} ${I(a,1)}eV${S?"/c^2":""}`}let F={...e,toSubscript:s,toSuperscript:c,formatST:y,format:p,formatGain:l,formatTime:v,formatTimeLong:f,formatReduction:u,formatPercent:h,formatMult:g,expMult:w,metric:I,ev:L};return{FORMATS:e,formats:F}}var Gt=17,ir=9e15,nr=Math.log10(9e15),sr=1/9e15,ar=308,or=-324,ne=5,ur=1023,lr=!0,fr=!1,cr=function(){let t=[];for(let r=or+1;r<=ar;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),gt=[2,Math.E,3,4,5,6,7,8,9,10],hr=[[1,1.0891180521811203,1.1789767925673957,1.2701455431742086,1.3632090180450092,1.4587818160364217,1.5575237916251419,1.6601571006859253,1.767485818836978,1.8804192098842727,2],[1,1.1121114330934079,1.231038924931609,1.3583836963111375,1.4960519303993531,1.6463542337511945,1.8121385357018724,1.996971324618307,2.2053895545527546,2.4432574483385254,Math.E],[1,1.1187738849693603,1.2464963939368214,1.38527004705667,1.5376664685821402,1.7068895236551784,1.897001227148399,2.1132403089001035,2.362480153784171,2.6539010333870774,3],[1,1.1367350847096405,1.2889510672956703,1.4606478703324786,1.6570295196661111,1.8850062585672889,2.1539465047453485,2.476829779693097,2.872061932789197,3.3664204535587183,4],[1,1.1494592900767588,1.319708228183931,1.5166291280087583,1.748171114438024,2.0253263297298045,2.3636668498288547,2.7858359149579424,3.3257226212448145,4.035730287722532,5],[1,1.159225940787673,1.343712473580932,1.5611293155111927,1.8221199554561318,2.14183924486326,2.542468319282638,3.0574682501653316,3.7390572020926873,4.6719550537360774,6],[1,1.1670905356972596,1.3632807444991446,1.5979222279405536,1.8842640123816674,2.2416069644878687,2.69893426559423,3.3012632110403577,4.121250340630164,5.281493033448316,7],[1,1.1736630594087796,1.379783782386201,1.6292821855668218,1.9378971836180754,2.3289975651071977,2.8384347394720835,3.5232708454565906,4.478242031114584,5.868592169644505,8],[1,1.1793017514670474,1.394054150657457,1.65664127441059,1.985170999970283,2.4069682290577457,2.9647310119960752,3.7278665320924946,4.814462547283592,6.436522247411611,9],[1,1.1840100246247336,1.4061375836156955,1.6802272208863964,2.026757028388619,2.4770056063449646,3.080525271755482,3.9191964192627284,5.135152840833187,6.989961179534715,10]],dr=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],N=function(e){return o.fromValue_noAlloc(e)},D=function(t,e,r){return o.fromComponents(t,e,r)},Y=function(e,r,i){return o.fromComponents_noNormalize(e,r,i)},ht=function(e,r){let i=r+1,n=Math.ceil(Math.log10(Math.abs(e))),s=Math.round(e*Math.pow(10,i-n))*Math.pow(10,n-i);return parseFloat(s.toFixed(Math.max(i-n,0)))},Ut=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},mr=function(t){if(!isFinite(t))return t;if(t<-50)return t===Math.trunc(t)?Number.NEGATIVE_INFINITY:0;let e=1;for(;t<10;)e=e*t,++t;t-=1;let r=.9189385332046727;r=r+(t+.5)*Math.log(t),r=r-t;let i=t*t,n=t;return r=r+1/(12*n),n=n*i,r=r+1/(360*n),n=n*i,r=r+1/(1260*n),n=n*i,r=r+1/(1680*n),n=n*i,r=r+1/(1188*n),n=n*i,r=r+691/(360360*n),n=n*i,r=r+7/(1092*n),n=n*i,r=r+3617/(122400*n),Math.exp(r)/e},gr=.36787944117144233,se=.5671432904097838,ae=function(t,e=1e-10){let r,i;if(!Number.isFinite(t)||t===0)return t;if(t===1)return se;t<10?r=0:r=Math.log(t)-Math.log(Math.log(t));for(let n=0;n<100;++n){if(i=(t*Math.exp(-r)+r*r)/(r+1),Math.abs(i-r).5?1:-1;if(Math.random()*20<1)return Y(e,0,1);let r=Math.floor(Math.random()*(t+1)),i=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(i=Math.trunc(i));let n=Math.pow(10,i);return Math.random()>.9&&(n=Math.trunc(n)),D(e,r,n)}static affordGeometricSeries_core(t,e,r,i){let n=e.mul(r.pow(i));return o.floor(t.div(n).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,i){return e.mul(r.pow(i)).mul(o.sub(1,r.pow(t))).div(o.sub(1,r))}static affordArithmeticSeries_core(t,e,r,i){let s=e.add(i.mul(r)).sub(r.div(2)),c=s.pow(2);return s.neg().add(c.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let n=e.add(i.mul(r));return t.div(2).mul(n.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.sign==1?(this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY):this.sign==-1&&(this.mag=Number.NEGATIVE_INFINITY,this.layer=Number.NEGATIVE_INFINITY),this;if(this.layer===0&&this.mag=ir)return this.layer+=1,this.mag=e*Math.log10(t),this;for(;t0;)this.layer-=1,this.layer===0?this.mag=Math.pow(10,this.mag):(this.mag=e*Math.pow(10,t),t=Math.abs(this.mag),e=Math.sign(this.mag));return this.layer===0&&(this.mag<0?(this.mag=-this.mag,this.sign=-this.sign):this.mag===0&&(this.sign=0)),(Number.isNaN(this.sign)||Number.isNaN(this.layer)||Number.isNaN(this.mag))&&(this.sign=Number.NaN,this.layer=Number.NaN,this.mag=Number.NaN),this}fromComponents(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this.normalize(),this}fromComponents_noNormalize(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this}fromMantissaExponent(t,e){return this.layer=1,this.sign=Math.sign(t),t=Math.abs(t),this.mag=e+Math.log10(t),this.normalize(),this}fromMantissaExponent_noNormalize(t,e){return this.fromMantissaExponent(t,e),this}fromDecimal(t){return this.sign=t.sign,this.layer=t.layer,this.mag=t.mag,this}fromNumber(t){return this.mag=Math.abs(t),this.sign=Math.sign(t),this.layer=0,this.normalize(),this}fromString(t,e=!1){let r=t,i=o.fromStringCache.get(r);if(i!==void 0)return this.fromDecimal(i);lr?t=t.replace(",",""):fr&&(t=t.replace(",","."));let n=t.split("^^^");if(n.length===2){let w=parseFloat(n[0]),I=parseFloat(n[1]),L=n[1].split(";"),F=1;if(L.length===2&&(F=parseFloat(L[1]),isFinite(F)||(F=1)),isFinite(w)&&isFinite(I)){let a=o.pentate(w,I,F,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}}let s=t.split("^^");if(s.length===2){let w=parseFloat(s[0]),I=parseFloat(s[1]),L=s[1].split(";"),F=1;if(L.length===2&&(F=parseFloat(L[1]),isFinite(F)||(F=1)),isFinite(w)&&isFinite(I)){let a=o.tetrate(w,I,F,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}}let c=t.split("^");if(c.length===2){let w=parseFloat(c[0]),I=parseFloat(c[1]);if(isFinite(w)&&isFinite(I)){let L=o.pow(w,I);return this.sign=L.sign,this.layer=L.layer,this.mag=L.mag,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}}t=t.trim().toLowerCase();let y,p,l=t.split("pt");if(l.length===2){y=10,p=parseFloat(l[0]),l[1]=l[1].replace("(",""),l[1]=l[1].replace(")","");let w=parseFloat(l[1]);if(isFinite(w)||(w=1),isFinite(y)&&isFinite(p)){let I=o.tetrate(y,p,w,e);return this.sign=I.sign,this.layer=I.layer,this.mag=I.mag,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}}if(l=t.split("p"),l.length===2){y=10,p=parseFloat(l[0]),l[1]=l[1].replace("(",""),l[1]=l[1].replace(")","");let w=parseFloat(l[1]);if(isFinite(w)||(w=1),isFinite(y)&&isFinite(p)){let I=o.tetrate(y,p,w,e);return this.sign=I.sign,this.layer=I.layer,this.mag=I.mag,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}}if(l=t.split("f"),l.length===2){y=10,l[0]=l[0].replace("(",""),l[0]=l[0].replace(")","");let w=parseFloat(l[0]);if(l[1]=l[1].replace("(",""),l[1]=l[1].replace(")",""),p=parseFloat(l[1]),isFinite(w)||(w=1),isFinite(y)&&isFinite(p)){let I=o.tetrate(y,p,w,e);return this.sign=I.sign,this.layer=I.layer,this.mag=I.mag,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}}let v=t.split("e"),f=v.length-1;if(f===0){let w=parseFloat(t);if(isFinite(w))return this.fromNumber(w),o.fromStringCache.size>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}else if(f===1){let w=parseFloat(t);if(isFinite(w)&&w!==0)return this.fromNumber(w),o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}let u=t.split("e^");if(u.length===2){this.sign=1,u[0].charAt(0)=="-"&&(this.sign=-1);let w="";for(let I=0;I=43&&L<=57||L===101)w+=u[1].charAt(I);else return this.layer=parseFloat(w),this.mag=parseFloat(u[1].substr(I+1)),this.normalize(),o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}}if(f<1)return this.sign=0,this.layer=0,this.mag=0,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this;let h=parseFloat(v[0]);if(h===0)return this.sign=0,this.layer=0,this.mag=0,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this;let g=parseFloat(v[v.length-1]);if(f>=2){let w=parseFloat(v[v.length-2]);isFinite(w)&&(g*=Math.sign(w),g+=Ut(w))}if(!isFinite(h))this.sign=v[0]==="-"?-1:1,this.layer=f,this.mag=g;else if(f===1)this.sign=Math.sign(h),this.layer=1,this.mag=g+Math.log10(Math.abs(h));else if(this.sign=Math.sign(h),this.layer=f,f===2){let w=o.mul(D(1,2,g),N(h));return this.sign=w.sign,this.layer=w.layer,this.mag=w.mag,o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}else this.mag=g;return this.normalize(),o.fromStringCache.maxSize>=1&&o.fromStringCache.set(r,o.fromDecimal(this)),this}fromValue(t){return t instanceof o?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.NEGATIVE_INFINITY&&this.layer===Number.NEGATIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:ht(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:ht(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=ne?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):ht(this.m,t)+"e"+ht(this.e,t):this.layer===1?ht(this.m,t)+"e"+ht(this.e,t):this.layer<=ne?(this.sign===-1?"-":"")+"e".repeat(this.layer)+ht(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+ht(this.mag,t)}abs(){return Y(this.sign===0?0:1,this.layer,this.mag)}neg(){return Y(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?o.dZero:this.layer===0?D(this.sign,0,Math.round(this.mag)):this}floor(){return this.mag<0?this.sign===-1?o.dNegOne:o.dZero:this.sign===-1?this.neg().ceil().neg():this.layer===0?D(this.sign,0,Math.floor(this.mag)):this}ceil(){return this.mag<0?this.sign===1?o.dOne:o.dZero:this.sign===-1?this.neg().floor().neg():this.layer===0?D(this.sign,0,Math.ceil(this.mag)):this}trunc(){return this.mag<0?o.dZero:this.layer===0?D(this.sign,0,Math.trunc(this.mag)):this}add(t){let e=N(t);if(!Number.isFinite(this.layer))return this;if(!Number.isFinite(e.layer)||this.sign===0)return e;if(e.sign===0)return this;if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return Y(0,0,0);let r,i;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(o.cmpabs(this,e)>0?(r=this,i=e):(r=e,i=this),r.layer===0&&i.layer===0)return o.fromNumber(r.sign*r.mag+i.sign*i.mag);let n=r.layer*Math.sign(r.mag),s=i.layer*Math.sign(i.mag);if(n-s>=2)return r;if(n===0&&s===-1){if(Math.abs(i.mag-Math.log10(r.mag))>Gt)return r;{let c=Math.pow(10,Math.log10(r.mag)-i.mag),y=i.sign+r.sign*c;return D(Math.sign(y),1,i.mag+Math.log10(Math.abs(y)))}}if(n===1&&s===0){if(Math.abs(r.mag-Math.log10(i.mag))>Gt)return r;{let c=Math.pow(10,r.mag-Math.log10(i.mag)),y=i.sign+r.sign*c;return D(Math.sign(y),1,Math.log10(i.mag)+Math.log10(Math.abs(y)))}}if(Math.abs(r.mag-i.mag)>Gt)return r;{let c=Math.pow(10,r.mag-i.mag),y=i.sign+r.sign*c;return D(Math.sign(y),1,i.mag+Math.log10(Math.abs(y)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(N(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=N(t);if(!Number.isFinite(this.layer))return this;if(!Number.isFinite(e.layer))return e;if(this.sign===0||e.sign===0)return Y(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return Y(this.sign*e.sign,0,1);let r,i;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=this,i=e):(r=e,i=this),r.layer===0&&i.layer===0)return o.fromNumber(r.sign*i.sign*r.mag*i.mag);if(r.layer>=3||r.layer-i.layer>=2)return D(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return D(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return D(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let n=D(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(D(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return D(r.sign*i.sign,n.layer+1,n.sign*n.mag)}if(r.layer===2&&i.layer===2){let n=D(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(D(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return D(r.sign*i.sign,n.layer+1,n.sign*n.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=N(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?o.dNaN:this.layer===0?D(this.sign,0,1/this.mag):D(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=N(t).abs();if(e.eq(o.dZero))return o.dZero;let r=this.toNumber(),i=e.toNumber();return isFinite(r)&&isFinite(i)&&r!=0&&i!=0?new o(r%i):this.sub(e).eq(this)?o.dZero:e.sub(this).eq(e)?this:this.sign==-1?this.abs().mod(e).neg():this.sub(this.div(e).floor().mul(e))}modulo(t){return this.mod(t)}modular(t){return this.mod(t)}cmp(t){let e=N(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,i=e.mag>0?e.layer:-e.layer;return r>i?1:re.mag?1:this.mag0?e:this}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=N(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=N(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let i=this.mag,n=r.mag;return this.layer>r.layer&&(n=Ut(n)),this.layer0?D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):D(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?o.dNaN:this.layer>0?D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):D(this.sign,0,Math.log10(this.mag))}log(t){return t=N(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?o.dNaN:this.layer===0&&t.layer===0?D(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):o.div(this.log10(),t.log10())}log2(){return this.sign<=0?o.dNaN:this.layer===0?D(this.sign,0,Math.log2(this.mag)):this.layer===1?D(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?D(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?o.dNaN:this.layer===0?D(this.sign,0,Math.log(this.mag)):this.layer===1?D(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?D(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):D(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=N(t),r=this,i=e;if(r.sign===0)return i.eq(0)?Y(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(i.sign===0)return Y(1,0,1);if(i.sign===1&&i.layer===0&&i.mag===1)return r;let n=r.absLog10().mul(i).pow10();return this.sign===-1?Math.abs(i.toNumber()%2)%2===1?n.neg():Math.abs(i.toNumber()%2)%2===0?n:o.dNaN:n}pow10(){if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return o.dNaN;let t=this;if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return D(1,0,e);if(t.sign===0)return o.dOne;t=Y(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?D(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?D(-t.sign,t.layer+1,-t.mag):o.dOne}pow_base(t){return N(t).pow(this)}root(t){let e=N(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?o.exp(o.mul(this,o.ln(this).sub(1))):o.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(Y(1,0,24)))return o.fromNumber(mr(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,i=t,n=12*i,s=1/n,c=e+s;if(c===e||(e=c,i=i*r,n=360*i,s=1/n,c=e-s,c===e))return o.exp(e);e=c,i=i*r,n=1260*i;let y=1/n;return e=e+y,i=i*r,n=1680*i,y=1/n,e=e-y,o.exp(e)}else return this.layer===1?o.exp(o.mul(this,o.ln(this).sub(1))):o.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?o.dOne:this.layer===0&&this.mag<=709.7?o.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?D(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?D(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):D(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return o.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return D(1,2,Math.log10(this.mag)-.3010299956639812);{let t=o.div(Y(this.sign,this.layer-1,this.mag),Y(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=Y(1,0,1),r=!1){if(t===1)return o.pow(this,e);if(t===0)return new o(e);if(this.eq(o.dOne))return o.dOne;if(this.eq(-1))return o.pow(this,e);if(t===Number.POSITIVE_INFINITY){let s=this.toNumber();if(s<=1.444667861009766&&s>=.06598803584531254){if(s>1.444667861009099)return o.fromNumber(Math.E);let c=o.ln(this).neg();return c.lambertw().div(c)}else return s>1.444667861009766?o.fromNumber(Number.POSITIVE_INFINITY):o.dNaN}if(this.eq(o.dZero)){let s=Math.abs((t+1)%2);return s>1&&(s=2-s),o.fromNumber(s)}if(t<0)return o.iteratedlog(e,this,-t,r);e=N(e);let i=t;t=Math.trunc(t);let n=i-t;if(this.gt(o.dZero)&&this.lte(1.444667861009766)&&(i>1e4||!r)){t=Math.min(1e4,t);for(let s=0;s1e4){let s=this.pow(e);return i<=1e4||Math.ceil(i)%2==0?e.mul(1-n).add(s.mul(n)):e.mul(n).add(s.mul(1-n))}return e}n!==0&&(e.eq(o.dOne)?this.gt(10)||r?e=this.pow(n):(e=o.fromNumber(o.tetrate_critical(this.toNumber(),n)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(n,r):e=e.layeradd(n,this,r));for(let s=0;s3)return Y(e.sign,e.layer+(t-s-1),e.mag);if(s>1e4)return e}return e}iteratedexp(t=2,e=Y(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return o.tetrate(t,-e,this,r);t=N(t);let i=o.fromDecimal(this),n=e;e=Math.trunc(e);let s=n-e;if(i.layer-t.layer>3){let c=Math.min(e,i.layer-t.layer-3);e-=c,i.layer-=c}for(let c=0;c1e4)return i}return s>0&&s<1&&(t.eq(10)?i=i.layeradd10(-s,r):i=i.layeradd(-s,t,r)),i}slog(t=10,e=100,r=!1){let i=.001,n=!1,s=!1,c=this.slog_internal(t,r).toNumber();for(let y=1;y1&&s!=l&&(n=!0),s=l,n?i/=2:i*=2,i=Math.abs(i)*(l?-1:1),c+=i,i===0)break}return o.fromNumber(c)}slog_internal(t=10,e=!1){if(t=N(t),t.lte(o.dZero)||t.eq(o.dOne))return o.dNaN;if(t.lt(o.dOne))return this.eq(o.dOne)?o.dZero:this.eq(o.dZero)?o.dNegOne:o.dNaN;if(this.mag<0||this.eq(o.dZero))return o.dNegOne;let r=0,i=o.fromDecimal(this);if(i.layer-t.layer>3){let n=i.layer-t.layer-3;r+=n,i.layer-=n}for(let n=0;n<100;++n)if(i.lt(o.dZero))i=o.pow(t,i),r-=1;else{if(i.lte(o.dOne))return e?o.fromNumber(r+i.toNumber()-1):o.fromNumber(r+o.slog_critical(t.toNumber(),i.toNumber()));r+=1,i=o.log(i,t)}return o.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:o.critical_section(t,e,dr)}static tetrate_critical(t,e){return o.critical_section(t,e,hr)}static critical_section(t,e,r,i=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let n=0,s=0;for(let y=0;yt){let p=(t-gt[y])/(gt[y+1]-gt[y]);n=r[y][Math.floor(e)]*(1-p)+r[y+1][Math.floor(e)]*p,s=r[y][Math.ceil(e)]*(1-p)+r[y+1][Math.ceil(e)]*p;break}let c=e-Math.floor(e);return n<=0||s<=0?n*(1-c)+s*c:Math.pow(t,Math.log(n)/Math.log(t)*(1-c)+Math.log(s)/Math.log(t)*c)}layeradd10(t,e=!1){t=o.fromValue_noAlloc(t).toNumber();let r=o.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let i=Math.trunc(t);t-=i,r.layer+=i}if(t<=-1){let i=Math.trunc(t);if(t-=i,r.layer+=i,r.layer<0)for(let n=0;n<100;++n){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let n=this.slog(e).toNumber()+t;return n>=0?o.tetrate(e,n,o.dOne,r):Number.isFinite(n)?n>=-1?o.log(o.tetrate(e,n+1,o.dOne,r),e):o.log(o.log(o.tetrate(e,n+2,o.dOne,r),e),e):o.dNaN}lambertw(){if(this.lt(-.3678794411710499))throw Error("lambertw is unimplemented for results less than -1, sorry!");if(this.mag<0)return o.fromNumber(ae(this.toNumber()));if(this.layer===0)return o.fromNumber(ae(this.sign*this.mag));if(this.layer===1)return oe(this);if(this.layer===2)return oe(this);if(this.layer>=3)return Y(this.sign,this.layer-1,this.mag);throw"Unhandled behavior in lambertw()"}ssqrt(){return this.linear_sroot(2)}linear_sroot(t){if(t==1)return this;if(this.eq(o.dInf))return o.dInf;if(!this.isFinite())return o.dNaN;if(t>0&&t<1)return this.root(t);if(t>-2&&t<-1)return o.fromNumber(t).add(2).pow(this.recip());if(t<=0)return o.dNaN;if(t==Number.POSITIVE_INFINITY){let e=this.toNumber();return egr?this.pow(this.recip()):o.dNaN}if(this.eq(1))return o.dOne;if(this.lt(0))return o.dNaN;if(this.lte("1ee-16"))return t%2==1?this:o.dNaN;if(this.gt(1)){let e=o.dTen;this.gte(o.tetrate(10,t,1,!0))&&(e=this.iteratedlog(10,t-1,!0)),t<=1&&(e=this.root(t));let r=o.dZero,i=e.layer,n=e.iteratedlog(10,i,!0),s=n,c=n.div(2),y=!0;for(;y;)c=r.add(n).div(2),o.iteratedexp(10,i,c,!0).tetrate(t,1,!0).gt(this)?n=c:r=c,c.eq(s)?y=!1:s=c;return o.iteratedexp(10,i,c,!0)}else{let e=1,r=D(1,10,1),i=D(1,10,1),n=D(1,10,1),s=D(1,1,-16),c=o.dZero,y=D(1,10,1),p=s.pow10().recip(),l=o.dZero,v=p,f=p,u=Math.ceil(t)%2==0,h=0,g=D(1,10,1),w=!1,I=o.dZero,L=!1;for(;e<4;){if(e==2){if(u)break;n=D(1,10,1),s=r,e=3,y=D(1,10,1),g=D(1,10,1)}for(w=!1;s.neq(n);){if(I=s,s.pow10().recip().tetrate(t,1,!0).eq(1)&&s.pow10().recip().lt(.4))p=s.pow10().recip(),v=s.pow10().recip(),f=s.pow10().recip(),l=o.dZero,h=-1,e==3&&(g=s);else if(s.pow10().recip().tetrate(t,1,!0).eq(s.pow10().recip())&&!u&&s.pow10().recip().lt(.4))p=s.pow10().recip(),v=s.pow10().recip(),f=s.pow10().recip(),l=o.dZero,h=0;else if(s.pow10().recip().tetrate(t,1,!0).eq(s.pow10().recip().mul(2).tetrate(t,1,!0)))p=s.pow10().recip(),v=o.dZero,f=p.mul(2),l=p,u?h=-1:h=0;else{for(c=s.mul(12e-17),p=s.pow10().recip(),v=s.add(c).pow10().recip(),l=p.sub(v),f=p.add(l);v.tetrate(t,1,!0).eq(p.tetrate(t,1,!0))||f.tetrate(t,1,!0).eq(p.tetrate(t,1,!0))||v.gte(p)||f.lte(p);)c=c.mul(2),v=s.add(c).pow10().recip(),l=p.sub(v),f=p.add(l);if((e==1&&f.tetrate(t,1,!0).gt(p.tetrate(t,1,!0))&&v.tetrate(t,1,!0).gt(p.tetrate(t,1,!0))||e==3&&f.tetrate(t,1,!0).lt(p.tetrate(t,1,!0))&&v.tetrate(t,1,!0).lt(p.tetrate(t,1,!0)))&&(g=s),f.tetrate(t,1,!0).lt(p.tetrate(t,1,!0)))h=-1;else if(u)h=1;else if(e==3&&s.gt_tolerance(r,1e-8))h=0;else{for(;v.tetrate(t,1,!0).eq_tolerance(p.tetrate(t,1,!0),1e-8)||f.tetrate(t,1,!0).eq_tolerance(p.tetrate(t,1,!0),1e-8)||v.gte(p)||f.lte(p);)c=c.mul(2),v=s.add(c).pow10().recip(),l=p.sub(v),f=p.add(l);f.tetrate(t,1,!0).sub(p.tetrate(t,1,!0)).lt(p.tetrate(t,1,!0).sub(v.tetrate(t,1,!0)))?h=0:h=1}}if(h==-1&&(L=!0),e==1&&h==1||e==3&&h!=0)if(n.eq(D(1,10,1)))s=s.mul(2);else{let m=!1;if(w&&(h==1&&e==1||h==-1&&e==3)&&(m=!0),s=s.add(n).div(2),m)break}else if(n.eq(D(1,10,1)))n=s,s=s.div(2);else{let m=!1;if(w&&(h==1&&e==1||h==-1&&e==3)&&(m=!0),n=n.sub(y),s=s.sub(y),m)break}if(n.sub(s).div(2).abs().gt(y.mul(1.5))&&(w=!0),y=n.sub(s).div(2).abs(),s.gt("1e18")||s.eq(I))break}if(s.gt("1e18")||!L||g==D(1,10,1))break;e==1?r=g:e==3&&(i=g),e++}n=r,s=D(1,1,-18);let F=s,a=o.dZero,S=!0;for(;S;)if(n.eq(D(1,10,1))?a=s.mul(2):a=n.add(s).div(2),o.pow(10,a).recip().tetrate(t,1,!0).gt(this)?s=a:n=a,a.eq(F)?S=!1:F=a,s.gt("1e18"))return o.dNaN;if(a.eq_tolerance(r,1e-15)){if(i.eq(D(1,10,1)))return o.dNaN;for(n=D(1,10,1),s=i,F=s,a=o.dZero,S=!0;S;)if(n.eq(D(1,10,1))?a=s.mul(2):a=n.add(s).div(2),o.pow(10,a).recip().tetrate(t,1,!0).gt(this)?s=a:n=a,a.eq(F)?S=!1:F=a,s.gt("1e18"))return o.dNaN;return a.pow10().recip()}else return a.pow10().recip()}}pentate(t=2,e=Y(1,0,1),r=!1){e=N(e);let i=t;t=Math.trunc(t);let n=i-t;n!==0&&(e.eq(o.dOne)?(++t,e=o.fromNumber(n)):this.eq(10)?e=e.layeradd10(n,r):e=e.layeradd(n,this,r));for(let s=0;s10)return e}return e}sin(){return this.mag<0?this:this.layer===0?o.fromNumber(Math.sin(this.sign*this.mag)):Y(0,0,0)}cos(){return this.mag<0?o.dOne:this.layer===0?o.fromNumber(Math.cos(this.sign*this.mag)):Y(0,0,0)}tan(){return this.mag<0?this:this.layer===0?o.fromNumber(Math.tan(this.sign*this.mag)):Y(0,0,0)}asin(){return this.mag<0?this:this.layer===0?o.fromNumber(Math.asin(this.sign*this.mag)):Y(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?o.fromNumber(Math.acos(this.toNumber())):this.layer===0?o.fromNumber(Math.acos(this.sign*this.mag)):Y(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?this:this.layer===0?o.fromNumber(Math.atan(this.sign*this.mag)):o.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return o.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return o.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?Y(Number.NaN,Number.NaN,Number.NaN):o.ln(this.add(1).div(o.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?this:this.root(o.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,i){return new o(t).add(new o(e).minus(new o(t)).times(new o(r)).times(new o(i)))}clone(){return this}static clone(t){return o.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=i.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(i=i.sub(t).div(e).add(t))),i}static softcap(t,e,r,i){return new o(t).softcap(e,r,i)}scale(t,e,r,i=!1){t=new o(t),e=new o(e);let n=this.clone();return n.gte(t)&&([0,"pow"].includes(r)&&(n=i?n.mul(t.pow(e.sub(1))).root(e):n.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(n=i?n.div(t).max(1).log(e).add(t):o.pow(e,n.sub(t)).mul(t))),n}static scale(t,e,r,i,n=!1){return new o(t).scale(e,r,i,n)}format(t=2,e=9,r="mixed_sc"){return pt.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return pt.format(new o(t),e,r,i)}formatST(t=2,e=9,r="st"){return pt.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return pt.format(new o(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return pt.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,n){return pt.formatGain(new o(t),e,r,i,n)}toRoman(t=5e3){t=new o(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),i={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},n="";for(let s of Object.keys(i)){let c=Math.floor(r/i[s]);r-=c*i[s],n+=s.repeat(c)}return n}static toRoman(t,e){return new o(t).toRoman(e)}static random(t=0,e=1){return t=new o(t),e=new o(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new o(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new o(Math.random()).lt(t)}};o.dZero=Y(0,0,0),o.dOne=Y(1,0,1),o.dNegOne=Y(-1,0,1),o.dTwo=Y(1,0,2),o.dTen=Y(1,0,10),o.dNaN=Y(Number.NaN,Number.NaN,Number.NaN),o.dInf=Y(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),o.dNegInf=Y(-1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),o.dNumberMax=D(1,0,Number.MAX_VALUE),o.dNumberMin=D(1,0,Number.MIN_VALUE),o.fromStringCache=new Rt(ur),lt([Tt()],o.prototype,"sign",2),lt([Tt()],o.prototype,"mag",2),lt([Tt()],o.prototype,"layer",2),o=lt([tr()],o);var{formats:pt,FORMATS:pr}=rr(o);o.formats=pt;var P=(()=>{let t=e=>new o(e);return Object.getOwnPropertyNames(o).filter(e=>!Object.getOwnPropertyNames(class{}).includes(e)).forEach(e=>{t[e]=o[e]}),t})(),Nt=class{get desc(){return this.description}get description(){return this.descriptionFn()}constructor(t){this.id=t.id,this.name=t.name??"",this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>"",this.value=t.value,this.order=t.order??99}},$t=class{constructor(t=1,e){this.addBoost=this.setBoost.bind(this),e=e?Array.isArray(e)?e:[e]:void 0,this.baseEffect=P(t),this.boostArray=[],e&&e.forEach(r=>{this.boostArray.push(new Nt(r))})}getBoosts(t,e){let r=[],i=[];for(let n=0;nf),l=n,v=this.getBoosts(s,!0);v[0][0]?this.boostArray[v[1][0]]=new Nt({id:s,name:c,description:y,value:p,order:l}):this.boostArray.push(new Nt({id:s,name:c,description:y,value:p,order:l}))}else{t=Array.isArray(t)?t:[t];for(let s of t){let c=this.getBoosts(s.id,!0);c[0][0]?this.boostArray[c[1][0]]=new Nt(s):this.boostArray.push(new Nt(s))}}}calculate(t=this.baseEffect){let e=P(t),r=this.boostArray;r=r.sort((i,n)=>i.order-n.order);for(let i of r)e=i.value(e);return e}},$r=ot(ct()),xt=30,ue=.001;function le(t,e,r,i){i=Object.assign({},{verbose:!1,mode:"geometric"},i),t=P(t),e=P(e),r=P(r);let n,s;return i.mode==="geometric"?(n=t.sub(e).abs().div(t.abs().add(e.abs()).div(2)),s=n.lte(r)):(n=t.sub(e).abs(),s=n.lte(r)),(i.verbose===!0||i.verbose==="onlyOnFail"&&!s)&&console.log({a:t,b:e,tolerance:r,config:i,diff:n,result:s}),s}function zt(t,e,r="geometric",i=xt,n=ue){let s=P(1),c=P(e);if(t(c).eq(0))return{value:P(0),lowerBound:P(0),upperBound:P(0)};if(t(c).lt(e))return console.warn("The function is not monotonically increasing. (f(n) < n)"),{value:c,lowerBound:c,upperBound:c};for(let p=0;pe.cost(g.add(r)),u=P.min(i,zt(f,t,n,s).value.floor()),h=P(0);return[u,h]}let p=zt(f=>Yt(e.cost,f,r),t,n,s).value.floor().min(r.add(y).sub(1)),l=Yt(e.cost,p,r);return[p.sub(r).add(1).max(0),l]}function de(t){return t=P(t),`${t.sign}/${t.mag}/${t.layer}`}function yr(t){return`el/${de(t)}`}var vt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?P(t.level):P(1)}};lt([Tt()],vt.prototype,"id",2),lt([Ft(()=>o)],vt.prototype,"level",2);var me=class De{static{this.cacheSize=15}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn()}get level(){return((this??{data:{level:P(1)}}).data??{level:P(1)}).level}set level(e){this.data.level=P(e)}constructor(e,r,i){let n=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>n,this.cache=new Rt(i??De.cacheSize),this.id=e.id,this.name=e.name??e.id,this.descriptionFn=e.description?typeof e.description=="function"?e.description:()=>e.description:()=>"",this.cost=e.cost,this.costBulk=e.costBulk,this.maxLevel=e.maxLevel,this.effect=e.effect,this.el=e.el,this.defaultLevel=e.level??P(1)}},zr=ot(ct()),yt=class{constructor(){this.value=P(0),this.upgrades={}}};lt([Ft(()=>o)],yt.prototype,"value",2),lt([Ft(()=>vt)],yt.prototype,"upgrades",2);var ge=class{get pointer(){return this.pointerFn()}get value(){return this.pointer.value}set value(t){this.pointer.value=t}constructor(t=new yt,e,r={defaultVal:P(0),defaultBoost:P(1)}){this.defaultVal=r.defaultVal,this.defaultBoost=r.defaultBoost,this.pointerFn=typeof t=="function"?t:()=>t,this.boost=new $t(this.defaultBoost),this.pointer.value=this.defaultVal,this.upgrades={},e&&this.addUpgrade(e)}onLoadData(){for(let t of Object.values(this.upgrades))t.effect?.(t.level,t,this)}reset(t=!0,e=!0,r=!0){if(t&&(this.value=this.defaultVal),e)for(let i of Object.values(this.upgrades))i.level=P(i.defaultLevel),r&&i.effect?.(i.level,i,this)}gain(t=1e3){let e=this.boost.calculate().mul(P(t).div(1e3));return this.pointer.value=this.pointer.value.add(e),e}pointerAddUpgrade(t){let e=new vt(t);return this.pointer.upgrades[e.id]=e,e}pointerGetUpgrade(t){return this.pointer.upgrades[t]??null}getUpgrade(t){return this.upgrades[t]??null}addUpgrade(t,e=!0){Array.isArray(t)||(t=[t]);let r={};for(let i of t){let n=this.pointerAddUpgrade(i),s=new me(i,()=>this.pointerGetUpgrade(i.id));s.effect&&e&&s.effect(s.level,s,this),r[i.id]=s,this.upgrades[i.id]=s}return Object.values(r)}updateUpgrade(t,e){let r=this.getUpgrade(t);r!==null&&(r.name=e.name??r.name,r.cost=e.cost??r.cost,r.maxLevel=e.maxLevel??r.maxLevel,r.effect=e.effect??r.effect)}calculateUpgrade(t,e=1/0,r,i){let n=this.getUpgrade(t);return n===null?(console.warn(`Upgrade "${t}" not found.`),[P(0),P(0)]):(e=n.level.add(e),n.maxLevel!==void 0&&(e=P.min(e,n.maxLevel)),he(this.value,n,n.level,e,r,i))}getNextCost(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),P(0);let s=this.calculateUpgrade(t,e,r,i)[0];return n.cost(n.level.add(s))}getNextCostMax(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),P(0);let s=this.calculateUpgrade(t,e,r,i);return n.cost(n.level.add(s[0])).add(s[1])}buyUpgrade(t,e,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),!1;let[s,c]=this.calculateUpgrade(t,e,r,i);return s.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(c),n.level=n.level.add(s),n.effect?.(n.level,n,this),!0)}},Yr=ot(ct()),Lt=class{constructor(t=0){this.value=P(t)}};lt([Ft(()=>o)],Lt.prototype,"value",2);var pe=class{get pointer(){return this.pointerFn()}constructor(t,e=!0,r=0){this.initial=P(r),t??=new Lt(this.initial),this.pointerFn=typeof t=="function"?t:()=>t,this.boost=e?new $t(this.initial):null}update(){console.warn("AttributeStatic.update is deprecated and will be removed in the future. The value is automatically updated when accessed."),this.boost&&(this.pointer.value=this.boost.calculate())}get value(){return this.boost&&(this.pointer.value=this.boost.calculate()),this.pointer.value}set value(t){if(this.boost)throw new Error("Cannot set value of attributeStatic when boost is enabled.");this.pointer.value=t}},ve=class{constructor(t,e,r){this.x=t,this.y=e,this.properties=r??{}}setValue(t,e){return this.properties[t]=e,e}getValue(t){return this.properties[t]}},br=class{constructor(t,e,r){this.xSize=t,this.ySize=e,this.cells=[];for(let i=0;ikt,DataManager:()=>_e,EventManager:()=>Me,EventTypes:()=>we,Game:()=>_r,GameAttribute:()=>Ae,GameCurrency:()=>Se,GameReset:()=>Oe,KeyManager:()=>be,gameDefaultConfig:()=>Ie,keys:()=>Mr});var Zr=ot(ct()),kt=class{constructor(t){this.configOptionTemplate=t}parse(t){if(typeof t>"u")return this.configOptionTemplate;function e(r,i){for(let n in i)typeof r[n]>"u"?r[n]=i[n]:typeof r[n]=="object"&&typeof i[n]=="object"&&!Array.isArray(r[n])&&!Array.isArray(i[n])&&(r[n]=e(r[n],i[n]));return r}return e(t,this.configOptionTemplate)}get options(){return this.configOptionTemplate}},wr={autoAddInterval:!0,fps:30},Mr="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ".split("").concat(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]),be=class Re{constructor(e){if(this.addKeys=this.addKey.bind(this),this.keysPressed=[],this.binds=[],this.tickers=[],this.config=Re.configManager.parse(e),this.config.autoAddInterval){let r=this.config.fps?this.config.fps:30;this.tickerInterval=setInterval(()=>{for(let i of this.tickers)i(1e3/r)},1e3/r)}typeof document>"u"||(this.tickers.push(r=>{for(let i of this.binds)(typeof i.onDownContinuous<"u"||typeof i.fn<"u")&&this.isPressing(i.id)&&(i.onDownContinuous?.(r),i.fn?.(r))}),document.addEventListener("keydown",r=>{this.logKey(r,!0),this.onAll("down",r.key)}),document.addEventListener("keyup",r=>{this.logKey(r,!1),this.onAll("up",r.key)}),document.addEventListener("keypress",r=>{this.onAll("press",r.key)}))}static{this.configManager=new kt(wr)}changeFps(e){this.config.fps=e,this.tickerInterval&&(clearInterval(this.tickerInterval),this.tickerInterval=setInterval(()=>{for(let r of this.tickers)r(1e3/e)},1e3/e))}logKey(e,r){let i=e.key;r&&!this.keysPressed.includes(i)?this.keysPressed.push(i):!r&&this.keysPressed.includes(i)&&this.keysPressed.splice(this.keysPressed.indexOf(i),1)}onAll(e,r){for(let i of this.binds)if(i.key===r)switch(e){case"down":i.onDown?.();break;case"press":default:i.onPress?.();break;case"up":i.onUp?.();break}}isPressing(e){for(let r of this.binds)if(r.id===e)return this.keysPressed.includes(r.key);return!1}getBind(e){return this.binds.find(r=>r.id===e)}addKey(e,r,i){e=typeof e=="string"?[{id:e,name:e,key:r??"",fn:i}]:e,e=Array.isArray(e)?e:[e];for(let n of e){n.id=n.id??n.name;let s=this.getBind(n.id);if(s){Object.assign(s,n);continue}this.binds.push(n)}}},we=(t=>(t.interval="interval",t.timeout="timeout",t))(we||{}),Nr={autoAddInterval:!0,fps:30},Me=class je{constructor(e){if(this.addEvent=this.setEvent.bind(this),this.config=je.configManager.parse(e),this.events={},this.config.autoAddInterval){let r=this.config.fps??30;this.tickerInterval=setInterval(()=>{this.tickerFunction()},1e3/r)}}static{this.configManager=new kt(Nr)}tickerFunction(){let e=Date.now();for(let r of Object.values(this.events))switch(r.type){case"interval":if(e-r.intervalLast>=r.delay){let i=e-r.intervalLast;r.callbackFn(i),r.intervalLast=e}break;case"timeout":{let i=e-r.timeCreated;e-r.timeCreated>=r.delay&&(r.callbackFn(i),delete this.events[r.name])}break}}changeFps(e){this.config.fps=e,this.tickerInterval&&(clearInterval(this.tickerInterval),this.tickerInterval=setInterval(()=>{this.tickerFunction()},1e3/e))}timeWarp(e){for(let r of Object.values(this.events))switch(r.type){case"interval":r.intervalLast-=e;break;case"timeout":r.timeCreated-=e;break}}setEvent(e,r,i,n){this.events[e]=(()=>{switch(r){case"interval":return{name:e,type:r,delay:typeof i=="number"?i:i.toNumber(),callbackFn:n,timeCreated:Date.now(),intervalLast:Date.now()};case"timeout":default:return{name:e,type:r,delay:typeof i=="number"?i:i.toNumber(),callbackFn:n,timeCreated:Date.now()}}})()}removeEvent(e){delete this.events[e]}},Hr=ot(ct()),Ne=ot(Ye()),Zt=ot(Ve()),_e=class{constructor(t){this.data={},this.static={},this.eventsOnLoad=[],this.gameRef=typeof t=="function"?t():t}addEventOnLoad(t){this.eventsOnLoad.push(t)}setData(t,e){typeof this.data[t]>"u"&&this.normalData&&console.warn("After initializing data, you should not add new properties to data."),this.data[t]=e;let r=()=>this.data;return{get value(){return r()[t]},set value(i){r()[t]=i},setValue(i){r()[t]=i}}}getData(t){return this.data[t]}setStatic(t,e){return typeof this.static[t]>"u"&&this.normalData&&console.warn("After initializing data, you should not add new properties to staticData."),this.static[t]=e,this.static[t]}getStatic(t){return this.static[t]}init(){this.normalData=this.data,this.normalDataPlain=jt(this.data)}compileDataRaw(t=this.data){let e=jt(t),r=(0,Zt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(e)}`),i;try{i="8.4.0"}catch{i="8.3.0"}return[{hash:r,game:{title:this.gameRef.config.name.title,id:this.gameRef.config.name.id,version:this.gameRef.config.name.version},emath:{version:i}},e]}compileData(t=this.data){let e=JSON.stringify(this.compileDataRaw(t));return(0,Ne.compressToBase64)(e)}decompileData(t=window.localStorage.getItem(`${this.gameRef.config.name.id}-data`)){if(!t)return null;let e;try{return e=JSON.parse((0,Ne.decompressFromBase64)(t)),e}catch(r){if(r instanceof SyntaxError)console.error(`Failed to decompile data (corrupted) "${t}":`,r);else throw r;return null}}validateData(t){let[e,r]=t;if(typeof e=="string")return(0,Zt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`)===e;let i=e.hash,n=(0,Zt.default)(`${this.gameRef.config.name.id}/${JSON.stringify(r)}`);return i===n}resetData(t=!1){if(!this.normalData)throw new Error("dataManager.resetData(): You must call init() before writing to data.");this.data=this.normalData,this.saveData(),t&&window.location.reload()}saveData(t=this.compileData()){if(!t)throw new Error("dataManager.saveData(): Data to save is empty.");if(!window.localStorage)throw new Error("dataManager.saveData(): Local storage is not supported. You can use compileData() instead to implement a custom save system.");window.localStorage.setItem(`${this.gameRef.config.name.id}-data`,t)}exportData(){let t=this.compileData();if(prompt("Download save data?:",t)!=null){let e=new Blob([t],{type:"text/plain"}),r=document.createElement("a");r.href=URL.createObjectURL(e),r.download=`${this.gameRef.config.name.id}-data.txt`,r.textContent=`Download ${this.gameRef.config.name.id}-data.txt file`,document.body.appendChild(r),r.click(),document.body.removeChild(r)}}parseData(t=this.decompileData(),e=!0){if((!this.normalData||!this.normalDataPlain)&&e)throw new Error("dataManager.parseData(): You must call init() before writing to data.");if(!t)return null;let[,r]=t;function i(v){return typeof v=="object"&&v?.constructor===Object}let n=(v,f)=>Object.prototype.hasOwnProperty.call(v,f);function s(v,f,u){if(!v||!f||!u)throw new Error("dataManager.deepMerge(): Missing arguments.");let h=u;for(let g in v)if(n(v,g)&&!n(u,g)&&(h[g]=v[g]),f[g]instanceof yt){let w=v[g],I=u[g];if(Array.isArray(I.upgrades)){let L=I.upgrades;I.upgrades={};for(let F of L)I.upgrades[F.id]=F}I.upgrades={...w.upgrades,...I.upgrades},h[g]=I}else i(v[g])&&i(u[g])&&(h[g]=s(v[g],f[g],u[g]));return h}let c=e?s(this.normalDataPlain,this.normalData,r):r,y=Object.getOwnPropertyNames(new vt({id:"",level:P(0)}));function p(v,f){let u=ie(v,f);if(u instanceof yt)for(let h in u.upgrades){let g=u.upgrades[h];if(!g||!y.every(w=>Object.getOwnPropertyNames(g).includes(w))){delete u.upgrades[h];continue}u.upgrades[h]=ie(vt,g)}if(!u)throw new Error(`Failed to convert ${v.name} to class instance.`);return u}function l(v,f){if(!v||!f)throw new Error("dataManager.plainToInstanceRecursive(): Missing arguments.");let u=f;for(let h in v){if(f[h]===void 0){console.warn(`Missing property "${h}" in loaded data.`);continue}if(!i(f[h]))continue;let g=v[h].constructor;if(g===Object){u[h]=l(v[h],f[h]);continue}u[h]=p(g,f[h])}return u}return c=l(this.normalData,c),c}loadData(t=this.decompileData()){if(t=typeof t=="string"?this.decompileData(t):t,!t)return null;let e=this.validateData([t[0],jt(t[1])]),r=this.parseData(t);if(!r)return null;this.data=r;for(let i of this.eventsOnLoad)i();return e}},Se=class{get data(){return this.dataPointer()}get static(){return this.staticPointer()}constructor(t,e,r,i){this.dataPointer=typeof t=="function"?t:()=>t,this.staticPointer=typeof e=="function"?e:()=>e,this.game=r,this.name=i,this.game.dataManager.addEventOnLoad(()=>{this.static.onLoadData()})}get value(){return this.data.value}},Ae=class{constructor(t,e,r){this.data=typeof t=="function"?t():t,this.static=typeof e=="function"?e():e,this.game=r}get value(){return this.static.value}set value(t){this.data.value=t}},Oe=class{constructor(t,e){this.currenciesToReset=Array.isArray(t)?t:[t],this.extender=Array.isArray(e)?e:e?[e]:[],this.id=Symbol()}reset(){this.onReset?.(this),this.currenciesToReset.forEach(t=>{t.static.reset()}),this.extender.forEach(t=>{t.id!==this.id&&t.reset()})}},Ie={mode:"production",name:{title:"",id:"",version:"0.0.0"},settings:{framerate:30},initIntervalBasedManagers:!0},_r=class Ge{static{this.configManager=new kt(Ie)}constructor(e){this.config=Ge.configManager.parse(e),this.dataManager=new _e(this),this.keyManager=new be({autoAddInterval:this.config.initIntervalBasedManagers,fps:this.config.settings.framerate}),this.eventManager=new Me({autoAddInterval:this.config.initIntervalBasedManagers,fps:this.config.settings.framerate}),this.tickers=[]}init(){this.dataManager.init()}changeFps(e){this.keyManager.changeFps(e),this.eventManager.changeFps(e)}addCurrency(e,r=[]){return this.dataManager.setData(e,{currency:new yt}),this.dataManager.setStatic(e,{currency:new ge(()=>this.dataManager.getData(e).currency,r)}),new Se(()=>this.dataManager.getData(e).currency,()=>this.dataManager.getStatic(e).currency,this,e)}addAttribute(e,r=!0,i=0){return this.dataManager.setData(e,new Lt(i)),this.dataManager.setStatic(e,new pe(this.dataManager.getData(e),r,i)),new Ae(this.dataManager.getData(e),this.dataManager.getStatic(e),this)}addReset(e,r){return new Oe(e,r)}},Sr={...Kt,...ye};if(typeof at.exports=="object"&&typeof At=="object"){var Ar=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,n)&&n!==r&&Object.defineProperty(t,n,{get:()=>e[n],enumerable:!(i=Object.getOwnPropertyDescriptor(e,n))||i.enumerable});return t};at.exports=Ar(at.exports,At)}return at.exports}); /*! Bundled license information: reflect-metadata/Reflect.js: diff --git a/dist/game/eMath.game.mjs b/dist/game/eMath.game.mjs index 7f7517c..3d04fcc 100644 --- a/dist/game/eMath.game.mjs +++ b/dist/game/eMath.game.mjs @@ -5477,7 +5477,7 @@ import "reflect-metadata"; import { Type, Expose as Expose2 } from "class-transformer"; // src/classes/numericalAnalysis.ts -var DEFAULT_ITERATIONS = 35; +var DEFAULT_ITERATIONS = 30; var DEFAULT_TOLERANCE = 1e-3; function equalsTolerance(a, b, tolerance, config) { config = Object.assign({}, { @@ -5532,7 +5532,8 @@ function inverseFunctionApprox(f, n, mode = "geometric", iterations = DEFAULT_IT const midValue = f(mid); if (equalsTolerance(lowerBound, upperBound, tolerance, { verbose: false, mode: "geometric" })) { break; - } else if (midValue.lt(n)) { + } + if (midValue.lt(n)) { lowerBound = mid; } else { upperBound = mid; @@ -5624,16 +5625,6 @@ function calculateUpgrade(value, upgrade, start, end = Infinity, mode, iteration const maxLevelAffordableActual = maxLevelAffordable.sub(start).add(1).max(0); return [maxLevelAffordableActual, cost]; } -function decimalToJSONString(n) { - n = E(n); - return `${n.sign}/${n.mag}/${n.layer}`; -} -function upgradeToCacheNameSum(start, end) { - return `sum/${decimalToJSONString(start)}/${decimalToJSONString(end)}}`; -} -function upgradeToCacheNameEL(level) { - return `el/${decimalToJSONString(level)}`; -} var UpgradeData = class { /** * Constructs a new upgrade object with an initial level of 1 (or the provided level) @@ -5654,7 +5645,7 @@ __decorateClass([ var UpgradeStatic = class _UpgradeStatic { static { /** The default size of the cache. Should be one less than a power of 2. */ - this.cacheSize = 63; + this.cacheSize = 15; } /** @returns The data of the upgrade. */ get data() { @@ -5677,7 +5668,7 @@ var UpgradeStatic = class _UpgradeStatic { * Constructs a new static upgrade object. * @param init - The upgrade object to initialize. * @param dataPointer - A function or reference that returns the pointer of the data / frontend. - * @param cacheSize - The size of the cache. Should be one less than a power of 2. See {@link cache} + * @param cacheSize - The size of the cache. Should be one less than a power of 2. See {@link cache}. Set to `0` to disable caching. */ constructor(init, dataPointer, cacheSize) { const data = typeof dataPointer === "function" ? dataPointer() : dataPointer; @@ -5693,33 +5684,51 @@ var UpgradeStatic = class _UpgradeStatic { this.el = init.el; this.defaultLevel = init.level ?? E(1); } - getCached(type, start, end) { - if (type === "sum") { - return this.cache.get(upgradeToCacheNameSum(start, end ?? E(0))); - } else { - return this.cache.get(upgradeToCacheNameEL(start)); - } - } - setCached(type, start, endOrStart, costSum) { - const data = type === "sum" ? { - id: this.id, - el: false, - start: E(start), - end: E(endOrStart), - cost: E(costSum) - } : { - id: this.id, - el: true, - level: E(start), - cost: E(endOrStart) - }; - if (type === "sum") { - this.cache.set(upgradeToCacheNameSum(start, endOrStart), data); - } else { - this.cache.set(upgradeToCacheNameEL(start), data); - } - return data; - } + // /** + // * Gets the cached data of the upgrade. + // * @param type - The type of the cache. "sum" or "el" + // * @param start - The starting level of the upgrade. + // * @param end - The ending level or quantity to reach for the upgrade. + // * @returns The data of the upgrade. + // */ + // public getCached (type: "sum", start: ESource, end: ESource): UpgradeCachedSum | undefined; + // public getCached (type: "el", start: ESource): UpgradeCachedEL | undefined; + // public getCached (type: "sum" | "el", start: ESource, end?: ESource): UpgradeCachedEL | UpgradeCachedSum | undefined { + // if (type === "sum") { + // return this.cache.get(upgradeToCacheNameSum(start, end ?? E(0))); + // } else { + // return this.cache.get(upgradeToCacheNameEL(start)); + // } + // } + // /** + // * Sets the cached data of the upgrade. + // * @param type - The type of the cache. "sum" or "el" + // * @param start - The starting level of the upgrade. + // * @param end - The ending level or quantity to reach for the upgrade. + // * @param cost - The cost of the upgrade. + // */ + // public setCached(type: "sum", start: ESource, end: ESource, cost: ESource): UpgradeCachedSum; + // public setCached(type: "el", level: ESource, cost: ESource): UpgradeCachedEL; + // public setCached (type: "sum" | "el", start: ESource, endOrStart: ESource, costSum?: ESource): UpgradeCachedEL | UpgradeCachedSum { + // const data = type === "sum" ? { + // id: this.id, + // el: false, + // start: E(start), + // end: E(endOrStart), + // cost: E(costSum), + // } : { + // id: this.id, + // el: true, + // level: E(start), + // cost: E(endOrStart), + // }; + // if (type === "sum") { + // this.cache.set(upgradeToCacheNameSum(start, endOrStart), data as UpgradeCachedSum); + // } else { + // this.cache.set(upgradeToCacheNameEL(start), data as UpgradeCachedEL); + // } + // return data as UpgradeCachedEL | UpgradeCachedSum; + // } }; // src/classes/Currency.ts @@ -6538,7 +6547,7 @@ var DataManager = class { const hasedData = (0, import_md5.default)(`${this.gameRef.config.name.id}/${JSON.stringify(gameDataString)}`); let version; try { - version = "8.3.0"; + version = "8.4.0"; } catch (error) { version = "8.3.0"; } diff --git a/dist/main/eMath.js b/dist/main/eMath.js index 731ffdd..cdbdb79 100644 --- a/dist/main/eMath.js +++ b/dist/main/eMath.js @@ -4802,7 +4802,7 @@ var import_reflect_metadata = require("reflect-metadata"); var import_class_transformer2 = require("class-transformer"); // src/classes/numericalAnalysis.ts -var DEFAULT_ITERATIONS = 35; +var DEFAULT_ITERATIONS = 30; var DEFAULT_TOLERANCE = 1e-3; function equalsTolerance(a, b, tolerance, config) { config = Object.assign({}, { @@ -4857,7 +4857,8 @@ function inverseFunctionApprox(f, n, mode = "geometric", iterations = DEFAULT_IT const midValue = f(mid); if (equalsTolerance(lowerBound, upperBound, tolerance, { verbose: false, mode: "geometric" })) { break; - } else if (midValue.lt(n)) { + } + if (midValue.lt(n)) { lowerBound = mid; } else { upperBound = mid; @@ -4903,14 +4904,14 @@ function calculateSum(f, b, a = 0, epsilon, iterations) { return calculateSumApprox(f, b, a, iterations); } } -function roundingBase(x, acc = 10, sig = 0, max = 1e3) { +function roundingBase(x, base = 10, acc = 0, max = 1e3) { x = E(x); - if (x.gte(E.pow(acc, max))) return x; - const powerN = E.floor(E.log(x, acc)); - let out = x.div(E.pow(acc, powerN)); - out = out.mul(E.pow(acc, sig)).round(); - out = out.div(E.pow(acc, sig)); - out = out.mul(E.pow(acc, powerN)); + if (x.gte(E.pow(base, max))) return x; + const powerN = E.floor(E.log(x, base)); + let out = x.div(E.pow(base, powerN)); + out = out.mul(E.pow(base, acc)).round(); + out = out.div(E.pow(base, acc)); + out = out.mul(E.pow(base, powerN)); return out; } @@ -4963,9 +4964,6 @@ function decimalToJSONString(n) { n = E(n); return `${n.sign}/${n.mag}/${n.layer}`; } -function upgradeToCacheNameSum(start, end) { - return `sum/${decimalToJSONString(start)}/${decimalToJSONString(end)}}`; -} function upgradeToCacheNameEL(level) { return `el/${decimalToJSONString(level)}`; } @@ -4989,7 +4987,7 @@ __decorateClass([ var UpgradeStatic = class _UpgradeStatic { static { /** The default size of the cache. Should be one less than a power of 2. */ - this.cacheSize = 63; + this.cacheSize = 15; } /** @returns The data of the upgrade. */ get data() { @@ -5012,7 +5010,7 @@ var UpgradeStatic = class _UpgradeStatic { * Constructs a new static upgrade object. * @param init - The upgrade object to initialize. * @param dataPointer - A function or reference that returns the pointer of the data / frontend. - * @param cacheSize - The size of the cache. Should be one less than a power of 2. See {@link cache} + * @param cacheSize - The size of the cache. Should be one less than a power of 2. See {@link cache}. Set to `0` to disable caching. */ constructor(init, dataPointer, cacheSize) { const data = typeof dataPointer === "function" ? dataPointer() : dataPointer; @@ -5028,33 +5026,51 @@ var UpgradeStatic = class _UpgradeStatic { this.el = init.el; this.defaultLevel = init.level ?? E(1); } - getCached(type, start, end) { - if (type === "sum") { - return this.cache.get(upgradeToCacheNameSum(start, end ?? E(0))); - } else { - return this.cache.get(upgradeToCacheNameEL(start)); - } - } - setCached(type, start, endOrStart, costSum) { - const data = type === "sum" ? { - id: this.id, - el: false, - start: E(start), - end: E(endOrStart), - cost: E(costSum) - } : { - id: this.id, - el: true, - level: E(start), - cost: E(endOrStart) - }; - if (type === "sum") { - this.cache.set(upgradeToCacheNameSum(start, endOrStart), data); - } else { - this.cache.set(upgradeToCacheNameEL(start), data); - } - return data; - } + // /** + // * Gets the cached data of the upgrade. + // * @param type - The type of the cache. "sum" or "el" + // * @param start - The starting level of the upgrade. + // * @param end - The ending level or quantity to reach for the upgrade. + // * @returns The data of the upgrade. + // */ + // public getCached (type: "sum", start: ESource, end: ESource): UpgradeCachedSum | undefined; + // public getCached (type: "el", start: ESource): UpgradeCachedEL | undefined; + // public getCached (type: "sum" | "el", start: ESource, end?: ESource): UpgradeCachedEL | UpgradeCachedSum | undefined { + // if (type === "sum") { + // return this.cache.get(upgradeToCacheNameSum(start, end ?? E(0))); + // } else { + // return this.cache.get(upgradeToCacheNameEL(start)); + // } + // } + // /** + // * Sets the cached data of the upgrade. + // * @param type - The type of the cache. "sum" or "el" + // * @param start - The starting level of the upgrade. + // * @param end - The ending level or quantity to reach for the upgrade. + // * @param cost - The cost of the upgrade. + // */ + // public setCached(type: "sum", start: ESource, end: ESource, cost: ESource): UpgradeCachedSum; + // public setCached(type: "el", level: ESource, cost: ESource): UpgradeCachedEL; + // public setCached (type: "sum" | "el", start: ESource, endOrStart: ESource, costSum?: ESource): UpgradeCachedEL | UpgradeCachedSum { + // const data = type === "sum" ? { + // id: this.id, + // el: false, + // start: E(start), + // end: E(endOrStart), + // cost: E(costSum), + // } : { + // id: this.id, + // el: true, + // level: E(start), + // cost: E(endOrStart), + // }; + // if (type === "sum") { + // this.cache.set(upgradeToCacheNameSum(start, endOrStart), data as UpgradeCachedSum); + // } else { + // this.cache.set(upgradeToCacheNameEL(start), data as UpgradeCachedEL); + // } + // return data as UpgradeCachedEL | UpgradeCachedSum; + // } }; // src/classes/Currency.ts diff --git a/dist/main/eMath.min.js b/dist/main/eMath.min.js index 06a5dc2..415f25c 100644 --- a/dist/main/eMath.min.js +++ b/dist/main/eMath.min.js @@ -1,4 +1,4 @@ -"use strict";(function(pt,nt){var wt=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],nt);else if(typeof module=="object"&&module.exports)module.exports=nt();else{var ot=nt(),_t=wt?exports:pt;for(var yt in ot)_t[yt]=ot[yt]}})(typeof self<"u"?self:exports,()=>{var pt={},nt={exports:pt},wt=Object.create,ot=Object.defineProperty,_t=Object.getOwnPropertyDescriptor,yt=Object.getOwnPropertyNames,be=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty,Ne=(t,e)=>function(){return e||(0,t[yt(t)[0]])((e={exports:{}}).exports,e),e.exports},Yt=(t,e)=>{for(var r in e)ot(t,r,{get:e[r],enumerable:!0})},Zt=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of yt(e))!ve.call(t,n)&&n!==r&&ot(t,n,{get:()=>e[n],enumerable:!(i=_t(e,n))||i.enumerable});return t},bt=(t,e,r)=>(r=t!=null?wt(be(t)):{},Zt(e||!t||!t.__esModule?ot(r,"default",{value:t,enumerable:!0}):r,t)),Me=t=>Zt(ot({},"__esModule",{value:!0}),t),at=(t,e,r,i)=>{for(var n=i>1?void 0:i?_t(e,r):e,o=t.length-1,h;o>=0;o--)(h=t[o])&&(n=(i?h(e,r,n):h(n))||n);return i&&n&&ot(e,r,n),n},vt=Ne({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var i=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:d(),n=o(e);typeof i.Reflect<"u"&&(n=o(i.Reflect,n)),r(n,i),typeof i.Reflect>"u"&&(i.Reflect=e);function o(N,T){return function(C,V){Object.defineProperty(N,C,{configurable:!0,writable:!0,value:V}),T&&T(C,V)}}function h(){try{return Function("return this;")()}catch{}}function p(){try{return(0,eval)("(function() { return this; })()")}catch{}}function d(){return h()||p()}})(function(r,i){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",h=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",p=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",d=typeof Object.create=="function",N={__proto__:[]}instanceof Array,T=!d&&!N,C={create:d?function(){return $t(Object.create(null))}:N?function(){return $t({__proto__:null})}:function(){return $t({})},has:T?function(u,l){return n.call(u,l)}:function(u,l){return l in u},get:T?function(u,l){return n.call(u,l)?u[l]:void 0}:function(u,l){return u[l]}},V=Object.getPrototypeOf(Function),x=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:tr(),Z=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:er(),P=typeof WeakMap=="function"?WeakMap:rr(),L=o?Symbol.for("@reflect-metadata:registry"):void 0,Y=Qe(),W=Je(Y);function a(u,l,c,y){if(q(c)){if(!le(u))throw new TypeError;if(!fe(l))throw new TypeError;return J(u,l)}else{if(!le(u))throw new TypeError;if(!z(l))throw new TypeError;if(!z(y)&&!q(y)&&!gt(y))throw new TypeError;return gt(y)&&(y=void 0),c=st(c),rt(u,l,c,y)}}r("decorate",a);function g(u,l){function c(y,E){if(!z(y))throw new TypeError;if(!q(E)&&!We(E))throw new TypeError;Et(u,l,y,E)}return c}r("metadata",g);function m(u,l,c,y){if(!z(c))throw new TypeError;return q(y)||(y=st(y)),Et(u,l,c,y)}r("defineMetadata",m);function b(u,l,c){if(!z(l))throw new TypeError;return q(c)||(c=st(c)),Q(u,l,c)}r("hasMetadata",b);function _(u,l,c){if(!z(l))throw new TypeError;return q(c)||(c=st(c)),K(u,l,c)}r("hasOwnMetadata",_);function O(u,l,c){if(!z(l))throw new TypeError;return q(c)||(c=st(c)),tt(u,l,c)}r("getMetadata",O);function S(u,l,c){if(!z(l))throw new TypeError;return q(c)||(c=st(c)),lt(u,l,c)}r("getOwnMetadata",S);function R(u,l){if(!z(u))throw new TypeError;return q(l)||(l=st(l)),Tt(u,l)}r("getMetadataKeys",R);function k(u,l){if(!z(u))throw new TypeError;return q(l)||(l=st(l)),Ct(u,l)}r("getOwnMetadataKeys",k);function j(u,l,c){if(!z(l))throw new TypeError;if(q(c)||(c=st(c)),!z(l))throw new TypeError;q(c)||(c=st(c));var y=Mt(l,c,!1);return q(y)?!1:y.OrdinaryDeleteMetadata(u,l,c)}r("deleteMetadata",j);function J(u,l){for(var c=u.length-1;c>=0;--c){var y=u[c],E=y(l);if(!q(E)&&!gt(E)){if(!fe(E))throw new TypeError;l=E}}return l}function rt(u,l,c,y){for(var E=u.length-1;E>=0;--E){var H=u[E],D=H(l,c,y);if(!q(D)&&!gt(D)){if(!z(D))throw new TypeError;y=D}}return y}function Q(u,l,c){var y=K(u,l,c);if(y)return!0;var E=jt(l);return gt(E)?!1:Q(u,E,c)}function K(u,l,c){var y=Mt(l,c,!1);return q(y)?!1:ue(y.OrdinaryHasOwnMetadata(u,l,c))}function tt(u,l,c){var y=K(u,l,c);if(y)return lt(u,l,c);var E=jt(l);if(!gt(E))return tt(u,E,c)}function lt(u,l,c){var y=Mt(l,c,!1);if(!q(y))return y.OrdinaryGetOwnMetadata(u,l,c)}function Et(u,l,c,y){var E=Mt(c,y,!0);E.OrdinaryDefineOwnMetadata(u,l,c,y)}function Tt(u,l){var c=Ct(u,l),y=jt(u);if(y===null)return c;var E=Tt(y,l);if(E.length<=0)return c;if(c.length<=0)return E;for(var H=new Z,D=[],B=0,v=c;B=0&&v=this._keys.length?(this._index=-1,this._keys=l,this._values=l):this._index++,{value:w,done:!1}}return{value:void 0,done:!0}},B.prototype.throw=function(v){throw this._index>=0&&(this._index=-1,this._keys=l,this._values=l),v},B.prototype.return=function(v){return this._index>=0&&(this._index=-1,this._keys=l,this._values=l),{value:v,done:!0}},B}(),y=function(){function B(){this._keys=[],this._values=[],this._cacheKey=u,this._cacheIndex=-2}return Object.defineProperty(B.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),B.prototype.has=function(v){return this._find(v,!1)>=0},B.prototype.get=function(v){var w=this._find(v,!1);return w>=0?this._values[w]:void 0},B.prototype.set=function(v,w){var I=this._find(v,!0);return this._values[I]=w,this},B.prototype.delete=function(v){var w=this._find(v,!1);if(w>=0){for(var I=this._keys.length,F=w+1;FHt}),nt.exports=Me(zt);var sr=bt(vt()),Ht={};Yt(Ht,{Attribute:()=>Rt,AttributeStatic:()=>je,Boost:()=>kt,BoostObject:()=>mt,Currency:()=>At,CurrencyStatic:()=>Ve,DEFAULT_ITERATIONS:()=>Ot,E:()=>M,FORMATS:()=>Ue,FormatTypeList:()=>Se,Grid:()=>$e,GridCell:()=>ae,LRUCache:()=>Pt,ListNode:()=>Xt,UpgradeData:()=>Nt,UpgradeStatic:()=>se,calculateSum:()=>Gt,calculateSumApprox:()=>re,calculateSumLoop:()=>ee,calculateUpgrade:()=>ie,decimalToJSONString:()=>Ft,equalsTolerance:()=>te,inverseFunctionApprox:()=>Bt,roundingBase:()=>Re,upgradeToCacheNameEL:()=>Ut});var ar=bt(vt()),Pt=class{constructor(t){this.map=new Map,this.first=void 0,this.last=void 0,this.maxSize=t}get size(){return this.map.size}get(t){let e=this.map.get(t);if(e!==void 0)return e!==this.first&&(e===this.last?(this.last=e.prev,this.last.next=void 0):(e.prev.next=e.next,e.next.prev=e.prev),e.next=this.first,this.first.prev=e,this.first=e),e.value}set(t,e){if(this.maxSize<1)return;if(this.map.has(t))throw new Error("Cannot update existing keys in the cache");let r=new Xt(t,e);for(this.first===void 0?(this.first=r,this.last=r):(r.next=this.first,this.first.prev=r,this.first=r),this.map.set(t,r);this.map.size>this.maxSize;){let i=this.last;this.map.delete(i.key),this.last=i.prev,this.last.next=void 0}}},Xt=class{constructor(t,e){this.next=void 0,this.prev=void 0,this.key=t,this.value=e}},et;(function(t){t[t.PLAIN_TO_CLASS=0]="PLAIN_TO_CLASS",t[t.CLASS_TO_PLAIN=1]="CLASS_TO_PLAIN",t[t.CLASS_TO_CLASS=2]="CLASS_TO_CLASS"})(et||(et={}));var we=function(){function t(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return t.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},t.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.findTransformMetadatas=function(e,r,i){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?i===et.CLASS_TO_CLASS||i===et.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?i===et.CLASS_TO_PLAIN:!0})},t.prototype.findExcludeMetadata=function(e,r){return this.findMetadata(this._excludeMetadatas,e,r)},t.prototype.findExposeMetadata=function(e,r){return this.findMetadata(this._exposeMetadatas,e,r)},t.prototype.findExposeMetadataByCustomName=function(e,r){return this.getExposedMetadatas(e).find(function(i){return i.options&&i.options.name===r})},t.prototype.findTypeMetadata=function(e,r){return this.findMetadata(this._typeMetadatas,e,r)},t.prototype.getStrategy=function(e){var r=this._excludeMetadatas.get(e),i=r&&r.get(void 0),n=this._exposeMetadatas.get(e),o=n&&n.get(void 0);return i&&o||!i&&!o?"none":i?"excludeAll":"exposeAll"},t.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},t.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},t.prototype.getExposedProperties=function(e,r){return this.getExposedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===et.CLASS_TO_CLASS||r===et.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===et.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===et.CLASS_TO_CLASS||r===et.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===et.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var i=e.get(r),n;i&&(n=Array.from(i.values()).filter(function(C){return C.propertyName!==void 0}));for(var o=[],h=0,p=this.getAncestors(r);hNumber.MAX_SAFE_INTEGER)&&(b="\u03C9");let O=t.log(a,8e3).toNumber();if(m.equals(0))return b;if(m.gt(0)&&m.lte(3)){let k=[];for(let j=0;jNumber.MAX_SAFE_INTEGER)&&(b="\u03C9");let O=t.log(a,8e3).toNumber();if(m.equals(0))return b;if(m.gt(0)&&m.lte(2)){let k=[];for(let j=0;j118?e.elemental.beyondOg(_):e.elemental.config.element_lists[a-1][b]},beyondOg(a){let g=Math.floor(Math.log10(a)),m=["n","u","b","t","q","p","h","s","o","e"],b="";for(let _=g;_>=0;_--){let O=Math.floor(a/Math.pow(10,_))%10;b==""?b=m[O].toUpperCase():b+=m[O]}return b},abbreviationLength(a){return a==1?1:Math.pow(Math.floor(a/2)+1,2)*2},getAbbreviationAndValue(a){let g=a.log(118).toNumber(),m=Math.floor(g)+1,b=e.elemental.abbreviationLength(m),_=g-m+1,O=Math.floor(_*b),S=e.elemental.getAbbreviation(m,_),R=new t(118).pow(m+O/b-1);return[S,R]},formatElementalPart(a,g){return g.eq(1)?a:`${g} ${a}`},format(a,g=2){if(a.gt(new t(118).pow(new t(118).pow(new t(118).pow(4)))))return"e"+e.elemental.format(a.log10(),g);let m=a.log(118),_=m.log(118).log(118).toNumber(),O=Math.max(4-_*2,1),S=[];for(;m.gte(1)&&S.length=O)return S.map(k=>e.elemental.formatElementalPart(k[0],k[1])).join(" + ");let R=new t(118).pow(m).toFixed(S.length===1?3:g);return S.length===0?R:S.length===1?`${R} \xD7 ${e.elemental.formatElementalPart(S[0][0],S[0][1])}`:`${R} \xD7 (${S.map(k=>e.elemental.formatElementalPart(k[0],k[1])).join(" + ")})`}},old_sc:{format(a,g){a=new t(a);let m=a.log10().floor();if(m.lt(9))return m.lt(3)?a.toFixed(g):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let _=a.slog();return(_.gte(1e9)?"":new t(10).pow(_.sub(_.floor())).toFixed(4))+"F"+e.old_sc.format(_.floor(),0)}let b=a.div(new t(10).pow(m));return(m.log10().gte(9)?"":b.toFixed(4))+"e"+e.old_sc.format(m,0)}}},eng:{format(a,g=2){a=new t(a);let m=a.log10().floor();if(m.lt(9))return m.lt(3)?a.toFixed(g):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let _=a.slog();return(_.gte(1e9)?"":new t(10).pow(_.sub(_.floor())).toFixed(4))+"F"+e.eng.format(_.floor(),0)}let b=a.div(new t(1e3).pow(m.div(3).floor()));return(m.log10().gte(9)?"":b.toFixed(new t(4).sub(m.sub(m.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(m.div(3).floor().mul(3),0)}}},mixed_sc:{format(a,g,m=9){a=new t(a);let b=a.log10().floor();return b.lt(303)&&b.gte(m)?d(a,g,m,"st"):d(a,g,m,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(a,g=2,m){a=new t(a);let b=a.max(1).log10().max(1).log(r.log10()).floor();if(b.lte(0))return d(a,g,m,"sc");a=new t(10).pow(a.max(1).log10().div(r.log10().pow(b)).sub(b.gte(1)?1:0));let _=b.div(10).floor(),O=b.toNumber()%10-1;return d(a,Math.max(4,g),m,"sc")+" "+(_.gte(1)?"meta"+(_.gte(2)?"^"+d(_,0,m,"sc"):"")+"-":"")+(isNaN(O)?"nanity":e.layer.layers[O])}},standard:{tier1(a){return ft[0][0][a%10]+ft[0][1][Math.floor(a/10)%10]+ft[0][2][Math.floor(a/100)]},tier2(a){let g=a%10,m=Math.floor(a/10)%10,b=Math.floor(a/100)%10,_="";return a<10?ft[1][0][a]:(m==1&&g==0?_+="Vec":_+=ft[1][1][g]+ft[1][2][m],_+=ft[1][3][b],_)}},inf:{format(a,g,m){a=new t(a);let b=0,_=new t(Number.MAX_VALUE),O=["","\u221E","\u03A9","\u03A8","\u028A"],S=["","","m","mm","mmm"];for(;a.gte(_);)a=a.log(_),b++;return b==0?d(a,g,m,"sc"):a.gte(3)?S[b]+O[b]+"\u03C9^"+d(a.sub(1),g,m,"sc"):a.gte(2)?S[b]+"\u03C9"+O[b]+"-"+d(_.pow(a.sub(2)),g,m,"sc"):S[b]+O[b]+"-"+d(_.pow(a.sub(1)),g,m,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(a,g=new t(1e15),m=!1,b=9){if(a=new t(a),g=new t(g).div(1e3),a.lt(g.mul(1e3)))return"";let{alphabet:_}=e.alphabet.config,O=_.length,S=a.log(1e3).sub(g.log(1e3)).floor(),R=S.add(1).log(O+1).ceil(),k="",j=(J,rt)=>{let Q=J,K="";for(let tt=0;tt=O)return"\u03C9";K=_[lt]+K,Q=Q.sub(1).div(O).floor()}return K};if(R.lt(b))k=j(S,R);else{let J=R.sub(b).add(1),rt=S.div(t.pow(O+1,J.sub(1))).floor();k=`${j(rt,new t(b))}(${J.gt("1e9")?J.format():J.format(0)})`}return k},format(a,g=2,m=9,b="mixed_sc",_=new t(1e15),O=!1,S){if(a=new t(a),_=new t(_).div(1e3),a.lt(_.mul(1e3)))return d(a,g,m,b);let R=e.alphabet.getAbbreviation(a,_,O,S),k=a.div(t.pow(1e3,a.log(1e3).floor()));return`${R.length>(S??9)+2?"":k.toFixed(g)+" "}${R}`}}},r=new t(2).pow(1024),i="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",n="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function o(a){return a.toFixed(0).split("").map(g=>g==="-"?"\u208B":i[parseInt(g,10)]).join("")}function h(a){return a.toFixed(0).split("").map(g=>g==="-"?"\u208B":n[parseInt(g,10)]).join("")}function p(a,g=2,m=9,b="st"){return d(a,g,m,b)}function d(a,g=2,m=9,b="mixed_sc"){a=new t(a);let _=a.lt(0)?"-":"";if(a.mag==1/0)return _+"Infinity";if(Number.isNaN(a.mag))return _+"NaN";if(a.lt(0)&&(a=a.mul(-1)),a.eq(0))return a.toFixed(g);let O=a.log10().floor();switch(b){case"sc":case"scientific":if(a.log10().lt(Math.min(-g,0))&&g>1){let S=a.log10().ceil(),R=a.div(S.eq(-1)?new t(.1):new t(10).pow(S)),k=S.mul(-1).max(1).log10().gte(9);return _+(k?"":R.toFixed(2))+"e"+d(S,0,m,"mixed_sc")}else if(O.lt(m)){let S=Math.max(Math.min(g-O.toNumber(),g),0);return _+(S>0?a.toFixed(S):a.toFixed(S).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(a.gte("eeee10")){let k=a.slog();return(k.gte(1e9)?"":new t(10).pow(k.sub(k.floor())).toFixed(2))+"F"+d(k.floor(),0)}let S=a.div(new t(10).pow(O)),R=O.log10().gte(9);return _+(R?"":S.toFixed(2))+"e"+d(O,0,m,"mixed_sc")}case"st":case"standard":{let S=a.log(1e3).floor();if(S.lt(1))return _+a.toFixed(Math.max(Math.min(g-O.toNumber(),g),0));let R=S.mul(3),k=S.log10().floor();if(k.gte(3e3))return"e"+d(O,g,m,"st");let j="";if(S.lt(4))j=["","K","M","B"][Math.round(S.toNumber())];else{let Q=Math.floor(S.log(1e3).toNumber());for(Q<100&&(Q=Math.max(Q-1,0)),S=S.sub(1).div(new t(10).pow(Q*3));S.gt(0);){let K=S.div(1e3).floor(),tt=S.sub(K.mul(1e3)).floor().toNumber();tt>0&&(tt==1&&!Q&&(j="U"),Q&&(j=e.standard.tier2(Q)+(j?"-"+j:"")),tt>1&&(j=e.standard.tier1(tt)+j)),S=K,Q++}}let J=a.div(new t(10).pow(R)),rt=g===2?new t(2).sub(O.sub(R)).add(1).toNumber():g;return _+(k.gte(10)?"":J.toFixed(rt)+" ")+j}default:return e[b]||console.error('Invalid format type "',b,'"'),_+e[b].format(a,g,m)}}function N(a,g,m="mixed_sc",b,_){a=new t(a),g=new t(g);let O=a.add(g),S,R=O.div(a);return R.gte(10)&&a.gte(1e100)?(R=R.log10().mul(20),S="(+"+d(R,b,_,m)+" OoMs/sec)"):S="(+"+d(g,b,_,m)+"/sec)",S}function T(a,g=2,m="s"){return a=new t(a),a.gte(86400)?d(a.div(86400).floor(),0,12,"sc")+":"+T(a.mod(86400),g,"d"):a.gte(3600)||m=="d"?(a.div(3600).gte(10)||m!="d"?"":"0")+d(a.div(3600).floor(),0,12,"sc")+":"+T(a.mod(3600),g,"h"):a.gte(60)||m=="h"?(a.div(60).gte(10)||m!="h"?"":"0")+d(a.div(60).floor(),0,12,"sc")+":"+T(a.mod(60),g,"m"):(a.gte(10)||m!="m"?"":"0")+d(a,g,12,"sc")}function C(a,g=!1,m=0,b=9,_="mixed_sc"){let O=Ct=>d(Ct,m,b,_);a=new t(a);let S=a.mul(1e3).mod(1e3).floor(),R=a.mod(60).floor(),k=a.div(60).mod(60).floor(),j=a.div(3600).mod(24).floor(),J=a.div(86400).mod(365.2425).floor(),rt=a.div(31556952).floor(),Q=rt.eq(1)?" year":" years",K=J.eq(1)?" day":" days",tt=j.eq(1)?" hour":" hours",lt=k.eq(1)?" minute":" minutes",Et=R.eq(1)?" second":" seconds",Tt=S.eq(1)?" millisecond":" milliseconds";return`${rt.gt(0)?O(rt)+Q+", ":""}${J.gt(0)?O(J)+K+", ":""}${j.gt(0)?O(j)+tt+", ":""}${k.gt(0)?O(k)+lt+", ":""}${R.gt(0)?O(R)+Et+",":""}${g&&S.gt(0)?" "+O(S)+Tt:""}`.replace(/,([^,]*)$/,"$1").trim()}function V(a){return a=new t(a),d(new t(1).sub(a).mul(100))+"%"}function x(a){return a=new t(a),d(a.mul(100))+"%"}function Z(a,g=2){return a=new t(a),a.gte(1)?"\xD7"+a.format(g):"/"+a.pow(-1).format(g)}function P(a,g,m=10){return t.gte(a,10)?t.pow(m,t.log(a,m).pow(g)):new t(a)}function L(a,g=0){a=new t(a);let m=(S=>S.map((R,k)=>({name:R.name,altName:R.altName,value:t.pow(1e3,new t(k).add(1))})))([{name:"K",altName:"Kilo"},{name:"M",altName:"Mega"},{name:"G",altName:"Giga"},{name:"T",altName:"Tera"},{name:"P",altName:"Peta"},{name:"E",altName:"Exa"},{name:"Z",altName:"Zetta"},{name:"Y",altName:"Yotta"},{name:"R",altName:"Ronna"},{name:"Q",altName:"Quetta"}]),b="",_=a.lte(0)?0:t.min(t.log(a,1e3).sub(1),m.length-1).floor().toNumber(),O=m[_];if(_===0)switch(g){case 1:b="";break;case 2:case 0:default:b=a.format();break}switch(g){case 1:b=O.name;break;case 2:b=a.divide(O.value).format();break;case 3:b=O.altName;break;case 0:default:b=`${a.divide(O.value).format()} ${O.name}`;break}return b}function Y(a,g=!1){return`${L(a,2)} ${L(a,1)}eV${g?"/c^2":""}`}let W={...e,toSubscript:o,toSuperscript:h,formatST:p,format:d,formatGain:N,formatTime:T,formatTimeLong:C,formatReduction:V,formatPercent:x,formatMult:Z,expMult:P,metric:L,ev:Y};return{FORMATS:e,formats:W}}var xt=17,Oe=9e15,Fe=Math.log10(9e15),Ae=1/9e15,Ee=308,Te=-324,Wt=5,Ce=1023,Pe=!0,qe=!1,xe=function(){let t=[];for(let r=Te+1;r<=Ee;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),ht=[2,Math.E,3,4,5,6,7,8,9,10],Le=[[1,1.0891180521811203,1.1789767925673957,1.2701455431742086,1.3632090180450092,1.4587818160364217,1.5575237916251419,1.6601571006859253,1.767485818836978,1.8804192098842727,2],[1,1.1121114330934079,1.231038924931609,1.3583836963111375,1.4960519303993531,1.6463542337511945,1.8121385357018724,1.996971324618307,2.2053895545527546,2.4432574483385254,Math.E],[1,1.1187738849693603,1.2464963939368214,1.38527004705667,1.5376664685821402,1.7068895236551784,1.897001227148399,2.1132403089001035,2.362480153784171,2.6539010333870774,3],[1,1.1367350847096405,1.2889510672956703,1.4606478703324786,1.6570295196661111,1.8850062585672889,2.1539465047453485,2.476829779693097,2.872061932789197,3.3664204535587183,4],[1,1.1494592900767588,1.319708228183931,1.5166291280087583,1.748171114438024,2.0253263297298045,2.3636668498288547,2.7858359149579424,3.3257226212448145,4.035730287722532,5],[1,1.159225940787673,1.343712473580932,1.5611293155111927,1.8221199554561318,2.14183924486326,2.542468319282638,3.0574682501653316,3.7390572020926873,4.6719550537360774,6],[1,1.1670905356972596,1.3632807444991446,1.5979222279405536,1.8842640123816674,2.2416069644878687,2.69893426559423,3.3012632110403577,4.121250340630164,5.281493033448316,7],[1,1.1736630594087796,1.379783782386201,1.6292821855668218,1.9378971836180754,2.3289975651071977,2.8384347394720835,3.5232708454565906,4.478242031114584,5.868592169644505,8],[1,1.1793017514670474,1.394054150657457,1.65664127441059,1.985170999970283,2.4069682290577457,2.9647310119960752,3.7278665320924946,4.814462547283592,6.436522247411611,9],[1,1.1840100246247336,1.4061375836156955,1.6802272208863964,2.026757028388619,2.4770056063449646,3.080525271755482,3.9191964192627284,5.135152840833187,6.989961179534715,10]],ke=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],f=function(e){return s.fromValue_noAlloc(e)},A=function(t,e,r){return s.fromComponents(t,e,r)},U=function(e,r,i){return s.fromComponents_noNormalize(e,r,i)},ut=function(e,r){let i=r+1,n=Math.ceil(Math.log10(Math.abs(e))),o=Math.round(e*Math.pow(10,i-n))*Math.pow(10,n-i);return parseFloat(o.toFixed(Math.max(i-n,0)))},Lt=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},Be=function(t){if(!isFinite(t))return t;if(t<-50)return t===Math.trunc(t)?Number.NEGATIVE_INFINITY:0;let e=1;for(;t<10;)e=e*t,++t;t-=1;let r=.9189385332046727;r=r+(t+.5)*Math.log(t),r=r-t;let i=t*t,n=t;return r=r+1/(12*n),n=n*i,r=r+1/(360*n),n=n*i,r=r+1/(1260*n),n=n*i,r=r+1/(1680*n),n=n*i,r=r+1/(1188*n),n=n*i,r=r+691/(360360*n),n=n*i,r=r+7/(1092*n),n=n*i,r=r+3617/(122400*n),Math.exp(r)/e},Ge=.36787944117144233,Dt=.5671432904097838,Qt=function(t,e=1e-10){let r,i;if(!Number.isFinite(t)||t===0)return t;if(t===1)return Dt;t<10?r=0:r=Math.log(t)-Math.log(Math.log(t));for(let n=0;n<100;++n){if(i=(t*Math.exp(-r)+r*r)/(r+1),Math.abs(i-r).5?1:-1;if(Math.random()*20<1)return U(e,0,1);let r=Math.floor(Math.random()*(t+1)),i=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(i=Math.trunc(i));let n=Math.pow(10,i);return Math.random()>.9&&(n=Math.trunc(n)),A(e,r,n)}static affordGeometricSeries_core(t,e,r,i){let n=e.mul(r.pow(i));return s.floor(t.div(n).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,i){return e.mul(r.pow(i)).mul(s.sub(1,r.pow(t))).div(s.sub(1,r))}static affordArithmeticSeries_core(t,e,r,i){let o=e.add(i.mul(r)).sub(r.div(2)),h=o.pow(2);return o.neg().add(h.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let n=e.add(i.mul(r));return t.div(2).mul(n.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.sign==1?(this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY):this.sign==-1&&(this.mag=Number.NEGATIVE_INFINITY,this.layer=Number.NEGATIVE_INFINITY),this;if(this.layer===0&&this.mag=Oe)return this.layer+=1,this.mag=e*Math.log10(t),this;for(;t0;)this.layer-=1,this.layer===0?this.mag=Math.pow(10,this.mag):(this.mag=e*Math.pow(10,t),t=Math.abs(this.mag),e=Math.sign(this.mag));return this.layer===0&&(this.mag<0?(this.mag=-this.mag,this.sign=-this.sign):this.mag===0&&(this.sign=0)),(Number.isNaN(this.sign)||Number.isNaN(this.layer)||Number.isNaN(this.mag))&&(this.sign=Number.NaN,this.layer=Number.NaN,this.mag=Number.NaN),this}fromComponents(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this.normalize(),this}fromComponents_noNormalize(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this}fromMantissaExponent(t,e){return this.layer=1,this.sign=Math.sign(t),t=Math.abs(t),this.mag=e+Math.log10(t),this.normalize(),this}fromMantissaExponent_noNormalize(t,e){return this.fromMantissaExponent(t,e),this}fromDecimal(t){return this.sign=t.sign,this.layer=t.layer,this.mag=t.mag,this}fromNumber(t){return this.mag=Math.abs(t),this.sign=Math.sign(t),this.layer=0,this.normalize(),this}fromString(t,e=!1){let r=t,i=s.fromStringCache.get(r);if(i!==void 0)return this.fromDecimal(i);Pe?t=t.replace(",",""):qe&&(t=t.replace(",","."));let n=t.split("^^^");if(n.length===2){let P=parseFloat(n[0]),L=parseFloat(n[1]),Y=n[1].split(";"),W=1;if(Y.length===2&&(W=parseFloat(Y[1]),isFinite(W)||(W=1)),isFinite(P)&&isFinite(L)){let a=s.pentate(P,L,W,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let o=t.split("^^");if(o.length===2){let P=parseFloat(o[0]),L=parseFloat(o[1]),Y=o[1].split(";"),W=1;if(Y.length===2&&(W=parseFloat(Y[1]),isFinite(W)||(W=1)),isFinite(P)&&isFinite(L)){let a=s.tetrate(P,L,W,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let h=t.split("^");if(h.length===2){let P=parseFloat(h[0]),L=parseFloat(h[1]);if(isFinite(P)&&isFinite(L)){let Y=s.pow(P,L);return this.sign=Y.sign,this.layer=Y.layer,this.mag=Y.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}t=t.trim().toLowerCase();let p,d,N=t.split("pt");if(N.length===2){p=10,d=parseFloat(N[0]),N[1]=N[1].replace("(",""),N[1]=N[1].replace(")","");let P=parseFloat(N[1]);if(isFinite(P)||(P=1),isFinite(p)&&isFinite(d)){let L=s.tetrate(p,d,P,e);return this.sign=L.sign,this.layer=L.layer,this.mag=L.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}if(N=t.split("p"),N.length===2){p=10,d=parseFloat(N[0]),N[1]=N[1].replace("(",""),N[1]=N[1].replace(")","");let P=parseFloat(N[1]);if(isFinite(P)||(P=1),isFinite(p)&&isFinite(d)){let L=s.tetrate(p,d,P,e);return this.sign=L.sign,this.layer=L.layer,this.mag=L.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}if(N=t.split("f"),N.length===2){p=10,N[0]=N[0].replace("(",""),N[0]=N[0].replace(")","");let P=parseFloat(N[0]);if(N[1]=N[1].replace("(",""),N[1]=N[1].replace(")",""),d=parseFloat(N[1]),isFinite(P)||(P=1),isFinite(p)&&isFinite(d)){let L=s.tetrate(p,d,P,e);return this.sign=L.sign,this.layer=L.layer,this.mag=L.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let T=t.split("e"),C=T.length-1;if(C===0){let P=parseFloat(t);if(isFinite(P))return this.fromNumber(P),s.fromStringCache.size>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else if(C===1){let P=parseFloat(t);if(isFinite(P)&&P!==0)return this.fromNumber(P),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}let V=t.split("e^");if(V.length===2){this.sign=1,V[0].charAt(0)=="-"&&(this.sign=-1);let P="";for(let L=0;L=43&&Y<=57||Y===101)P+=V[1].charAt(L);else return this.layer=parseFloat(P),this.mag=parseFloat(V[1].substr(L+1)),this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}if(C<1)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let x=parseFloat(T[0]);if(x===0)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let Z=parseFloat(T[T.length-1]);if(C>=2){let P=parseFloat(T[T.length-2]);isFinite(P)&&(Z*=Math.sign(P),Z+=Lt(P))}if(!isFinite(x))this.sign=T[0]==="-"?-1:1,this.layer=C,this.mag=Z;else if(C===1)this.sign=Math.sign(x),this.layer=1,this.mag=Z+Math.log10(Math.abs(x));else if(this.sign=Math.sign(x),this.layer=C,C===2){let P=s.mul(A(1,2,Z),f(x));return this.sign=P.sign,this.layer=P.layer,this.mag=P.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else this.mag=Z;return this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}fromValue(t){return t instanceof s?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.NEGATIVE_INFINITY&&this.layer===Number.NEGATIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:ut(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:ut(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=Wt?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):ut(this.m,t)+"e"+ut(this.e,t):this.layer===1?ut(this.m,t)+"e"+ut(this.e,t):this.layer<=Wt?(this.sign===-1?"-":"")+"e".repeat(this.layer)+ut(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+ut(this.mag,t)}abs(){return U(this.sign===0?0:1,this.layer,this.mag)}neg(){return U(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?s.dZero:this.layer===0?A(this.sign,0,Math.round(this.mag)):this}floor(){return this.mag<0?this.sign===-1?s.dNegOne:s.dZero:this.sign===-1?this.neg().ceil().neg():this.layer===0?A(this.sign,0,Math.floor(this.mag)):this}ceil(){return this.mag<0?this.sign===1?s.dOne:s.dZero:this.sign===-1?this.neg().floor().neg():this.layer===0?A(this.sign,0,Math.ceil(this.mag)):this}trunc(){return this.mag<0?s.dZero:this.layer===0?A(this.sign,0,Math.trunc(this.mag)):this}add(t){let e=f(t);if(!Number.isFinite(this.layer))return this;if(!Number.isFinite(e.layer)||this.sign===0)return e;if(e.sign===0)return this;if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return U(0,0,0);let r,i;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(s.cmpabs(this,e)>0?(r=this,i=e):(r=e,i=this),r.layer===0&&i.layer===0)return s.fromNumber(r.sign*r.mag+i.sign*i.mag);let n=r.layer*Math.sign(r.mag),o=i.layer*Math.sign(i.mag);if(n-o>=2)return r;if(n===0&&o===-1){if(Math.abs(i.mag-Math.log10(r.mag))>xt)return r;{let h=Math.pow(10,Math.log10(r.mag)-i.mag),p=i.sign+r.sign*h;return A(Math.sign(p),1,i.mag+Math.log10(Math.abs(p)))}}if(n===1&&o===0){if(Math.abs(r.mag-Math.log10(i.mag))>xt)return r;{let h=Math.pow(10,r.mag-Math.log10(i.mag)),p=i.sign+r.sign*h;return A(Math.sign(p),1,Math.log10(i.mag)+Math.log10(Math.abs(p)))}}if(Math.abs(r.mag-i.mag)>xt)return r;{let h=Math.pow(10,r.mag-i.mag),p=i.sign+r.sign*h;return A(Math.sign(p),1,i.mag+Math.log10(Math.abs(p)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(f(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=f(t);if(!Number.isFinite(this.layer))return this;if(!Number.isFinite(e.layer))return e;if(this.sign===0||e.sign===0)return U(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return U(this.sign*e.sign,0,1);let r,i;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=this,i=e):(r=e,i=this),r.layer===0&&i.layer===0)return s.fromNumber(r.sign*i.sign*r.mag*i.mag);if(r.layer>=3||r.layer-i.layer>=2)return A(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return A(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return A(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let n=A(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(A(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return A(r.sign*i.sign,n.layer+1,n.sign*n.mag)}if(r.layer===2&&i.layer===2){let n=A(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(A(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return A(r.sign*i.sign,n.layer+1,n.sign*n.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=f(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?s.dNaN:this.layer===0?A(this.sign,0,1/this.mag):A(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=f(t).abs();if(e.eq(s.dZero))return s.dZero;let r=this.toNumber(),i=e.toNumber();return isFinite(r)&&isFinite(i)&&r!=0&&i!=0?new s(r%i):this.sub(e).eq(this)?s.dZero:e.sub(this).eq(e)?this:this.sign==-1?this.abs().mod(e).neg():this.sub(this.div(e).floor().mul(e))}modulo(t){return this.mod(t)}modular(t){return this.mod(t)}cmp(t){let e=f(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,i=e.mag>0?e.layer:-e.layer;return r>i?1:re.mag?1:this.mag0?e:this}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=f(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=f(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let i=this.mag,n=r.mag;return this.layer>r.layer&&(n=Lt(n)),this.layer0?A(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):A(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?s.dNaN:this.layer>0?A(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):A(this.sign,0,Math.log10(this.mag))}log(t){return t=f(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?s.dNaN:this.layer===0&&t.layer===0?A(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):s.div(this.log10(),t.log10())}log2(){return this.sign<=0?s.dNaN:this.layer===0?A(this.sign,0,Math.log2(this.mag)):this.layer===1?A(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?A(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):A(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?s.dNaN:this.layer===0?A(this.sign,0,Math.log(this.mag)):this.layer===1?A(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?A(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):A(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=f(t),r=this,i=e;if(r.sign===0)return i.eq(0)?U(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(i.sign===0)return U(1,0,1);if(i.sign===1&&i.layer===0&&i.mag===1)return r;let n=r.absLog10().mul(i).pow10();return this.sign===-1?Math.abs(i.toNumber()%2)%2===1?n.neg():Math.abs(i.toNumber()%2)%2===0?n:s.dNaN:n}pow10(){if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return s.dNaN;let t=this;if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return A(1,0,e);if(t.sign===0)return s.dOne;t=U(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?A(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?A(-t.sign,t.layer+1,-t.mag):s.dOne}pow_base(t){return f(t).pow(this)}root(t){let e=f(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(U(1,0,24)))return s.fromNumber(Be(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,i=t,n=12*i,o=1/n,h=e+o;if(h===e||(e=h,i=i*r,n=360*i,o=1/n,h=e-o,h===e))return s.exp(e);e=h,i=i*r,n=1260*i;let p=1/n;return e=e+p,i=i*r,n=1680*i,p=1/n,e=e-p,s.exp(e)}else return this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?s.dOne:this.layer===0&&this.mag<=709.7?s.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?A(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?A(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):A(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return s.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return A(1,2,Math.log10(this.mag)-.3010299956639812);{let t=s.div(U(this.sign,this.layer-1,this.mag),U(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=U(1,0,1),r=!1){if(t===1)return s.pow(this,e);if(t===0)return new s(e);if(this.eq(s.dOne))return s.dOne;if(this.eq(-1))return s.pow(this,e);if(t===Number.POSITIVE_INFINITY){let o=this.toNumber();if(o<=1.444667861009766&&o>=.06598803584531254){if(o>1.444667861009099)return s.fromNumber(Math.E);let h=s.ln(this).neg();return h.lambertw().div(h)}else return o>1.444667861009766?s.fromNumber(Number.POSITIVE_INFINITY):s.dNaN}if(this.eq(s.dZero)){let o=Math.abs((t+1)%2);return o>1&&(o=2-o),s.fromNumber(o)}if(t<0)return s.iteratedlog(e,this,-t,r);e=f(e);let i=t;t=Math.trunc(t);let n=i-t;if(this.gt(s.dZero)&&this.lte(1.444667861009766)&&(i>1e4||!r)){t=Math.min(1e4,t);for(let o=0;o1e4){let o=this.pow(e);return i<=1e4||Math.ceil(i)%2==0?e.mul(1-n).add(o.mul(n)):e.mul(n).add(o.mul(1-n))}return e}n!==0&&(e.eq(s.dOne)?this.gt(10)||r?e=this.pow(n):(e=s.fromNumber(s.tetrate_critical(this.toNumber(),n)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(n,r):e=e.layeradd(n,this,r));for(let o=0;o3)return U(e.sign,e.layer+(t-o-1),e.mag);if(o>1e4)return e}return e}iteratedexp(t=2,e=U(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return s.tetrate(t,-e,this,r);t=f(t);let i=s.fromDecimal(this),n=e;e=Math.trunc(e);let o=n-e;if(i.layer-t.layer>3){let h=Math.min(e,i.layer-t.layer-3);e-=h,i.layer-=h}for(let h=0;h1e4)return i}return o>0&&o<1&&(t.eq(10)?i=i.layeradd10(-o,r):i=i.layeradd(-o,t,r)),i}slog(t=10,e=100,r=!1){let i=.001,n=!1,o=!1,h=this.slog_internal(t,r).toNumber();for(let p=1;p1&&o!=N&&(n=!0),o=N,n?i/=2:i*=2,i=Math.abs(i)*(N?-1:1),h+=i,i===0)break}return s.fromNumber(h)}slog_internal(t=10,e=!1){if(t=f(t),t.lte(s.dZero)||t.eq(s.dOne))return s.dNaN;if(t.lt(s.dOne))return this.eq(s.dOne)?s.dZero:this.eq(s.dZero)?s.dNegOne:s.dNaN;if(this.mag<0||this.eq(s.dZero))return s.dNegOne;let r=0,i=s.fromDecimal(this);if(i.layer-t.layer>3){let n=i.layer-t.layer-3;r+=n,i.layer-=n}for(let n=0;n<100;++n)if(i.lt(s.dZero))i=s.pow(t,i),r-=1;else{if(i.lte(s.dOne))return e?s.fromNumber(r+i.toNumber()-1):s.fromNumber(r+s.slog_critical(t.toNumber(),i.toNumber()));r+=1,i=s.log(i,t)}return s.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:s.critical_section(t,e,ke)}static tetrate_critical(t,e){return s.critical_section(t,e,Le)}static critical_section(t,e,r,i=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let n=0,o=0;for(let p=0;pt){let d=(t-ht[p])/(ht[p+1]-ht[p]);n=r[p][Math.floor(e)]*(1-d)+r[p+1][Math.floor(e)]*d,o=r[p][Math.ceil(e)]*(1-d)+r[p+1][Math.ceil(e)]*d;break}let h=e-Math.floor(e);return n<=0||o<=0?n*(1-h)+o*h:Math.pow(t,Math.log(n)/Math.log(t)*(1-h)+Math.log(o)/Math.log(t)*h)}layeradd10(t,e=!1){t=s.fromValue_noAlloc(t).toNumber();let r=s.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let i=Math.trunc(t);t-=i,r.layer+=i}if(t<=-1){let i=Math.trunc(t);if(t-=i,r.layer+=i,r.layer<0)for(let n=0;n<100;++n){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let n=this.slog(e).toNumber()+t;return n>=0?s.tetrate(e,n,s.dOne,r):Number.isFinite(n)?n>=-1?s.log(s.tetrate(e,n+1,s.dOne,r),e):s.log(s.log(s.tetrate(e,n+2,s.dOne,r),e),e):s.dNaN}lambertw(){if(this.lt(-.3678794411710499))throw Error("lambertw is unimplemented for results less than -1, sorry!");if(this.mag<0)return s.fromNumber(Qt(this.toNumber()));if(this.layer===0)return s.fromNumber(Qt(this.sign*this.mag));if(this.layer===1)return Jt(this);if(this.layer===2)return Jt(this);if(this.layer>=3)return U(this.sign,this.layer-1,this.mag);throw"Unhandled behavior in lambertw()"}ssqrt(){return this.linear_sroot(2)}linear_sroot(t){if(t==1)return this;if(this.eq(s.dInf))return s.dInf;if(!this.isFinite())return s.dNaN;if(t>0&&t<1)return this.root(t);if(t>-2&&t<-1)return s.fromNumber(t).add(2).pow(this.recip());if(t<=0)return s.dNaN;if(t==Number.POSITIVE_INFINITY){let e=this.toNumber();return eGe?this.pow(this.recip()):s.dNaN}if(this.eq(1))return s.dOne;if(this.lt(0))return s.dNaN;if(this.lte("1ee-16"))return t%2==1?this:s.dNaN;if(this.gt(1)){let e=s.dTen;this.gte(s.tetrate(10,t,1,!0))&&(e=this.iteratedlog(10,t-1,!0)),t<=1&&(e=this.root(t));let r=s.dZero,i=e.layer,n=e.iteratedlog(10,i,!0),o=n,h=n.div(2),p=!0;for(;p;)h=r.add(n).div(2),s.iteratedexp(10,i,h,!0).tetrate(t,1,!0).gt(this)?n=h:r=h,h.eq(o)?p=!1:o=h;return s.iteratedexp(10,i,h,!0)}else{let e=1,r=A(1,10,1),i=A(1,10,1),n=A(1,10,1),o=A(1,1,-16),h=s.dZero,p=A(1,10,1),d=o.pow10().recip(),N=s.dZero,T=d,C=d,V=Math.ceil(t)%2==0,x=0,Z=A(1,10,1),P=!1,L=s.dZero,Y=!1;for(;e<4;){if(e==2){if(V)break;n=A(1,10,1),o=r,e=3,p=A(1,10,1),Z=A(1,10,1)}for(P=!1;o.neq(n);){if(L=o,o.pow10().recip().tetrate(t,1,!0).eq(1)&&o.pow10().recip().lt(.4))d=o.pow10().recip(),T=o.pow10().recip(),C=o.pow10().recip(),N=s.dZero,x=-1,e==3&&(Z=o);else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip())&&!V&&o.pow10().recip().lt(.4))d=o.pow10().recip(),T=o.pow10().recip(),C=o.pow10().recip(),N=s.dZero,x=0;else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip().mul(2).tetrate(t,1,!0)))d=o.pow10().recip(),T=s.dZero,C=d.mul(2),N=d,V?x=-1:x=0;else{for(h=o.mul(12e-17),d=o.pow10().recip(),T=o.add(h).pow10().recip(),N=d.sub(T),C=d.add(N);T.tetrate(t,1,!0).eq(d.tetrate(t,1,!0))||C.tetrate(t,1,!0).eq(d.tetrate(t,1,!0))||T.gte(d)||C.lte(d);)h=h.mul(2),T=o.add(h).pow10().recip(),N=d.sub(T),C=d.add(N);if((e==1&&C.tetrate(t,1,!0).gt(d.tetrate(t,1,!0))&&T.tetrate(t,1,!0).gt(d.tetrate(t,1,!0))||e==3&&C.tetrate(t,1,!0).lt(d.tetrate(t,1,!0))&&T.tetrate(t,1,!0).lt(d.tetrate(t,1,!0)))&&(Z=o),C.tetrate(t,1,!0).lt(d.tetrate(t,1,!0)))x=-1;else if(V)x=1;else if(e==3&&o.gt_tolerance(r,1e-8))x=0;else{for(;T.tetrate(t,1,!0).eq_tolerance(d.tetrate(t,1,!0),1e-8)||C.tetrate(t,1,!0).eq_tolerance(d.tetrate(t,1,!0),1e-8)||T.gte(d)||C.lte(d);)h=h.mul(2),T=o.add(h).pow10().recip(),N=d.sub(T),C=d.add(N);C.tetrate(t,1,!0).sub(d.tetrate(t,1,!0)).lt(d.tetrate(t,1,!0).sub(T.tetrate(t,1,!0)))?x=0:x=1}}if(x==-1&&(Y=!0),e==1&&x==1||e==3&&x!=0)if(n.eq(A(1,10,1)))o=o.mul(2);else{let m=!1;if(P&&(x==1&&e==1||x==-1&&e==3)&&(m=!0),o=o.add(n).div(2),m)break}else if(n.eq(A(1,10,1)))n=o,o=o.div(2);else{let m=!1;if(P&&(x==1&&e==1||x==-1&&e==3)&&(m=!0),n=n.sub(p),o=o.sub(p),m)break}if(n.sub(o).div(2).abs().gt(p.mul(1.5))&&(P=!0),p=n.sub(o).div(2).abs(),o.gt("1e18")||o.eq(L))break}if(o.gt("1e18")||!Y||Z==A(1,10,1))break;e==1?r=Z:e==3&&(i=Z),e++}n=r,o=A(1,1,-18);let W=o,a=s.dZero,g=!0;for(;g;)if(n.eq(A(1,10,1))?a=o.mul(2):a=n.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:n=a,a.eq(W)?g=!1:W=a,o.gt("1e18"))return s.dNaN;if(a.eq_tolerance(r,1e-15)){if(i.eq(A(1,10,1)))return s.dNaN;for(n=A(1,10,1),o=i,W=o,a=s.dZero,g=!0;g;)if(n.eq(A(1,10,1))?a=o.mul(2):a=n.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:n=a,a.eq(W)?g=!1:W=a,o.gt("1e18"))return s.dNaN;return a.pow10().recip()}else return a.pow10().recip()}}pentate(t=2,e=U(1,0,1),r=!1){e=f(e);let i=t;t=Math.trunc(t);let n=i-t;n!==0&&(e.eq(s.dOne)?(++t,e=s.fromNumber(n)):this.eq(10)?e=e.layeradd10(n,r):e=e.layeradd(n,this,r));for(let o=0;o10)return e}return e}sin(){return this.mag<0?this:this.layer===0?s.fromNumber(Math.sin(this.sign*this.mag)):U(0,0,0)}cos(){return this.mag<0?s.dOne:this.layer===0?s.fromNumber(Math.cos(this.sign*this.mag)):U(0,0,0)}tan(){return this.mag<0?this:this.layer===0?s.fromNumber(Math.tan(this.sign*this.mag)):U(0,0,0)}asin(){return this.mag<0?this:this.layer===0?s.fromNumber(Math.asin(this.sign*this.mag)):U(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?s.fromNumber(Math.acos(this.toNumber())):this.layer===0?s.fromNumber(Math.acos(this.sign*this.mag)):U(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?this:this.layer===0?s.fromNumber(Math.atan(this.sign*this.mag)):s.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return s.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return s.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?U(Number.NaN,Number.NaN,Number.NaN):s.ln(this.add(1).div(s.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?this:this.root(s.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,i){return new s(t).add(new s(e).minus(new s(t)).times(new s(r)).times(new s(i)))}clone(){return this}static clone(t){return s.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=i.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(i=i.sub(t).div(e).add(t))),i}static softcap(t,e,r,i){return new s(t).softcap(e,r,i)}scale(t,e,r,i=!1){t=new s(t),e=new s(e);let n=this.clone();return n.gte(t)&&([0,"pow"].includes(r)&&(n=i?n.mul(t.pow(e.sub(1))).root(e):n.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(n=i?n.div(t).max(1).log(e).add(t):s.pow(e,n.sub(t)).mul(t))),n}static scale(t,e,r,i,n=!1){return new s(t).scale(e,r,i,n)}format(t=2,e=9,r="mixed_sc"){return ct.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return ct.format(new s(t),e,r,i)}formatST(t=2,e=9,r="st"){return ct.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return ct.format(new s(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return ct.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,n){return ct.formatGain(new s(t),e,r,i,n)}toRoman(t=5e3){t=new s(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),i={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},n="";for(let o of Object.keys(i)){let h=Math.floor(r/i[o]);r-=h*i[o],n+=o.repeat(h)}return n}static toRoman(t,e){return new s(t).toRoman(e)}static random(t=0,e=1){return t=new s(t),e=new s(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new s(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new s(Math.random()).lt(t)}};s.dZero=U(0,0,0),s.dOne=U(1,0,1),s.dNegOne=U(-1,0,1),s.dTwo=U(1,0,2),s.dTen=U(1,0,10),s.dNaN=U(Number.NaN,Number.NaN,Number.NaN),s.dInf=U(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNegInf=U(-1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),s.dNumberMax=A(1,0,Number.MAX_VALUE),s.dNumberMin=A(1,0,Number.MIN_VALUE),s.fromStringCache=new Pt(Ce),at([St()],s.prototype,"sign",2),at([St()],s.prototype,"mag",2),at([St()],s.prototype,"layer",2),s=at([_e()],s);var{formats:ct,FORMATS:Ue}=Ie(s);s.formats=ct;var M=(()=>{let t=e=>new s(e);return Object.getOwnPropertyNames(s).filter(e=>!Object.getOwnPropertyNames(class{}).includes(e)).forEach(e=>{t[e]=s[e]}),t})(),mt=class{get desc(){return this.description}get description(){return this.descriptionFn()}constructor(t){this.id=t.id,this.name=t.name??"",this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>"",this.value=t.value,this.order=t.order??99}},kt=class{constructor(t=1,e){this.addBoost=this.setBoost.bind(this),e=e?Array.isArray(e)?e:[e]:void 0,this.baseEffect=M(t),this.boostArray=[],e&&e.forEach(r=>{this.boostArray.push(new mt(r))})}getBoosts(t,e){let r=[],i=[];for(let n=0;nC),N=n,T=this.getBoosts(o,!0);T[0][0]?this.boostArray[T[1][0]]=new mt({id:o,name:h,description:p,value:d,order:N}):this.boostArray.push(new mt({id:o,name:h,description:p,value:d,order:N}))}else{t=Array.isArray(t)?t:[t];for(let o of t){let h=this.getBoosts(o.id,!0);h[0][0]?this.boostArray[h[1][0]]=new mt(o):this.boostArray.push(new mt(o))}}}calculate(t=this.baseEffect){let e=M(t),r=this.boostArray;r=r.sort((i,n)=>i.order-n.order);for(let i of r)e=i.value(e);return e}},or=bt(vt()),Ot=35,Kt=.001;function te(t,e,r,i){i=Object.assign({},{verbose:!1,mode:"geometric"},i),t=M(t),e=M(e),r=M(r);let n,o;return i.mode==="geometric"?(n=t.sub(e).abs().div(t.abs().add(e.abs()).div(2)),o=n.lte(r)):(n=t.sub(e).abs(),o=n.lte(r)),(i.verbose===!0||i.verbose==="onlyOnFail"&&!o)&&console.log({a:t,b:e,tolerance:r,config:i,diff:n,result:o}),o}function Bt(t,e,r="geometric",i=Ot,n=Kt){let o=M(1),h=M(e);if(t(h).eq(0))return{value:M(0),lowerBound:M(0),upperBound:M(0)};if(t(h).lt(e))return console.warn("The function is not monotonically increasing. (f(n) < n)"),{value:h,lowerBound:h,upperBound:h};for(let d=0;de.cost(Z.add(r)),V=M.min(i,Bt(C,t,n,o).value.floor()),x=M(0);return[V,x]}let d=Bt(C=>Gt(e.cost,C,r),t,n,o).value.floor().min(r.add(p).sub(1)),N=Gt(e.cost,d,r);return[d.sub(r).add(1).max(0),N]}function Ft(t){return t=M(t),`${t.sign}/${t.mag}/${t.layer}`}function ne(t,e){return`sum/${Ft(t)}/${Ft(e)}}`}function Ut(t){return`el/${Ft(t)}`}var Nt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?M(t.level):M(1)}};at([St()],Nt.prototype,"id",2),at([It(()=>s)],Nt.prototype,"level",2);var se=class ye{static{this.cacheSize=63}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn()}get level(){return((this??{data:{level:M(1)}}).data??{level:M(1)}).level}set level(e){this.data.level=M(e)}constructor(e,r,i){let n=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>n,this.cache=new Pt(i??ye.cacheSize),this.id=e.id,this.name=e.name??e.id,this.descriptionFn=e.description?typeof e.description=="function"?e.description:()=>e.description:()=>"",this.cost=e.cost,this.costBulk=e.costBulk,this.maxLevel=e.maxLevel,this.effect=e.effect,this.el=e.el,this.defaultLevel=e.level??M(1)}getCached(e,r,i){return e==="sum"?this.cache.get(ne(r,i??M(0))):this.cache.get(Ut(r))}setCached(e,r,i,n){let o=e==="sum"?{id:this.id,el:!1,start:M(r),end:M(i),cost:M(n)}:{id:this.id,el:!0,level:M(r),cost:M(i)};return e==="sum"?this.cache.set(ne(r,i),o):this.cache.set(Ut(r),o),o}},ur=bt(vt()),At=class{constructor(){this.value=M(0),this.upgrades={}}};at([It(()=>s)],At.prototype,"value",2),at([It(()=>Nt)],At.prototype,"upgrades",2);var Ve=class{get pointer(){return this.pointerFn()}get value(){return this.pointer.value}set value(t){this.pointer.value=t}constructor(t=new At,e,r={defaultVal:M(0),defaultBoost:M(1)}){this.defaultVal=r.defaultVal,this.defaultBoost=r.defaultBoost,this.pointerFn=typeof t=="function"?t:()=>t,this.boost=new kt(this.defaultBoost),this.pointer.value=this.defaultVal,this.upgrades={},e&&this.addUpgrade(e)}onLoadData(){for(let t of Object.values(this.upgrades))t.effect?.(t.level,t,this)}reset(t=!0,e=!0,r=!0){if(t&&(this.value=this.defaultVal),e)for(let i of Object.values(this.upgrades))i.level=M(i.defaultLevel),r&&i.effect?.(i.level,i,this)}gain(t=1e3){let e=this.boost.calculate().mul(M(t).div(1e3));return this.pointer.value=this.pointer.value.add(e),e}pointerAddUpgrade(t){let e=new Nt(t);return this.pointer.upgrades[e.id]=e,e}pointerGetUpgrade(t){return this.pointer.upgrades[t]??null}getUpgrade(t){return this.upgrades[t]??null}addUpgrade(t,e=!0){Array.isArray(t)||(t=[t]);let r={};for(let i of t){let n=this.pointerAddUpgrade(i),o=new se(i,()=>this.pointerGetUpgrade(i.id));o.effect&&e&&o.effect(o.level,o,this),r[i.id]=o,this.upgrades[i.id]=o}return Object.values(r)}updateUpgrade(t,e){let r=this.getUpgrade(t);r!==null&&(r.name=e.name??r.name,r.cost=e.cost??r.cost,r.maxLevel=e.maxLevel??r.maxLevel,r.effect=e.effect??r.effect)}calculateUpgrade(t,e=1/0,r,i){let n=this.getUpgrade(t);return n===null?(console.warn(`Upgrade "${t}" not found.`),[M(0),M(0)]):(e=n.level.add(e),n.maxLevel!==void 0&&(e=M.min(e,n.maxLevel)),ie(this.value,n,n.level,e,r,i))}getNextCost(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),M(0);let o=this.calculateUpgrade(t,e,r,i)[0];return n.cost(n.level.add(o))}getNextCostMax(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),M(0);let o=this.calculateUpgrade(t,e,r,i);return n.cost(n.level.add(o[0])).add(o[1])}buyUpgrade(t,e,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),!1;let[o,h]=this.calculateUpgrade(t,e,r,i);return o.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(h),n.level=n.level.add(o),n.effect?.(n.level,n,this),!0)}},lr=bt(vt()),Rt=class{constructor(t=0){this.value=M(t)}};at([It(()=>s)],Rt.prototype,"value",2);var je=class{get pointer(){return this.pointerFn()}constructor(t,e=!0,r=0){this.initial=M(r),t??=new Rt(this.initial),this.pointerFn=typeof t=="function"?t:()=>t,this.boost=e?new kt(this.initial):null}update(){console.warn("AttributeStatic.update is deprecated and will be removed in the future. The value is automatically updated when accessed."),this.boost&&(this.pointer.value=this.boost.calculate())}get value(){return this.boost&&(this.pointer.value=this.boost.calculate()),this.pointer.value}set value(t){if(this.boost)throw new Error("Cannot set value of attributeStatic when boost is enabled.");this.pointer.value=t}},ae=class{constructor(t,e,r){this.x=t,this.y=e,this.properties=r??{}}setValue(t,e){return this.properties[t]=e,e}getValue(t){return this.properties[t]}},$e=class{constructor(t,e,r){this.xSize=t,this.ySize=e,this.cells=[];for(let i=0;i{if(e&&typeof e=="object"||typeof e=="function")for(let n of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,n)&&n!==r&&Object.defineProperty(t,n,{get:()=>e[n],enumerable:!(i=Object.getOwnPropertyDescriptor(e,n))||i.enumerable});return t};nt.exports=Ye(nt.exports,pt)}return nt.exports}); +"use strict";(function(pt,nt){var wt=typeof exports=="object";if(typeof define=="function"&&define.amd)define([],nt);else if(typeof module=="object"&&module.exports)module.exports=nt();else{var ot=nt(),_t=wt?exports:pt;for(var yt in ot)_t[yt]=ot[yt]}})(typeof self<"u"?self:exports,()=>{var pt={},nt={exports:pt},wt=Object.create,ot=Object.defineProperty,_t=Object.getOwnPropertyDescriptor,yt=Object.getOwnPropertyNames,pe=Object.getPrototypeOf,ye=Object.prototype.hasOwnProperty,ve=(t,e)=>function(){return e||(0,t[yt(t)[0]])((e={exports:{}}).exports,e),e.exports},jt=(t,e)=>{for(var r in e)ot(t,r,{get:e[r],enumerable:!0})},$t=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of yt(e))!ye.call(t,n)&&n!==r&&ot(t,n,{get:()=>e[n],enumerable:!(i=_t(e,n))||i.enumerable});return t},vt=(t,e,r)=>(r=t!=null?wt(pe(t)):{},$t(e||!t||!t.__esModule?ot(r,"default",{value:t,enumerable:!0}):r,t)),be=t=>$t(ot({},"__esModule",{value:!0}),t),at=(t,e,r,i)=>{for(var n=i>1?void 0:i?_t(e,r):e,o=t.length-1,h;o>=0;o--)(h=t[o])&&(n=(i?h(e,r,n):h(n))||n);return i&&n&&ot(e,r,n),n},bt=ve({"node_modules/reflect-metadata/Reflect.js"(){var t;(function(e){(function(r){var i=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:d(),n=o(e);typeof i.Reflect<"u"&&(n=o(i.Reflect,n)),r(n,i),typeof i.Reflect>"u"&&(i.Reflect=e);function o(N,T){return function(C,V){Object.defineProperty(N,C,{configurable:!0,writable:!0,value:V}),T&&T(C,V)}}function h(){try{return Function("return this;")()}catch{}}function p(){try{return(0,eval)("(function() { return this; })()")}catch{}}function d(){return h()||p()}})(function(r,i){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",h=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",p=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",d=typeof Object.create=="function",N={__proto__:[]}instanceof Array,T=!d&&!N,C={create:d?function(){return Vt(Object.create(null))}:N?function(){return Vt({__proto__:null})}:function(){return Vt({})},has:T?function(u,l){return n.call(u,l)}:function(u,l){return l in u},get:T?function(u,l){return n.call(u,l)?u[l]:void 0}:function(u,l){return u[l]}},V=Object.getPrototypeOf(Function),x=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:Ke(),Z=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:tr(),P=typeof WeakMap=="function"?WeakMap:er(),L=o?Symbol.for("@reflect-metadata:registry"):void 0,Y=De(),W=Qe(Y);function a(u,l,c,y){if(q(c)){if(!oe(u))throw new TypeError;if(!ue(l))throw new TypeError;return J(u,l)}else{if(!oe(u))throw new TypeError;if(!z(l))throw new TypeError;if(!z(y)&&!q(y)&&!gt(y))throw new TypeError;return gt(y)&&(y=void 0),c=st(c),rt(u,l,c,y)}}r("decorate",a);function g(u,l){function c(y,E){if(!z(y))throw new TypeError;if(!q(E)&&!Xe(E))throw new TypeError;At(u,l,y,E)}return c}r("metadata",g);function m(u,l,c,y){if(!z(c))throw new TypeError;return q(y)||(y=st(y)),At(u,l,c,y)}r("defineMetadata",m);function v(u,l,c){if(!z(l))throw new TypeError;return q(c)||(c=st(c)),Q(u,l,c)}r("hasMetadata",v);function w(u,l,c){if(!z(l))throw new TypeError;return q(c)||(c=st(c)),K(u,l,c)}r("hasOwnMetadata",w);function O(u,l,c){if(!z(l))throw new TypeError;return q(c)||(c=st(c)),tt(u,l,c)}r("getMetadata",O);function _(u,l,c){if(!z(l))throw new TypeError;return q(c)||(c=st(c)),lt(u,l,c)}r("getOwnMetadata",_);function R(u,l){if(!z(u))throw new TypeError;return q(l)||(l=st(l)),Et(u,l)}r("getMetadataKeys",R);function k(u,l){if(!z(u))throw new TypeError;return q(l)||(l=st(l)),Tt(u,l)}r("getOwnMetadataKeys",k);function j(u,l,c){if(!z(l))throw new TypeError;if(q(c)||(c=st(c)),!z(l))throw new TypeError;q(c)||(c=st(c));var y=Mt(l,c,!1);return q(y)?!1:y.OrdinaryDeleteMetadata(u,l,c)}r("deleteMetadata",j);function J(u,l){for(var c=u.length-1;c>=0;--c){var y=u[c],E=y(l);if(!q(E)&&!gt(E)){if(!ue(E))throw new TypeError;l=E}}return l}function rt(u,l,c,y){for(var E=u.length-1;E>=0;--E){var H=u[E],D=H(l,c,y);if(!q(D)&&!gt(D)){if(!z(D))throw new TypeError;y=D}}return y}function Q(u,l,c){var y=K(u,l,c);if(y)return!0;var E=Rt(l);return gt(E)?!1:Q(u,E,c)}function K(u,l,c){var y=Mt(l,c,!1);return q(y)?!1:ae(y.OrdinaryHasOwnMetadata(u,l,c))}function tt(u,l,c){var y=K(u,l,c);if(y)return lt(u,l,c);var E=Rt(l);if(!gt(E))return tt(u,E,c)}function lt(u,l,c){var y=Mt(l,c,!1);if(!q(y))return y.OrdinaryGetOwnMetadata(u,l,c)}function At(u,l,c,y){var E=Mt(c,y,!0);E.OrdinaryDefineOwnMetadata(u,l,c,y)}function Et(u,l){var c=Tt(u,l),y=Rt(u);if(y===null)return c;var E=Et(y,l);if(E.length<=0)return c;if(c.length<=0)return E;for(var H=new Z,D=[],B=0,b=c;B=0&&b=this._keys.length?(this._index=-1,this._keys=l,this._values=l):this._index++,{value:M,done:!1}}return{value:void 0,done:!0}},B.prototype.throw=function(b){throw this._index>=0&&(this._index=-1,this._keys=l,this._values=l),b},B.prototype.return=function(b){return this._index>=0&&(this._index=-1,this._keys=l,this._values=l),{value:b,done:!0}},B}(),y=function(){function B(){this._keys=[],this._values=[],this._cacheKey=u,this._cacheIndex=-2}return Object.defineProperty(B.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),B.prototype.has=function(b){return this._find(b,!1)>=0},B.prototype.get=function(b){var M=this._find(b,!1);return M>=0?this._values[M]:void 0},B.prototype.set=function(b,M){var S=this._find(b,!0);return this._values[S]=M,this},B.prototype.delete=function(b){var M=this._find(b,!1);if(M>=0){for(var S=this._keys.length,F=M+1;FZt}),nt.exports=be(Yt);var nr=vt(bt()),Zt={};jt(Zt,{Attribute:()=>Gt,AttributeStatic:()=>Ve,Boost:()=>Lt,BoostObject:()=>mt,Currency:()=>Ft,CurrencyStatic:()=>Re,DEFAULT_ITERATIONS:()=>Ot,E:()=>I,FORMATS:()=>Be,FormatTypeList:()=>we,Grid:()=>je,GridCell:()=>ne,LRUCache:()=>Ct,ListNode:()=>zt,UpgradeData:()=>Nt,UpgradeStatic:()=>ie,calculateSum:()=>Bt,calculateSumApprox:()=>te,calculateSumLoop:()=>Kt,calculateUpgrade:()=>ee,decimalToJSONString:()=>re,equalsTolerance:()=>Jt,inverseFunctionApprox:()=>kt,roundingBase:()=>Ge,upgradeToCacheNameEL:()=>Ue});var sr=vt(bt()),Ct=class{constructor(t){this.map=new Map,this.first=void 0,this.last=void 0,this.maxSize=t}get size(){return this.map.size}get(t){let e=this.map.get(t);if(e!==void 0)return e!==this.first&&(e===this.last?(this.last=e.prev,this.last.next=void 0):(e.prev.next=e.next,e.next.prev=e.prev),e.next=this.first,this.first.prev=e,this.first=e),e.value}set(t,e){if(this.maxSize<1)return;if(this.map.has(t))throw new Error("Cannot update existing keys in the cache");let r=new zt(t,e);for(this.first===void 0?(this.first=r,this.last=r):(r.next=this.first,this.first.prev=r,this.first=r),this.map.set(t,r);this.map.size>this.maxSize;){let i=this.last;this.map.delete(i.key),this.last=i.prev,this.last.next=void 0}}},zt=class{constructor(t,e){this.next=void 0,this.prev=void 0,this.key=t,this.value=e}},et;(function(t){t[t.PLAIN_TO_CLASS=0]="PLAIN_TO_CLASS",t[t.CLASS_TO_PLAIN=1]="CLASS_TO_PLAIN",t[t.CLASS_TO_CLASS=2]="CLASS_TO_CLASS"})(et||(et={}));var Ne=function(){function t(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return t.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},t.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},t.prototype.findTransformMetadatas=function(e,r,i){return this.findMetadatas(this._transformMetadatas,e,r).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?i===et.CLASS_TO_CLASS||i===et.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?i===et.CLASS_TO_PLAIN:!0})},t.prototype.findExcludeMetadata=function(e,r){return this.findMetadata(this._excludeMetadatas,e,r)},t.prototype.findExposeMetadata=function(e,r){return this.findMetadata(this._exposeMetadatas,e,r)},t.prototype.findExposeMetadataByCustomName=function(e,r){return this.getExposedMetadatas(e).find(function(i){return i.options&&i.options.name===r})},t.prototype.findTypeMetadata=function(e,r){return this.findMetadata(this._typeMetadatas,e,r)},t.prototype.getStrategy=function(e){var r=this._excludeMetadatas.get(e),i=r&&r.get(void 0),n=this._exposeMetadatas.get(e),o=n&&n.get(void 0);return i&&o||!i&&!o?"none":i?"excludeAll":"exposeAll"},t.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},t.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},t.prototype.getExposedProperties=function(e,r){return this.getExposedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===et.CLASS_TO_CLASS||r===et.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===et.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.getExcludedProperties=function(e,r){return this.getExcludedMetadatas(e).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?r===et.CLASS_TO_CLASS||r===et.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?r===et.CLASS_TO_PLAIN:!0}).map(function(i){return i.propertyName})},t.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},t.prototype.getMetadata=function(e,r){var i=e.get(r),n;i&&(n=Array.from(i.values()).filter(function(C){return C.propertyName!==void 0}));for(var o=[],h=0,p=this.getAncestors(r);hNumber.MAX_SAFE_INTEGER)&&(v="\u03C9");let O=t.log(a,8e3).toNumber();if(m.equals(0))return v;if(m.gt(0)&&m.lte(3)){let k=[];for(let j=0;jNumber.MAX_SAFE_INTEGER)&&(v="\u03C9");let O=t.log(a,8e3).toNumber();if(m.equals(0))return v;if(m.gt(0)&&m.lte(2)){let k=[];for(let j=0;j118?e.elemental.beyondOg(w):e.elemental.config.element_lists[a-1][v]},beyondOg(a){let g=Math.floor(Math.log10(a)),m=["n","u","b","t","q","p","h","s","o","e"],v="";for(let w=g;w>=0;w--){let O=Math.floor(a/Math.pow(10,w))%10;v==""?v=m[O].toUpperCase():v+=m[O]}return v},abbreviationLength(a){return a==1?1:Math.pow(Math.floor(a/2)+1,2)*2},getAbbreviationAndValue(a){let g=a.log(118).toNumber(),m=Math.floor(g)+1,v=e.elemental.abbreviationLength(m),w=g-m+1,O=Math.floor(w*v),_=e.elemental.getAbbreviation(m,w),R=new t(118).pow(m+O/v-1);return[_,R]},formatElementalPart(a,g){return g.eq(1)?a:`${g} ${a}`},format(a,g=2){if(a.gt(new t(118).pow(new t(118).pow(new t(118).pow(4)))))return"e"+e.elemental.format(a.log10(),g);let m=a.log(118),w=m.log(118).log(118).toNumber(),O=Math.max(4-w*2,1),_=[];for(;m.gte(1)&&_.length=O)return _.map(k=>e.elemental.formatElementalPart(k[0],k[1])).join(" + ");let R=new t(118).pow(m).toFixed(_.length===1?3:g);return _.length===0?R:_.length===1?`${R} \xD7 ${e.elemental.formatElementalPart(_[0][0],_[0][1])}`:`${R} \xD7 (${_.map(k=>e.elemental.formatElementalPart(k[0],k[1])).join(" + ")})`}},old_sc:{format(a,g){a=new t(a);let m=a.log10().floor();if(m.lt(9))return m.lt(3)?a.toFixed(g):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let w=a.slog();return(w.gte(1e9)?"":new t(10).pow(w.sub(w.floor())).toFixed(4))+"F"+e.old_sc.format(w.floor(),0)}let v=a.div(new t(10).pow(m));return(m.log10().gte(9)?"":v.toFixed(4))+"e"+e.old_sc.format(m,0)}}},eng:{format(a,g=2){a=new t(a);let m=a.log10().floor();if(m.lt(9))return m.lt(3)?a.toFixed(g):a.floor().toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,");{if(a.gte("eeee10")){let w=a.slog();return(w.gte(1e9)?"":new t(10).pow(w.sub(w.floor())).toFixed(4))+"F"+e.eng.format(w.floor(),0)}let v=a.div(new t(1e3).pow(m.div(3).floor()));return(m.log10().gte(9)?"":v.toFixed(new t(4).sub(m.sub(m.div(3).floor().mul(3))).toNumber()))+"e"+e.eng.format(m.div(3).floor().mul(3),0)}}},mixed_sc:{format(a,g,m=9){a=new t(a);let v=a.log10().floor();return v.lt(303)&&v.gte(m)?d(a,g,m,"st"):d(a,g,m,"sc")}},layer:{layers:["infinity","eternity","reality","equality","affinity","celerity","identity","vitality","immunity","atrocity"],format(a,g=2,m){a=new t(a);let v=a.max(1).log10().max(1).log(r.log10()).floor();if(v.lte(0))return d(a,g,m,"sc");a=new t(10).pow(a.max(1).log10().div(r.log10().pow(v)).sub(v.gte(1)?1:0));let w=v.div(10).floor(),O=v.toNumber()%10-1;return d(a,Math.max(4,g),m,"sc")+" "+(w.gte(1)?"meta"+(w.gte(2)?"^"+d(w,0,m,"sc"):"")+"-":"")+(isNaN(O)?"nanity":e.layer.layers[O])}},standard:{tier1(a){return ft[0][0][a%10]+ft[0][1][Math.floor(a/10)%10]+ft[0][2][Math.floor(a/100)]},tier2(a){let g=a%10,m=Math.floor(a/10)%10,v=Math.floor(a/100)%10,w="";return a<10?ft[1][0][a]:(m==1&&g==0?w+="Vec":w+=ft[1][1][g]+ft[1][2][m],w+=ft[1][3][v],w)}},inf:{format(a,g,m){a=new t(a);let v=0,w=new t(Number.MAX_VALUE),O=["","\u221E","\u03A9","\u03A8","\u028A"],_=["","","m","mm","mmm"];for(;a.gte(w);)a=a.log(w),v++;return v==0?d(a,g,m,"sc"):a.gte(3)?_[v]+O[v]+"\u03C9^"+d(a.sub(1),g,m,"sc"):a.gte(2)?_[v]+"\u03C9"+O[v]+"-"+d(w.pow(a.sub(2)),g,m,"sc"):_[v]+O[v]+"-"+d(w.pow(a.sub(1)),g,m,"sc")}},alphabet:{config:{alphabet:"abcdefghijklmnopqrstuvwxyz"},getAbbreviation(a,g=new t(1e15),m=!1,v=9){if(a=new t(a),g=new t(g).div(1e3),a.lt(g.mul(1e3)))return"";let{alphabet:w}=e.alphabet.config,O=w.length,_=a.log(1e3).sub(g.log(1e3)).floor(),R=_.add(1).log(O+1).ceil(),k="",j=(J,rt)=>{let Q=J,K="";for(let tt=0;tt=O)return"\u03C9";K=w[lt]+K,Q=Q.sub(1).div(O).floor()}return K};if(R.lt(v))k=j(_,R);else{let J=R.sub(v).add(1),rt=_.div(t.pow(O+1,J.sub(1))).floor();k=`${j(rt,new t(v))}(${J.gt("1e9")?J.format():J.format(0)})`}return k},format(a,g=2,m=9,v="mixed_sc",w=new t(1e15),O=!1,_){if(a=new t(a),w=new t(w).div(1e3),a.lt(w.mul(1e3)))return d(a,g,m,v);let R=e.alphabet.getAbbreviation(a,w,O,_),k=a.div(t.pow(1e3,a.log(1e3).floor()));return`${R.length>(_??9)+2?"":k.toFixed(g)+" "}${R}`}}},r=new t(2).pow(1024),i="\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089",n="\u2070\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079";function o(a){return a.toFixed(0).split("").map(g=>g==="-"?"\u208B":i[parseInt(g,10)]).join("")}function h(a){return a.toFixed(0).split("").map(g=>g==="-"?"\u208B":n[parseInt(g,10)]).join("")}function p(a,g=2,m=9,v="st"){return d(a,g,m,v)}function d(a,g=2,m=9,v="mixed_sc"){a=new t(a);let w=a.lt(0)?"-":"";if(a.mag==1/0)return w+"Infinity";if(Number.isNaN(a.mag))return w+"NaN";if(a.lt(0)&&(a=a.mul(-1)),a.eq(0))return a.toFixed(g);let O=a.log10().floor();switch(v){case"sc":case"scientific":if(a.log10().lt(Math.min(-g,0))&&g>1){let _=a.log10().ceil(),R=a.div(_.eq(-1)?new t(.1):new t(10).pow(_)),k=_.mul(-1).max(1).log10().gte(9);return w+(k?"":R.toFixed(2))+"e"+d(_,0,m,"mixed_sc")}else if(O.lt(m)){let _=Math.max(Math.min(g-O.toNumber(),g),0);return w+(_>0?a.toFixed(_):a.toFixed(_).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"))}else{if(a.gte("eeee10")){let k=a.slog();return(k.gte(1e9)?"":new t(10).pow(k.sub(k.floor())).toFixed(2))+"F"+d(k.floor(),0)}let _=a.div(new t(10).pow(O)),R=O.log10().gte(9);return w+(R?"":_.toFixed(2))+"e"+d(O,0,m,"mixed_sc")}case"st":case"standard":{let _=a.log(1e3).floor();if(_.lt(1))return w+a.toFixed(Math.max(Math.min(g-O.toNumber(),g),0));let R=_.mul(3),k=_.log10().floor();if(k.gte(3e3))return"e"+d(O,g,m,"st");let j="";if(_.lt(4))j=["","K","M","B"][Math.round(_.toNumber())];else{let Q=Math.floor(_.log(1e3).toNumber());for(Q<100&&(Q=Math.max(Q-1,0)),_=_.sub(1).div(new t(10).pow(Q*3));_.gt(0);){let K=_.div(1e3).floor(),tt=_.sub(K.mul(1e3)).floor().toNumber();tt>0&&(tt==1&&!Q&&(j="U"),Q&&(j=e.standard.tier2(Q)+(j?"-"+j:"")),tt>1&&(j=e.standard.tier1(tt)+j)),_=K,Q++}}let J=a.div(new t(10).pow(R)),rt=g===2?new t(2).sub(O.sub(R)).add(1).toNumber():g;return w+(k.gte(10)?"":J.toFixed(rt)+" ")+j}default:return e[v]||console.error('Invalid format type "',v,'"'),w+e[v].format(a,g,m)}}function N(a,g,m="mixed_sc",v,w){a=new t(a),g=new t(g);let O=a.add(g),_,R=O.div(a);return R.gte(10)&&a.gte(1e100)?(R=R.log10().mul(20),_="(+"+d(R,v,w,m)+" OoMs/sec)"):_="(+"+d(g,v,w,m)+"/sec)",_}function T(a,g=2,m="s"){return a=new t(a),a.gte(86400)?d(a.div(86400).floor(),0,12,"sc")+":"+T(a.mod(86400),g,"d"):a.gte(3600)||m=="d"?(a.div(3600).gte(10)||m!="d"?"":"0")+d(a.div(3600).floor(),0,12,"sc")+":"+T(a.mod(3600),g,"h"):a.gte(60)||m=="h"?(a.div(60).gte(10)||m!="h"?"":"0")+d(a.div(60).floor(),0,12,"sc")+":"+T(a.mod(60),g,"m"):(a.gte(10)||m!="m"?"":"0")+d(a,g,12,"sc")}function C(a,g=!1,m=0,v=9,w="mixed_sc"){let O=Tt=>d(Tt,m,v,w);a=new t(a);let _=a.mul(1e3).mod(1e3).floor(),R=a.mod(60).floor(),k=a.div(60).mod(60).floor(),j=a.div(3600).mod(24).floor(),J=a.div(86400).mod(365.2425).floor(),rt=a.div(31556952).floor(),Q=rt.eq(1)?" year":" years",K=J.eq(1)?" day":" days",tt=j.eq(1)?" hour":" hours",lt=k.eq(1)?" minute":" minutes",At=R.eq(1)?" second":" seconds",Et=_.eq(1)?" millisecond":" milliseconds";return`${rt.gt(0)?O(rt)+Q+", ":""}${J.gt(0)?O(J)+K+", ":""}${j.gt(0)?O(j)+tt+", ":""}${k.gt(0)?O(k)+lt+", ":""}${R.gt(0)?O(R)+At+",":""}${g&&_.gt(0)?" "+O(_)+Et:""}`.replace(/,([^,]*)$/,"$1").trim()}function V(a){return a=new t(a),d(new t(1).sub(a).mul(100))+"%"}function x(a){return a=new t(a),d(a.mul(100))+"%"}function Z(a,g=2){return a=new t(a),a.gte(1)?"\xD7"+a.format(g):"/"+a.pow(-1).format(g)}function P(a,g,m=10){return t.gte(a,10)?t.pow(m,t.log(a,m).pow(g)):new t(a)}function L(a,g=0){a=new t(a);let m=(_=>_.map((R,k)=>({name:R.name,altName:R.altName,value:t.pow(1e3,new t(k).add(1))})))([{name:"K",altName:"Kilo"},{name:"M",altName:"Mega"},{name:"G",altName:"Giga"},{name:"T",altName:"Tera"},{name:"P",altName:"Peta"},{name:"E",altName:"Exa"},{name:"Z",altName:"Zetta"},{name:"Y",altName:"Yotta"},{name:"R",altName:"Ronna"},{name:"Q",altName:"Quetta"}]),v="",w=a.lte(0)?0:t.min(t.log(a,1e3).sub(1),m.length-1).floor().toNumber(),O=m[w];if(w===0)switch(g){case 1:v="";break;case 2:case 0:default:v=a.format();break}switch(g){case 1:v=O.name;break;case 2:v=a.divide(O.value).format();break;case 3:v=O.altName;break;case 0:default:v=`${a.divide(O.value).format()} ${O.name}`;break}return v}function Y(a,g=!1){return`${L(a,2)} ${L(a,1)}eV${g?"/c^2":""}`}let W={...e,toSubscript:o,toSuperscript:h,formatST:p,format:d,formatGain:N,formatTime:T,formatTimeLong:C,formatReduction:V,formatPercent:x,formatMult:Z,expMult:P,metric:L,ev:Y};return{FORMATS:e,formats:W}}var qt=17,Se=9e15,Ie=Math.log10(9e15),Oe=1/9e15,Fe=308,Ae=-324,Ht=5,Ee=1023,Te=!0,Ce=!1,Pe=function(){let t=[];for(let r=Ae+1;r<=Fe;r++)t.push(+("1e"+r));let e=323;return function(r){return t[r+e]}}(),ht=[2,Math.E,3,4,5,6,7,8,9,10],qe=[[1,1.0891180521811203,1.1789767925673957,1.2701455431742086,1.3632090180450092,1.4587818160364217,1.5575237916251419,1.6601571006859253,1.767485818836978,1.8804192098842727,2],[1,1.1121114330934079,1.231038924931609,1.3583836963111375,1.4960519303993531,1.6463542337511945,1.8121385357018724,1.996971324618307,2.2053895545527546,2.4432574483385254,Math.E],[1,1.1187738849693603,1.2464963939368214,1.38527004705667,1.5376664685821402,1.7068895236551784,1.897001227148399,2.1132403089001035,2.362480153784171,2.6539010333870774,3],[1,1.1367350847096405,1.2889510672956703,1.4606478703324786,1.6570295196661111,1.8850062585672889,2.1539465047453485,2.476829779693097,2.872061932789197,3.3664204535587183,4],[1,1.1494592900767588,1.319708228183931,1.5166291280087583,1.748171114438024,2.0253263297298045,2.3636668498288547,2.7858359149579424,3.3257226212448145,4.035730287722532,5],[1,1.159225940787673,1.343712473580932,1.5611293155111927,1.8221199554561318,2.14183924486326,2.542468319282638,3.0574682501653316,3.7390572020926873,4.6719550537360774,6],[1,1.1670905356972596,1.3632807444991446,1.5979222279405536,1.8842640123816674,2.2416069644878687,2.69893426559423,3.3012632110403577,4.121250340630164,5.281493033448316,7],[1,1.1736630594087796,1.379783782386201,1.6292821855668218,1.9378971836180754,2.3289975651071977,2.8384347394720835,3.5232708454565906,4.478242031114584,5.868592169644505,8],[1,1.1793017514670474,1.394054150657457,1.65664127441059,1.985170999970283,2.4069682290577457,2.9647310119960752,3.7278665320924946,4.814462547283592,6.436522247411611,9],[1,1.1840100246247336,1.4061375836156955,1.6802272208863964,2.026757028388619,2.4770056063449646,3.080525271755482,3.9191964192627284,5.135152840833187,6.989961179534715,10]],xe=[[-1,-.9194161097107025,-.8335625019330468,-.7425599821143978,-.6466611521029437,-.5462617907227869,-.4419033816638769,-.3342645487554494,-.224140440909962,-.11241087890006762,0],[-1,-.90603157029014,-.80786507256596,-.7064666939634,-.60294836853664,-.49849837513117,-.39430303318768,-.29147201034755,-.19097820800866,-.09361896280296,0],[-1,-.9021579584316141,-.8005762598234203,-.6964780623319391,-.5911906810998454,-.486050182576545,-.3823089430815083,-.28106046722897615,-.1831906535795894,-.08935809204418144,0],[-1,-.8917227442365535,-.781258746326964,-.6705130326902455,-.5612813129406509,-.4551067709033134,-.35319256652135966,-.2563741554088552,-.1651412821106526,-.0796919581982668,0],[-1,-.8843387974366064,-.7678744063886243,-.6529563724510552,-.5415870994657841,-.4352842206588936,-.33504449124791424,-.24138853420685147,-.15445285440944467,-.07409659641336663,0],[-1,-.8786709358426346,-.7577735191184886,-.6399546189952064,-.527284921869926,-.4211627631006314,-.3223479611761232,-.23107655627789858,-.1472057700818259,-.07035171210706326,0],[-1,-.8740862815291583,-.7497032990976209,-.6297119746181752,-.5161838335958787,-.41036238255751956,-.31277212146489963,-.2233976621705518,-.1418697367979619,-.06762117662323441,0],[-1,-.8702632331800649,-.7430366914122081,-.6213373075161548,-.5072025698095242,-.40171437727184167,-.30517930701410456,-.21736343968190863,-.137710238299109,-.06550774483471955,0],[-1,-.8670016295947213,-.7373984232432306,-.6143173985094293,-.49973884395492807,-.394584953527678,-.2989649949848695,-.21245647317021688,-.13434688362382652,-.0638072667348083,0],[-1,-.8641642839543857,-.732534623168535,-.6083127477059322,-.4934049257184696,-.3885773075899922,-.29376029055315767,-.2083678561173622,-.13155653399373268,-.062401588652553186,0]],f=function(e){return s.fromValue_noAlloc(e)},A=function(t,e,r){return s.fromComponents(t,e,r)},U=function(e,r,i){return s.fromComponents_noNormalize(e,r,i)},ut=function(e,r){let i=r+1,n=Math.ceil(Math.log10(Math.abs(e))),o=Math.round(e*Math.pow(10,i-n))*Math.pow(10,n-i);return parseFloat(o.toFixed(Math.max(i-n,0)))},xt=function(t){return Math.sign(t)*Math.log10(Math.abs(t))},Le=function(t){if(!isFinite(t))return t;if(t<-50)return t===Math.trunc(t)?Number.NEGATIVE_INFINITY:0;let e=1;for(;t<10;)e=e*t,++t;t-=1;let r=.9189385332046727;r=r+(t+.5)*Math.log(t),r=r-t;let i=t*t,n=t;return r=r+1/(12*n),n=n*i,r=r+1/(360*n),n=n*i,r=r+1/(1260*n),n=n*i,r=r+1/(1680*n),n=n*i,r=r+1/(1188*n),n=n*i,r=r+691/(360360*n),n=n*i,r=r+7/(1092*n),n=n*i,r=r+3617/(122400*n),Math.exp(r)/e},ke=.36787944117144233,Xt=.5671432904097838,Wt=function(t,e=1e-10){let r,i;if(!Number.isFinite(t)||t===0)return t;if(t===1)return Xt;t<10?r=0:r=Math.log(t)-Math.log(Math.log(t));for(let n=0;n<100;++n){if(i=(t*Math.exp(-r)+r*r)/(r+1),Math.abs(i-r).5?1:-1;if(Math.random()*20<1)return U(e,0,1);let r=Math.floor(Math.random()*(t+1)),i=r===0?Math.random()*616-308:Math.random()*16;Math.random()>.9&&(i=Math.trunc(i));let n=Math.pow(10,i);return Math.random()>.9&&(n=Math.trunc(n)),A(e,r,n)}static affordGeometricSeries_core(t,e,r,i){let n=e.mul(r.pow(i));return s.floor(t.div(n).mul(r.sub(1)).add(1).log10().div(r.log10()))}static sumGeometricSeries_core(t,e,r,i){return e.mul(r.pow(i)).mul(s.sub(1,r.pow(t))).div(s.sub(1,r))}static affordArithmeticSeries_core(t,e,r,i){let o=e.add(i.mul(r)).sub(r.div(2)),h=o.pow(2);return o.neg().add(h.add(r.mul(t).mul(2)).sqrt()).div(r).floor()}static sumArithmeticSeries_core(t,e,r,i){let n=e.add(i.mul(r));return t.div(2).mul(n.mul(2).plus(t.sub(1).mul(r)))}static efficiencyOfPurchase_core(t,e,r){return t.div(e).add(t.div(r))}normalize(){if(this.sign===0||this.mag===0&&this.layer===0||this.mag===Number.NEGATIVE_INFINITY&&this.layer>0&&Number.isFinite(this.layer))return this.sign=0,this.mag=0,this.layer=0,this;if(this.layer===0&&this.mag<0&&(this.mag=-this.mag,this.sign=-this.sign),this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY)return this.sign==1?(this.mag=Number.POSITIVE_INFINITY,this.layer=Number.POSITIVE_INFINITY):this.sign==-1&&(this.mag=Number.NEGATIVE_INFINITY,this.layer=Number.NEGATIVE_INFINITY),this;if(this.layer===0&&this.mag=Se)return this.layer+=1,this.mag=e*Math.log10(t),this;for(;t0;)this.layer-=1,this.layer===0?this.mag=Math.pow(10,this.mag):(this.mag=e*Math.pow(10,t),t=Math.abs(this.mag),e=Math.sign(this.mag));return this.layer===0&&(this.mag<0?(this.mag=-this.mag,this.sign=-this.sign):this.mag===0&&(this.sign=0)),(Number.isNaN(this.sign)||Number.isNaN(this.layer)||Number.isNaN(this.mag))&&(this.sign=Number.NaN,this.layer=Number.NaN,this.mag=Number.NaN),this}fromComponents(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this.normalize(),this}fromComponents_noNormalize(t,e,r){return this.sign=t,this.layer=e,this.mag=r,this}fromMantissaExponent(t,e){return this.layer=1,this.sign=Math.sign(t),t=Math.abs(t),this.mag=e+Math.log10(t),this.normalize(),this}fromMantissaExponent_noNormalize(t,e){return this.fromMantissaExponent(t,e),this}fromDecimal(t){return this.sign=t.sign,this.layer=t.layer,this.mag=t.mag,this}fromNumber(t){return this.mag=Math.abs(t),this.sign=Math.sign(t),this.layer=0,this.normalize(),this}fromString(t,e=!1){let r=t,i=s.fromStringCache.get(r);if(i!==void 0)return this.fromDecimal(i);Te?t=t.replace(",",""):Ce&&(t=t.replace(",","."));let n=t.split("^^^");if(n.length===2){let P=parseFloat(n[0]),L=parseFloat(n[1]),Y=n[1].split(";"),W=1;if(Y.length===2&&(W=parseFloat(Y[1]),isFinite(W)||(W=1)),isFinite(P)&&isFinite(L)){let a=s.pentate(P,L,W,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let o=t.split("^^");if(o.length===2){let P=parseFloat(o[0]),L=parseFloat(o[1]),Y=o[1].split(";"),W=1;if(Y.length===2&&(W=parseFloat(Y[1]),isFinite(W)||(W=1)),isFinite(P)&&isFinite(L)){let a=s.tetrate(P,L,W,e);return this.sign=a.sign,this.layer=a.layer,this.mag=a.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let h=t.split("^");if(h.length===2){let P=parseFloat(h[0]),L=parseFloat(h[1]);if(isFinite(P)&&isFinite(L)){let Y=s.pow(P,L);return this.sign=Y.sign,this.layer=Y.layer,this.mag=Y.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}t=t.trim().toLowerCase();let p,d,N=t.split("pt");if(N.length===2){p=10,d=parseFloat(N[0]),N[1]=N[1].replace("(",""),N[1]=N[1].replace(")","");let P=parseFloat(N[1]);if(isFinite(P)||(P=1),isFinite(p)&&isFinite(d)){let L=s.tetrate(p,d,P,e);return this.sign=L.sign,this.layer=L.layer,this.mag=L.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}if(N=t.split("p"),N.length===2){p=10,d=parseFloat(N[0]),N[1]=N[1].replace("(",""),N[1]=N[1].replace(")","");let P=parseFloat(N[1]);if(isFinite(P)||(P=1),isFinite(p)&&isFinite(d)){let L=s.tetrate(p,d,P,e);return this.sign=L.sign,this.layer=L.layer,this.mag=L.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}if(N=t.split("f"),N.length===2){p=10,N[0]=N[0].replace("(",""),N[0]=N[0].replace(")","");let P=parseFloat(N[0]);if(N[1]=N[1].replace("(",""),N[1]=N[1].replace(")",""),d=parseFloat(N[1]),isFinite(P)||(P=1),isFinite(p)&&isFinite(d)){let L=s.tetrate(p,d,P,e);return this.sign=L.sign,this.layer=L.layer,this.mag=L.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}let T=t.split("e"),C=T.length-1;if(C===0){let P=parseFloat(t);if(isFinite(P))return this.fromNumber(P),s.fromStringCache.size>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else if(C===1){let P=parseFloat(t);if(isFinite(P)&&P!==0)return this.fromNumber(P),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}let V=t.split("e^");if(V.length===2){this.sign=1,V[0].charAt(0)=="-"&&(this.sign=-1);let P="";for(let L=0;L=43&&Y<=57||Y===101)P+=V[1].charAt(L);else return this.layer=parseFloat(P),this.mag=parseFloat(V[1].substr(L+1)),this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}}if(C<1)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let x=parseFloat(T[0]);if(x===0)return this.sign=0,this.layer=0,this.mag=0,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this;let Z=parseFloat(T[T.length-1]);if(C>=2){let P=parseFloat(T[T.length-2]);isFinite(P)&&(Z*=Math.sign(P),Z+=xt(P))}if(!isFinite(x))this.sign=T[0]==="-"?-1:1,this.layer=C,this.mag=Z;else if(C===1)this.sign=Math.sign(x),this.layer=1,this.mag=Z+Math.log10(Math.abs(x));else if(this.sign=Math.sign(x),this.layer=C,C===2){let P=s.mul(A(1,2,Z),f(x));return this.sign=P.sign,this.layer=P.layer,this.mag=P.mag,s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}else this.mag=Z;return this.normalize(),s.fromStringCache.maxSize>=1&&s.fromStringCache.set(r,s.fromDecimal(this)),this}fromValue(t){return t instanceof s?this.fromDecimal(t):typeof t=="number"?this.fromNumber(t):typeof t=="string"?this.fromString(t):(this.sign=0,this.layer=0,this.mag=0,this)}toNumber(){return this.mag===Number.POSITIVE_INFINITY&&this.layer===Number.POSITIVE_INFINITY&&this.sign===1?Number.POSITIVE_INFINITY:this.mag===Number.NEGATIVE_INFINITY&&this.layer===Number.NEGATIVE_INFINITY&&this.sign===-1?Number.NEGATIVE_INFINITY:Number.isFinite(this.layer)?this.layer===0?this.sign*this.mag:this.layer===1?this.sign*Math.pow(10,this.mag):this.mag>0?this.sign>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:0:Number.NaN}mantissaWithDecimalPlaces(t){return isNaN(this.m)?Number.NaN:this.m===0?0:ut(this.m,t)}magnitudeWithDecimalPlaces(t){return isNaN(this.mag)?Number.NaN:this.mag===0?0:ut(this.mag,t)}toString(){return isNaN(this.layer)||isNaN(this.sign)||isNaN(this.mag)?"NaN":this.mag===Number.POSITIVE_INFINITY||this.layer===Number.POSITIVE_INFINITY||this.mag===Number.NEGATIVE_INFINITY||this.layer===Number.NEGATIVE_INFINITY?this.sign===1?"Infinity":"-Infinity":this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toString():this.m+"e"+this.e:this.layer===1?this.m+"e"+this.e:this.layer<=Ht?(this.sign===-1?"-":"")+"e".repeat(this.layer)+this.mag:(this.sign===-1?"-":"")+"(e^"+this.layer+")"+this.mag}toExponential(t){return this.layer===0?(this.sign*this.mag).toExponential(t):this.toStringWithDecimalPlaces(t)}toFixed(t){return this.layer===0?(this.sign*this.mag).toFixed(t):this.toStringWithDecimalPlaces(t)}toPrecision(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.exponent-1):this.toExponential(t-1)}valueOf(){return this.toString()}toJSON(){return this.toString()}toStringWithDecimalPlaces(t){return this.layer===0?this.mag<1e21&&this.mag>1e-7||this.mag===0?(this.sign*this.mag).toFixed(t):ut(this.m,t)+"e"+ut(this.e,t):this.layer===1?ut(this.m,t)+"e"+ut(this.e,t):this.layer<=Ht?(this.sign===-1?"-":"")+"e".repeat(this.layer)+ut(this.mag,t):(this.sign===-1?"-":"")+"(e^"+this.layer+")"+ut(this.mag,t)}abs(){return U(this.sign===0?0:1,this.layer,this.mag)}neg(){return U(-this.sign,this.layer,this.mag)}negate(){return this.neg()}negated(){return this.neg()}sgn(){return this.sign}round(){return this.mag<0?s.dZero:this.layer===0?A(this.sign,0,Math.round(this.mag)):this}floor(){return this.mag<0?this.sign===-1?s.dNegOne:s.dZero:this.sign===-1?this.neg().ceil().neg():this.layer===0?A(this.sign,0,Math.floor(this.mag)):this}ceil(){return this.mag<0?this.sign===1?s.dOne:s.dZero:this.sign===-1?this.neg().floor().neg():this.layer===0?A(this.sign,0,Math.ceil(this.mag)):this}trunc(){return this.mag<0?s.dZero:this.layer===0?A(this.sign,0,Math.trunc(this.mag)):this}add(t){let e=f(t);if(!Number.isFinite(this.layer))return this;if(!Number.isFinite(e.layer)||this.sign===0)return e;if(e.sign===0)return this;if(this.sign===-e.sign&&this.layer===e.layer&&this.mag===e.mag)return U(0,0,0);let r,i;if(this.layer>=2||e.layer>=2)return this.maxabs(e);if(s.cmpabs(this,e)>0?(r=this,i=e):(r=e,i=this),r.layer===0&&i.layer===0)return s.fromNumber(r.sign*r.mag+i.sign*i.mag);let n=r.layer*Math.sign(r.mag),o=i.layer*Math.sign(i.mag);if(n-o>=2)return r;if(n===0&&o===-1){if(Math.abs(i.mag-Math.log10(r.mag))>qt)return r;{let h=Math.pow(10,Math.log10(r.mag)-i.mag),p=i.sign+r.sign*h;return A(Math.sign(p),1,i.mag+Math.log10(Math.abs(p)))}}if(n===1&&o===0){if(Math.abs(r.mag-Math.log10(i.mag))>qt)return r;{let h=Math.pow(10,r.mag-Math.log10(i.mag)),p=i.sign+r.sign*h;return A(Math.sign(p),1,Math.log10(i.mag)+Math.log10(Math.abs(p)))}}if(Math.abs(r.mag-i.mag)>qt)return r;{let h=Math.pow(10,r.mag-i.mag),p=i.sign+r.sign*h;return A(Math.sign(p),1,i.mag+Math.log10(Math.abs(p)))}throw Error("Bad arguments to add: "+this+", "+t)}plus(t){return this.add(t)}sub(t){return this.add(f(t).neg())}subtract(t){return this.sub(t)}minus(t){return this.sub(t)}mul(t){let e=f(t);if(!Number.isFinite(this.layer))return this;if(!Number.isFinite(e.layer))return e;if(this.sign===0||e.sign===0)return U(0,0,0);if(this.layer===e.layer&&this.mag===-e.mag)return U(this.sign*e.sign,0,1);let r,i;if(this.layer>e.layer||this.layer==e.layer&&Math.abs(this.mag)>Math.abs(e.mag)?(r=this,i=e):(r=e,i=this),r.layer===0&&i.layer===0)return s.fromNumber(r.sign*i.sign*r.mag*i.mag);if(r.layer>=3||r.layer-i.layer>=2)return A(r.sign*i.sign,r.layer,r.mag);if(r.layer===1&&i.layer===0)return A(r.sign*i.sign,1,r.mag+Math.log10(i.mag));if(r.layer===1&&i.layer===1)return A(r.sign*i.sign,1,r.mag+i.mag);if(r.layer===2&&i.layer===1){let n=A(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(A(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return A(r.sign*i.sign,n.layer+1,n.sign*n.mag)}if(r.layer===2&&i.layer===2){let n=A(Math.sign(r.mag),r.layer-1,Math.abs(r.mag)).add(A(Math.sign(i.mag),i.layer-1,Math.abs(i.mag)));return A(r.sign*i.sign,n.layer+1,n.sign*n.mag)}throw Error("Bad arguments to mul: "+this+", "+t)}multiply(t){return this.mul(t)}times(t){return this.mul(t)}div(t){let e=f(t);return this.mul(e.recip())}divide(t){return this.div(t)}divideBy(t){return this.div(t)}dividedBy(t){return this.div(t)}recip(){return this.mag===0?s.dNaN:this.layer===0?A(this.sign,0,1/this.mag):A(this.sign,this.layer,-this.mag)}reciprocal(){return this.recip()}reciprocate(){return this.recip()}mod(t){let e=f(t).abs();if(e.eq(s.dZero))return s.dZero;let r=this.toNumber(),i=e.toNumber();return isFinite(r)&&isFinite(i)&&r!=0&&i!=0?new s(r%i):this.sub(e).eq(this)?s.dZero:e.sub(this).eq(e)?this:this.sign==-1?this.abs().mod(e).neg():this.sub(this.div(e).floor().mul(e))}modulo(t){return this.mod(t)}modular(t){return this.mod(t)}cmp(t){let e=f(t);return this.sign>e.sign?1:this.sign0?this.layer:-this.layer,i=e.mag>0?e.layer:-e.layer;return r>i?1:re.mag?1:this.mag0?e:this}clamp(t,e){return this.max(t).min(e)}clampMin(t){return this.max(t)}clampMax(t){return this.min(t)}cmp_tolerance(t,e){let r=f(t);return this.eq_tolerance(r,e)?0:this.cmp(r)}compare_tolerance(t,e){return this.cmp_tolerance(t,e)}eq_tolerance(t,e){let r=f(t);if(e==null&&(e=1e-7),this.sign!==r.sign||Math.abs(this.layer-r.layer)>1)return!1;let i=this.mag,n=r.mag;return this.layer>r.layer&&(n=xt(n)),this.layer0?A(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):A(1,0,Math.log10(this.mag))}log10(){return this.sign<=0?s.dNaN:this.layer>0?A(Math.sign(this.mag),this.layer-1,Math.abs(this.mag)):A(this.sign,0,Math.log10(this.mag))}log(t){return t=f(t),this.sign<=0||t.sign<=0||t.sign===1&&t.layer===0&&t.mag===1?s.dNaN:this.layer===0&&t.layer===0?A(this.sign,0,Math.log(this.mag)/Math.log(t.mag)):s.div(this.log10(),t.log10())}log2(){return this.sign<=0?s.dNaN:this.layer===0?A(this.sign,0,Math.log2(this.mag)):this.layer===1?A(Math.sign(this.mag),0,Math.abs(this.mag)*3.321928094887362):this.layer===2?A(Math.sign(this.mag),1,Math.abs(this.mag)+.5213902276543247):A(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}ln(){return this.sign<=0?s.dNaN:this.layer===0?A(this.sign,0,Math.log(this.mag)):this.layer===1?A(Math.sign(this.mag),0,Math.abs(this.mag)*2.302585092994046):this.layer===2?A(Math.sign(this.mag),1,Math.abs(this.mag)+.36221568869946325):A(Math.sign(this.mag),this.layer-1,Math.abs(this.mag))}logarithm(t){return this.log(t)}pow(t){let e=f(t),r=this,i=e;if(r.sign===0)return i.eq(0)?U(1,0,1):r;if(r.sign===1&&r.layer===0&&r.mag===1)return r;if(i.sign===0)return U(1,0,1);if(i.sign===1&&i.layer===0&&i.mag===1)return r;let n=r.absLog10().mul(i).pow10();return this.sign===-1?Math.abs(i.toNumber()%2)%2===1?n.neg():Math.abs(i.toNumber()%2)%2===0?n:s.dNaN:n}pow10(){if(!Number.isFinite(this.layer)||!Number.isFinite(this.mag))return s.dNaN;let t=this;if(t.layer===0){let e=Math.pow(10,t.sign*t.mag);if(Number.isFinite(e)&&Math.abs(e)>=.1)return A(1,0,e);if(t.sign===0)return s.dOne;t=U(t.sign,t.layer+1,Math.log10(t.mag))}return t.sign>0&&t.mag>=0?A(t.sign,t.layer+1,t.mag):t.sign<0&&t.mag>=0?A(-t.sign,t.layer+1,-t.mag):s.dOne}pow_base(t){return f(t).pow(this)}root(t){let e=f(t);return this.pow(e.recip())}factorial(){return this.mag<0?this.add(1).gamma():this.layer===0?this.add(1).gamma():this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}gamma(){if(this.mag<0)return this.recip();if(this.layer===0){if(this.lt(U(1,0,24)))return s.fromNumber(Le(this.sign*this.mag));let t=this.mag-1,e=.9189385332046727;e=e+(t+.5)*Math.log(t),e=e-t;let r=t*t,i=t,n=12*i,o=1/n,h=e+o;if(h===e||(e=h,i=i*r,n=360*i,o=1/n,h=e-o,h===e))return s.exp(e);e=h,i=i*r,n=1260*i;let p=1/n;return e=e+p,i=i*r,n=1680*i,p=1/n,e=e-p,s.exp(e)}else return this.layer===1?s.exp(s.mul(this,s.ln(this).sub(1))):s.exp(this)}lngamma(){return this.gamma().ln()}exp(){return this.mag<0?s.dOne:this.layer===0&&this.mag<=709.7?s.fromNumber(Math.exp(this.sign*this.mag)):this.layer===0?A(1,1,this.sign*Math.log10(Math.E)*this.mag):this.layer===1?A(1,2,this.sign*(Math.log10(.4342944819032518)+this.mag)):A(1,this.layer+1,this.sign*this.mag)}sqr(){return this.pow(2)}sqrt(){if(this.layer===0)return s.fromNumber(Math.sqrt(this.sign*this.mag));if(this.layer===1)return A(1,2,Math.log10(this.mag)-.3010299956639812);{let t=s.div(U(this.sign,this.layer-1,this.mag),U(1,0,2));return t.layer+=1,t.normalize(),t}}cube(){return this.pow(3)}cbrt(){return this.pow(1/3)}tetrate(t=2,e=U(1,0,1),r=!1){if(t===1)return s.pow(this,e);if(t===0)return new s(e);if(this.eq(s.dOne))return s.dOne;if(this.eq(-1))return s.pow(this,e);if(t===Number.POSITIVE_INFINITY){let o=this.toNumber();if(o<=1.444667861009766&&o>=.06598803584531254){if(o>1.444667861009099)return s.fromNumber(Math.E);let h=s.ln(this).neg();return h.lambertw().div(h)}else return o>1.444667861009766?s.fromNumber(Number.POSITIVE_INFINITY):s.dNaN}if(this.eq(s.dZero)){let o=Math.abs((t+1)%2);return o>1&&(o=2-o),s.fromNumber(o)}if(t<0)return s.iteratedlog(e,this,-t,r);e=f(e);let i=t;t=Math.trunc(t);let n=i-t;if(this.gt(s.dZero)&&this.lte(1.444667861009766)&&(i>1e4||!r)){t=Math.min(1e4,t);for(let o=0;o1e4){let o=this.pow(e);return i<=1e4||Math.ceil(i)%2==0?e.mul(1-n).add(o.mul(n)):e.mul(n).add(o.mul(1-n))}return e}n!==0&&(e.eq(s.dOne)?this.gt(10)||r?e=this.pow(n):(e=s.fromNumber(s.tetrate_critical(this.toNumber(),n)),this.lt(2)&&(e=e.sub(1).mul(this.minus(1)).plus(1))):this.eq(10)?e=e.layeradd10(n,r):e=e.layeradd(n,this,r));for(let o=0;o3)return U(e.sign,e.layer+(t-o-1),e.mag);if(o>1e4)return e}return e}iteratedexp(t=2,e=U(1,0,1),r=!1){return this.tetrate(t,e,r)}iteratedlog(t=10,e=1,r=!1){if(e<0)return s.tetrate(t,-e,this,r);t=f(t);let i=s.fromDecimal(this),n=e;e=Math.trunc(e);let o=n-e;if(i.layer-t.layer>3){let h=Math.min(e,i.layer-t.layer-3);e-=h,i.layer-=h}for(let h=0;h1e4)return i}return o>0&&o<1&&(t.eq(10)?i=i.layeradd10(-o,r):i=i.layeradd(-o,t,r)),i}slog(t=10,e=100,r=!1){let i=.001,n=!1,o=!1,h=this.slog_internal(t,r).toNumber();for(let p=1;p1&&o!=N&&(n=!0),o=N,n?i/=2:i*=2,i=Math.abs(i)*(N?-1:1),h+=i,i===0)break}return s.fromNumber(h)}slog_internal(t=10,e=!1){if(t=f(t),t.lte(s.dZero)||t.eq(s.dOne))return s.dNaN;if(t.lt(s.dOne))return this.eq(s.dOne)?s.dZero:this.eq(s.dZero)?s.dNegOne:s.dNaN;if(this.mag<0||this.eq(s.dZero))return s.dNegOne;let r=0,i=s.fromDecimal(this);if(i.layer-t.layer>3){let n=i.layer-t.layer-3;r+=n,i.layer-=n}for(let n=0;n<100;++n)if(i.lt(s.dZero))i=s.pow(t,i),r-=1;else{if(i.lte(s.dOne))return e?s.fromNumber(r+i.toNumber()-1):s.fromNumber(r+s.slog_critical(t.toNumber(),i.toNumber()));r+=1,i=s.log(i,t)}return s.fromNumber(r)}static slog_critical(t,e){return t>10?e-1:s.critical_section(t,e,xe)}static tetrate_critical(t,e){return s.critical_section(t,e,qe)}static critical_section(t,e,r,i=!1){e*=10,e<0&&(e=0),e>10&&(e=10),t<2&&(t=2),t>10&&(t=10);let n=0,o=0;for(let p=0;pt){let d=(t-ht[p])/(ht[p+1]-ht[p]);n=r[p][Math.floor(e)]*(1-d)+r[p+1][Math.floor(e)]*d,o=r[p][Math.ceil(e)]*(1-d)+r[p+1][Math.ceil(e)]*d;break}let h=e-Math.floor(e);return n<=0||o<=0?n*(1-h)+o*h:Math.pow(t,Math.log(n)/Math.log(t)*(1-h)+Math.log(o)/Math.log(t)*h)}layeradd10(t,e=!1){t=s.fromValue_noAlloc(t).toNumber();let r=s.fromDecimal(this);if(t>=1){r.mag<0&&r.layer>0?(r.sign=0,r.mag=0,r.layer=0):r.sign===-1&&r.layer==0&&(r.sign=1,r.mag=-r.mag);let i=Math.trunc(t);t-=i,r.layer+=i}if(t<=-1){let i=Math.trunc(t);if(t-=i,r.layer+=i,r.layer<0)for(let n=0;n<100;++n){if(r.layer++,r.mag=Math.log10(r.mag),!isFinite(r.mag))return r.sign===0&&(r.sign=1),r.layer<0&&(r.layer=0),r.normalize();if(r.layer>=0)break}}for(;r.layer<0;)r.layer++,r.mag=Math.log10(r.mag);return r.sign===0&&(r.sign=1,r.mag===0&&r.layer>=1&&(r.layer-=1,r.mag=1)),r.normalize(),t!==0?r.layeradd(t,10,e):r}layeradd(t,e,r=!1){let n=this.slog(e).toNumber()+t;return n>=0?s.tetrate(e,n,s.dOne,r):Number.isFinite(n)?n>=-1?s.log(s.tetrate(e,n+1,s.dOne,r),e):s.log(s.log(s.tetrate(e,n+2,s.dOne,r),e),e):s.dNaN}lambertw(){if(this.lt(-.3678794411710499))throw Error("lambertw is unimplemented for results less than -1, sorry!");if(this.mag<0)return s.fromNumber(Wt(this.toNumber()));if(this.layer===0)return s.fromNumber(Wt(this.sign*this.mag));if(this.layer===1)return Dt(this);if(this.layer===2)return Dt(this);if(this.layer>=3)return U(this.sign,this.layer-1,this.mag);throw"Unhandled behavior in lambertw()"}ssqrt(){return this.linear_sroot(2)}linear_sroot(t){if(t==1)return this;if(this.eq(s.dInf))return s.dInf;if(!this.isFinite())return s.dNaN;if(t>0&&t<1)return this.root(t);if(t>-2&&t<-1)return s.fromNumber(t).add(2).pow(this.recip());if(t<=0)return s.dNaN;if(t==Number.POSITIVE_INFINITY){let e=this.toNumber();return eke?this.pow(this.recip()):s.dNaN}if(this.eq(1))return s.dOne;if(this.lt(0))return s.dNaN;if(this.lte("1ee-16"))return t%2==1?this:s.dNaN;if(this.gt(1)){let e=s.dTen;this.gte(s.tetrate(10,t,1,!0))&&(e=this.iteratedlog(10,t-1,!0)),t<=1&&(e=this.root(t));let r=s.dZero,i=e.layer,n=e.iteratedlog(10,i,!0),o=n,h=n.div(2),p=!0;for(;p;)h=r.add(n).div(2),s.iteratedexp(10,i,h,!0).tetrate(t,1,!0).gt(this)?n=h:r=h,h.eq(o)?p=!1:o=h;return s.iteratedexp(10,i,h,!0)}else{let e=1,r=A(1,10,1),i=A(1,10,1),n=A(1,10,1),o=A(1,1,-16),h=s.dZero,p=A(1,10,1),d=o.pow10().recip(),N=s.dZero,T=d,C=d,V=Math.ceil(t)%2==0,x=0,Z=A(1,10,1),P=!1,L=s.dZero,Y=!1;for(;e<4;){if(e==2){if(V)break;n=A(1,10,1),o=r,e=3,p=A(1,10,1),Z=A(1,10,1)}for(P=!1;o.neq(n);){if(L=o,o.pow10().recip().tetrate(t,1,!0).eq(1)&&o.pow10().recip().lt(.4))d=o.pow10().recip(),T=o.pow10().recip(),C=o.pow10().recip(),N=s.dZero,x=-1,e==3&&(Z=o);else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip())&&!V&&o.pow10().recip().lt(.4))d=o.pow10().recip(),T=o.pow10().recip(),C=o.pow10().recip(),N=s.dZero,x=0;else if(o.pow10().recip().tetrate(t,1,!0).eq(o.pow10().recip().mul(2).tetrate(t,1,!0)))d=o.pow10().recip(),T=s.dZero,C=d.mul(2),N=d,V?x=-1:x=0;else{for(h=o.mul(12e-17),d=o.pow10().recip(),T=o.add(h).pow10().recip(),N=d.sub(T),C=d.add(N);T.tetrate(t,1,!0).eq(d.tetrate(t,1,!0))||C.tetrate(t,1,!0).eq(d.tetrate(t,1,!0))||T.gte(d)||C.lte(d);)h=h.mul(2),T=o.add(h).pow10().recip(),N=d.sub(T),C=d.add(N);if((e==1&&C.tetrate(t,1,!0).gt(d.tetrate(t,1,!0))&&T.tetrate(t,1,!0).gt(d.tetrate(t,1,!0))||e==3&&C.tetrate(t,1,!0).lt(d.tetrate(t,1,!0))&&T.tetrate(t,1,!0).lt(d.tetrate(t,1,!0)))&&(Z=o),C.tetrate(t,1,!0).lt(d.tetrate(t,1,!0)))x=-1;else if(V)x=1;else if(e==3&&o.gt_tolerance(r,1e-8))x=0;else{for(;T.tetrate(t,1,!0).eq_tolerance(d.tetrate(t,1,!0),1e-8)||C.tetrate(t,1,!0).eq_tolerance(d.tetrate(t,1,!0),1e-8)||T.gte(d)||C.lte(d);)h=h.mul(2),T=o.add(h).pow10().recip(),N=d.sub(T),C=d.add(N);C.tetrate(t,1,!0).sub(d.tetrate(t,1,!0)).lt(d.tetrate(t,1,!0).sub(T.tetrate(t,1,!0)))?x=0:x=1}}if(x==-1&&(Y=!0),e==1&&x==1||e==3&&x!=0)if(n.eq(A(1,10,1)))o=o.mul(2);else{let m=!1;if(P&&(x==1&&e==1||x==-1&&e==3)&&(m=!0),o=o.add(n).div(2),m)break}else if(n.eq(A(1,10,1)))n=o,o=o.div(2);else{let m=!1;if(P&&(x==1&&e==1||x==-1&&e==3)&&(m=!0),n=n.sub(p),o=o.sub(p),m)break}if(n.sub(o).div(2).abs().gt(p.mul(1.5))&&(P=!0),p=n.sub(o).div(2).abs(),o.gt("1e18")||o.eq(L))break}if(o.gt("1e18")||!Y||Z==A(1,10,1))break;e==1?r=Z:e==3&&(i=Z),e++}n=r,o=A(1,1,-18);let W=o,a=s.dZero,g=!0;for(;g;)if(n.eq(A(1,10,1))?a=o.mul(2):a=n.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:n=a,a.eq(W)?g=!1:W=a,o.gt("1e18"))return s.dNaN;if(a.eq_tolerance(r,1e-15)){if(i.eq(A(1,10,1)))return s.dNaN;for(n=A(1,10,1),o=i,W=o,a=s.dZero,g=!0;g;)if(n.eq(A(1,10,1))?a=o.mul(2):a=n.add(o).div(2),s.pow(10,a).recip().tetrate(t,1,!0).gt(this)?o=a:n=a,a.eq(W)?g=!1:W=a,o.gt("1e18"))return s.dNaN;return a.pow10().recip()}else return a.pow10().recip()}}pentate(t=2,e=U(1,0,1),r=!1){e=f(e);let i=t;t=Math.trunc(t);let n=i-t;n!==0&&(e.eq(s.dOne)?(++t,e=s.fromNumber(n)):this.eq(10)?e=e.layeradd10(n,r):e=e.layeradd(n,this,r));for(let o=0;o10)return e}return e}sin(){return this.mag<0?this:this.layer===0?s.fromNumber(Math.sin(this.sign*this.mag)):U(0,0,0)}cos(){return this.mag<0?s.dOne:this.layer===0?s.fromNumber(Math.cos(this.sign*this.mag)):U(0,0,0)}tan(){return this.mag<0?this:this.layer===0?s.fromNumber(Math.tan(this.sign*this.mag)):U(0,0,0)}asin(){return this.mag<0?this:this.layer===0?s.fromNumber(Math.asin(this.sign*this.mag)):U(Number.NaN,Number.NaN,Number.NaN)}acos(){return this.mag<0?s.fromNumber(Math.acos(this.toNumber())):this.layer===0?s.fromNumber(Math.acos(this.sign*this.mag)):U(Number.NaN,Number.NaN,Number.NaN)}atan(){return this.mag<0?this:this.layer===0?s.fromNumber(Math.atan(this.sign*this.mag)):s.fromNumber(Math.atan(this.sign*(1/0)))}sinh(){return this.exp().sub(this.negate().exp()).div(2)}cosh(){return this.exp().add(this.negate().exp()).div(2)}tanh(){return this.sinh().div(this.cosh())}asinh(){return s.ln(this.add(this.sqr().add(1).sqrt()))}acosh(){return s.ln(this.add(this.sqr().sub(1).sqrt()))}atanh(){return this.abs().gte(1)?U(Number.NaN,Number.NaN,Number.NaN):s.ln(this.add(1).div(s.fromNumber(1).sub(this))).div(2)}ascensionPenalty(t){return t===0?this:this.root(s.pow(10,t))}egg(){return this.add(9)}lessThanOrEqualTo(t){return this.cmp(t)<1}lessThan(t){return this.cmp(t)<0}greaterThanOrEqualTo(t){return this.cmp(t)>-1}greaterThan(t){return this.cmp(t)>0}static smoothDamp(t,e,r,i){return new s(t).add(new s(e).minus(new s(t)).times(new s(r)).times(new s(i)))}clone(){return this}static clone(t){return s.fromComponents(t.sign,t.layer,t.mag)}softcap(t,e,r){let i=this.clone();return i.gte(t)&&([0,"pow"].includes(r)&&(i=i.div(t).pow(e).mul(t)),[1,"mul"].includes(r)&&(i=i.sub(t).div(e).add(t))),i}static softcap(t,e,r,i){return new s(t).softcap(e,r,i)}scale(t,e,r,i=!1){t=new s(t),e=new s(e);let n=this.clone();return n.gte(t)&&([0,"pow"].includes(r)&&(n=i?n.mul(t.pow(e.sub(1))).root(e):n.pow(e).div(t.pow(e.sub(1)))),[1,"exp"].includes(r)&&(n=i?n.div(t).max(1).log(e).add(t):s.pow(e,n.sub(t)).mul(t))),n}static scale(t,e,r,i,n=!1){return new s(t).scale(e,r,i,n)}format(t=2,e=9,r="mixed_sc"){return ct.format(this.clone(),t,e,r)}static format(t,e=2,r=9,i="mixed_sc"){return ct.format(new s(t),e,r,i)}formatST(t=2,e=9,r="st"){return ct.format(this.clone(),t,e,r)}static formatST(t,e=2,r=9,i="st"){return ct.format(new s(t),e,r,i)}formatGain(t,e="mixed_sc",r,i){return ct.formatGain(this.clone(),t,e,r,i)}static formatGain(t,e,r="mixed_sc",i,n){return ct.formatGain(new s(t),e,r,i,n)}toRoman(t=5e3){t=new s(t);let e=this.clone();if(e.gte(t)||e.lt(1))return e;let r=e.toNumber(),i={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},n="";for(let o of Object.keys(i)){let h=Math.floor(r/i[o]);r-=h*i[o],n+=o.repeat(h)}return n}static toRoman(t,e){return new s(t).toRoman(e)}static random(t=0,e=1){return t=new s(t),e=new s(e),t=t.lt(e)?t:e,e=e.gt(t)?e:t,new s(Math.random()).mul(e.sub(t)).add(t)}static randomProb(t){return new s(Math.random()).lt(t)}};s.dZero=U(0,0,0),s.dOne=U(1,0,1),s.dNegOne=U(-1,0,1),s.dTwo=U(1,0,2),s.dTen=U(1,0,10),s.dNaN=U(Number.NaN,Number.NaN,Number.NaN),s.dInf=U(1,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s.dNegInf=U(-1,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),s.dNumberMax=A(1,0,Number.MAX_VALUE),s.dNumberMin=A(1,0,Number.MIN_VALUE),s.fromStringCache=new Ct(Ee),at([St()],s.prototype,"sign",2),at([St()],s.prototype,"mag",2),at([St()],s.prototype,"layer",2),s=at([Me()],s);var{formats:ct,FORMATS:Be}=_e(s);s.formats=ct;var I=(()=>{let t=e=>new s(e);return Object.getOwnPropertyNames(s).filter(e=>!Object.getOwnPropertyNames(class{}).includes(e)).forEach(e=>{t[e]=s[e]}),t})(),mt=class{get desc(){return this.description}get description(){return this.descriptionFn()}constructor(t){this.id=t.id,this.name=t.name??"",this.descriptionFn=t.description?typeof t.description=="function"?t.description:()=>t.description:()=>"",this.value=t.value,this.order=t.order??99}},Lt=class{constructor(t=1,e){this.addBoost=this.setBoost.bind(this),e=e?Array.isArray(e)?e:[e]:void 0,this.baseEffect=I(t),this.boostArray=[],e&&e.forEach(r=>{this.boostArray.push(new mt(r))})}getBoosts(t,e){let r=[],i=[];for(let n=0;nC),N=n,T=this.getBoosts(o,!0);T[0][0]?this.boostArray[T[1][0]]=new mt({id:o,name:h,description:p,value:d,order:N}):this.boostArray.push(new mt({id:o,name:h,description:p,value:d,order:N}))}else{t=Array.isArray(t)?t:[t];for(let o of t){let h=this.getBoosts(o.id,!0);h[0][0]?this.boostArray[h[1][0]]=new mt(o):this.boostArray.push(new mt(o))}}}calculate(t=this.baseEffect){let e=I(t),r=this.boostArray;r=r.sort((i,n)=>i.order-n.order);for(let i of r)e=i.value(e);return e}},ar=vt(bt()),Ot=30,Qt=.001;function Jt(t,e,r,i){i=Object.assign({},{verbose:!1,mode:"geometric"},i),t=I(t),e=I(e),r=I(r);let n,o;return i.mode==="geometric"?(n=t.sub(e).abs().div(t.abs().add(e.abs()).div(2)),o=n.lte(r)):(n=t.sub(e).abs(),o=n.lte(r)),(i.verbose===!0||i.verbose==="onlyOnFail"&&!o)&&console.log({a:t,b:e,tolerance:r,config:i,diff:n,result:o}),o}function kt(t,e,r="geometric",i=Ot,n=Qt){let o=I(1),h=I(e);if(t(h).eq(0))return{value:I(0),lowerBound:I(0),upperBound:I(0)};if(t(h).lt(e))return console.warn("The function is not monotonically increasing. (f(n) < n)"),{value:h,lowerBound:h,upperBound:h};for(let d=0;de.cost(Z.add(r)),V=I.min(i,kt(C,t,n,o).value.floor()),x=I(0);return[V,x]}let d=kt(C=>Bt(e.cost,C,r),t,n,o).value.floor().min(r.add(p).sub(1)),N=Bt(e.cost,d,r);return[d.sub(r).add(1).max(0),N]}function re(t){return t=I(t),`${t.sign}/${t.mag}/${t.layer}`}function Ue(t){return`el/${re(t)}`}var Nt=class{constructor(t){t=t??{},this.id=t.id,this.level=t.level?I(t.level):I(1)}};at([St()],Nt.prototype,"id",2),at([It(()=>s)],Nt.prototype,"level",2);var ie=class de{static{this.cacheSize=15}get data(){return this.dataPointerFn()}get description(){return this.descriptionFn()}get level(){return((this??{data:{level:I(1)}}).data??{level:I(1)}).level}set level(e){this.data.level=I(e)}constructor(e,r,i){let n=typeof r=="function"?r():r;this.dataPointerFn=typeof r=="function"?r:()=>n,this.cache=new Ct(i??de.cacheSize),this.id=e.id,this.name=e.name??e.id,this.descriptionFn=e.description?typeof e.description=="function"?e.description:()=>e.description:()=>"",this.cost=e.cost,this.costBulk=e.costBulk,this.maxLevel=e.maxLevel,this.effect=e.effect,this.el=e.el,this.defaultLevel=e.level??I(1)}},or=vt(bt()),Ft=class{constructor(){this.value=I(0),this.upgrades={}}};at([It(()=>s)],Ft.prototype,"value",2),at([It(()=>Nt)],Ft.prototype,"upgrades",2);var Re=class{get pointer(){return this.pointerFn()}get value(){return this.pointer.value}set value(t){this.pointer.value=t}constructor(t=new Ft,e,r={defaultVal:I(0),defaultBoost:I(1)}){this.defaultVal=r.defaultVal,this.defaultBoost=r.defaultBoost,this.pointerFn=typeof t=="function"?t:()=>t,this.boost=new Lt(this.defaultBoost),this.pointer.value=this.defaultVal,this.upgrades={},e&&this.addUpgrade(e)}onLoadData(){for(let t of Object.values(this.upgrades))t.effect?.(t.level,t,this)}reset(t=!0,e=!0,r=!0){if(t&&(this.value=this.defaultVal),e)for(let i of Object.values(this.upgrades))i.level=I(i.defaultLevel),r&&i.effect?.(i.level,i,this)}gain(t=1e3){let e=this.boost.calculate().mul(I(t).div(1e3));return this.pointer.value=this.pointer.value.add(e),e}pointerAddUpgrade(t){let e=new Nt(t);return this.pointer.upgrades[e.id]=e,e}pointerGetUpgrade(t){return this.pointer.upgrades[t]??null}getUpgrade(t){return this.upgrades[t]??null}addUpgrade(t,e=!0){Array.isArray(t)||(t=[t]);let r={};for(let i of t){let n=this.pointerAddUpgrade(i),o=new ie(i,()=>this.pointerGetUpgrade(i.id));o.effect&&e&&o.effect(o.level,o,this),r[i.id]=o,this.upgrades[i.id]=o}return Object.values(r)}updateUpgrade(t,e){let r=this.getUpgrade(t);r!==null&&(r.name=e.name??r.name,r.cost=e.cost??r.cost,r.maxLevel=e.maxLevel??r.maxLevel,r.effect=e.effect??r.effect)}calculateUpgrade(t,e=1/0,r,i){let n=this.getUpgrade(t);return n===null?(console.warn(`Upgrade "${t}" not found.`),[I(0),I(0)]):(e=n.level.add(e),n.maxLevel!==void 0&&(e=I.min(e,n.maxLevel)),ee(this.value,n,n.level,e,r,i))}getNextCost(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),I(0);let o=this.calculateUpgrade(t,e,r,i)[0];return n.cost(n.level.add(o))}getNextCostMax(t,e=1,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),I(0);let o=this.calculateUpgrade(t,e,r,i);return n.cost(n.level.add(o[0])).add(o[1])}buyUpgrade(t,e,r,i){let n=this.getUpgrade(t);if(n===null)return console.warn(`Upgrade "${t}" not found.`),!1;let[o,h]=this.calculateUpgrade(t,e,r,i);return o.lte(0)?!1:(this.pointer.value=this.pointer.value.sub(h),n.level=n.level.add(o),n.effect?.(n.level,n,this),!0)}},ur=vt(bt()),Gt=class{constructor(t=0){this.value=I(t)}};at([It(()=>s)],Gt.prototype,"value",2);var Ve=class{get pointer(){return this.pointerFn()}constructor(t,e=!0,r=0){this.initial=I(r),t??=new Gt(this.initial),this.pointerFn=typeof t=="function"?t:()=>t,this.boost=e?new Lt(this.initial):null}update(){console.warn("AttributeStatic.update is deprecated and will be removed in the future. The value is automatically updated when accessed."),this.boost&&(this.pointer.value=this.boost.calculate())}get value(){return this.boost&&(this.pointer.value=this.boost.calculate()),this.pointer.value}set value(t){if(this.boost)throw new Error("Cannot set value of attributeStatic when boost is enabled.");this.pointer.value=t}},ne=class{constructor(t,e,r){this.x=t,this.y=e,this.properties=r??{}}setValue(t,e){return this.properties[t]=e,e}getValue(t){return this.properties[t]}},je=class{constructor(t,e,r){this.xSize=t,this.ySize=e,this.cells=[];for(let i=0;i{if(e&&typeof e=="object"||typeof e=="function")for(let n of Object.getOwnPropertyNames(e))!Object.prototype.hasOwnProperty.call(t,n)&&n!==r&&Object.defineProperty(t,n,{get:()=>e[n],enumerable:!(i=Object.getOwnPropertyDescriptor(e,n))||i.enumerable});return t};nt.exports=$e(nt.exports,pt)}return nt.exports}); /*! Bundled license information: reflect-metadata/Reflect.js: diff --git a/dist/main/eMath.mjs b/dist/main/eMath.mjs index 1ae12df..68cb671 100644 --- a/dist/main/eMath.mjs +++ b/dist/main/eMath.mjs @@ -4744,7 +4744,7 @@ import "reflect-metadata"; import { Type, Expose as Expose2 } from "class-transformer"; // src/classes/numericalAnalysis.ts -var DEFAULT_ITERATIONS = 35; +var DEFAULT_ITERATIONS = 30; var DEFAULT_TOLERANCE = 1e-3; function equalsTolerance(a, b, tolerance, config) { config = Object.assign({}, { @@ -4799,7 +4799,8 @@ function inverseFunctionApprox(f, n, mode = "geometric", iterations = DEFAULT_IT const midValue = f(mid); if (equalsTolerance(lowerBound, upperBound, tolerance, { verbose: false, mode: "geometric" })) { break; - } else if (midValue.lt(n)) { + } + if (midValue.lt(n)) { lowerBound = mid; } else { upperBound = mid; @@ -4845,14 +4846,14 @@ function calculateSum(f, b, a = 0, epsilon, iterations) { return calculateSumApprox(f, b, a, iterations); } } -function roundingBase(x, acc = 10, sig = 0, max = 1e3) { +function roundingBase(x, base = 10, acc = 0, max = 1e3) { x = E(x); - if (x.gte(E.pow(acc, max))) return x; - const powerN = E.floor(E.log(x, acc)); - let out = x.div(E.pow(acc, powerN)); - out = out.mul(E.pow(acc, sig)).round(); - out = out.div(E.pow(acc, sig)); - out = out.mul(E.pow(acc, powerN)); + if (x.gte(E.pow(base, max))) return x; + const powerN = E.floor(E.log(x, base)); + let out = x.div(E.pow(base, powerN)); + out = out.mul(E.pow(base, acc)).round(); + out = out.div(E.pow(base, acc)); + out = out.mul(E.pow(base, powerN)); return out; } @@ -4905,9 +4906,6 @@ function decimalToJSONString(n) { n = E(n); return `${n.sign}/${n.mag}/${n.layer}`; } -function upgradeToCacheNameSum(start, end) { - return `sum/${decimalToJSONString(start)}/${decimalToJSONString(end)}}`; -} function upgradeToCacheNameEL(level) { return `el/${decimalToJSONString(level)}`; } @@ -4931,7 +4929,7 @@ __decorateClass([ var UpgradeStatic = class _UpgradeStatic { static { /** The default size of the cache. Should be one less than a power of 2. */ - this.cacheSize = 63; + this.cacheSize = 15; } /** @returns The data of the upgrade. */ get data() { @@ -4954,7 +4952,7 @@ var UpgradeStatic = class _UpgradeStatic { * Constructs a new static upgrade object. * @param init - The upgrade object to initialize. * @param dataPointer - A function or reference that returns the pointer of the data / frontend. - * @param cacheSize - The size of the cache. Should be one less than a power of 2. See {@link cache} + * @param cacheSize - The size of the cache. Should be one less than a power of 2. See {@link cache}. Set to `0` to disable caching. */ constructor(init, dataPointer, cacheSize) { const data = typeof dataPointer === "function" ? dataPointer() : dataPointer; @@ -4970,33 +4968,51 @@ var UpgradeStatic = class _UpgradeStatic { this.el = init.el; this.defaultLevel = init.level ?? E(1); } - getCached(type, start, end) { - if (type === "sum") { - return this.cache.get(upgradeToCacheNameSum(start, end ?? E(0))); - } else { - return this.cache.get(upgradeToCacheNameEL(start)); - } - } - setCached(type, start, endOrStart, costSum) { - const data = type === "sum" ? { - id: this.id, - el: false, - start: E(start), - end: E(endOrStart), - cost: E(costSum) - } : { - id: this.id, - el: true, - level: E(start), - cost: E(endOrStart) - }; - if (type === "sum") { - this.cache.set(upgradeToCacheNameSum(start, endOrStart), data); - } else { - this.cache.set(upgradeToCacheNameEL(start), data); - } - return data; - } + // /** + // * Gets the cached data of the upgrade. + // * @param type - The type of the cache. "sum" or "el" + // * @param start - The starting level of the upgrade. + // * @param end - The ending level or quantity to reach for the upgrade. + // * @returns The data of the upgrade. + // */ + // public getCached (type: "sum", start: ESource, end: ESource): UpgradeCachedSum | undefined; + // public getCached (type: "el", start: ESource): UpgradeCachedEL | undefined; + // public getCached (type: "sum" | "el", start: ESource, end?: ESource): UpgradeCachedEL | UpgradeCachedSum | undefined { + // if (type === "sum") { + // return this.cache.get(upgradeToCacheNameSum(start, end ?? E(0))); + // } else { + // return this.cache.get(upgradeToCacheNameEL(start)); + // } + // } + // /** + // * Sets the cached data of the upgrade. + // * @param type - The type of the cache. "sum" or "el" + // * @param start - The starting level of the upgrade. + // * @param end - The ending level or quantity to reach for the upgrade. + // * @param cost - The cost of the upgrade. + // */ + // public setCached(type: "sum", start: ESource, end: ESource, cost: ESource): UpgradeCachedSum; + // public setCached(type: "el", level: ESource, cost: ESource): UpgradeCachedEL; + // public setCached (type: "sum" | "el", start: ESource, endOrStart: ESource, costSum?: ESource): UpgradeCachedEL | UpgradeCachedSum { + // const data = type === "sum" ? { + // id: this.id, + // el: false, + // start: E(start), + // end: E(endOrStart), + // cost: E(costSum), + // } : { + // id: this.id, + // el: true, + // level: E(start), + // cost: E(endOrStart), + // }; + // if (type === "sum") { + // this.cache.set(upgradeToCacheNameSum(start, endOrStart), data as UpgradeCachedSum); + // } else { + // this.cache.set(upgradeToCacheNameEL(start), data as UpgradeCachedEL); + // } + // return data as UpgradeCachedEL | UpgradeCachedSum; + // } }; // src/classes/Currency.ts diff --git a/dist/types/classes/Upgrade.d.ts b/dist/types/classes/Upgrade.d.ts index 1151d03..53c93d5 100644 --- a/dist/types/classes/Upgrade.d.ts +++ b/dist/types/classes/Upgrade.d.ts @@ -11,7 +11,9 @@ import type { CurrencyStatic } from "./Currency"; /** * Calculates the cost and how many upgrades you can buy * Uses {@link inverseFunctionApprox} to calculate the maximum affordable quantity. - * The priority is: `target === 1` > `costBulk` > `el` + * The priority is: `target === 1` > `costBulk` > `el`. + * For sum upgrades, this function has a max time complexity of O(n^2) where n is the number of iterations. + * For el upgrades, this function has a max time complexity of O(n) where n is the number of iterations. * @param value - The current value of the currency. * @param upgrade - The upgrade object to calculate. * @param start - The starting level of the upgrade. Defaults the current level of the upgrade. @@ -115,40 +117,11 @@ interface UpgradeInit { * id: "upgId2", * cost: (level: E): E => level.mul(20), * }, - * ] as const satisfies UpgradeInit[] + * ] as const satisfies UpgradeInit[] // Must be readonly and satisfy UpgradeInit * * type test = UpgradeInitArrayType // "upgId1" | "upgId2" */ type UpgradeInitArrayType = U[number]["id"] extends never ? string : U[number]["id"]; -/** - * Interface for an upgrade. - * @template N - The ID of the upgrade. See {@link UpgradeInit} - */ -interface IUpgradeStatic extends Omit { - maxLevel?: E; - name: string; - description: string; - defaultLevel: E; - /** - * A function that returns a description of the upgrade. - * @param args - Arguments to pass to the description function. - * @returns The description of the upgrade. - */ - descriptionFn: (...args: any[]) => string; -} -/** - * Converts an upgrade init to a static upgrade. - * @deprecated - This is no longer used - */ -type ConvertInitToStatic = Omit & { - defaultLevel: E; - descriptionFn: (...args: any[]) => string; -}; -/** - * Interface for upgrade data. - * @template N - The ID of the upgrade. See {@link UpgradeInit} - */ -type IUpgradeData = Pick; /** * Represents a decimal number in the form of a string. `sign/mag/layer` * @deprecated Use an object index instead. @@ -182,26 +155,27 @@ declare function decimalToJSONString(n: ESource): DecimalJSONString; declare function upgradeToCacheNameEL(level: ESource): UpgradeCachedELName; /** * Interface for an upgrade that is cached. - * @template EL - Whether the upgrade is EL or not. + * We need a cache to reduce redundant calculations. + * + * We store the level, and the level +/- 1, or times/divided by 1 + 1e-3 if the level is larger than ~2e3. + * and the cost of the upgrade at those levels. + * + * This approach might be useful for lower levels of upgrades, but it's not very useful for higher levels. */ -interface UpgradeCached extends Pick { - el: EL; +interface UpgradeCached extends Pick { + el: boolean; + endLower: UpgradeCachedLevel; + end: UpgradeCachedLevel; + endUpper: UpgradeCachedLevel; } -/** Interface for an upgrade that is cached. (EL) */ -interface UpgradeCachedEL extends UpgradeCached, Pick { +interface UpgradeCachedLevel { level: E; - /** The cost of the upgrade at level (el) */ - cost: E; -} -/** Interface for an upgrade that is cached. (Not EL) */ -interface UpgradeCachedSum extends UpgradeCached { - start: E; - end: E; - /** - * The cost of the upgrade from start to end. (summation) - */ cost: E; } +/** + * Interface for upgrade data. + */ +type IUpgradeData = Pick; /** * Represents the frontend for an upgrade. * @template N - The ID of the upgrade. See {@link UpgradeInit} @@ -215,6 +189,22 @@ declare class UpgradeData implements IUpgradeData { */ constructor(init: Pick); } +/** + * Interface for an upgrade. + */ +interface IUpgradeStatic extends Omit { + maxLevel?: E; + name: string; + description: string; + defaultLevel: E; + /** + * A function that returns a description of the upgrade. + * @deprecated Use a getter function instead. + * @param args - Arguments to pass to the description function. + * @returns The description of the upgrade. + */ + descriptionFn: (...args: any[]) => string; +} /** * Represents the backend for an upgrade. */ @@ -231,7 +221,7 @@ declare class UpgradeStatic implements IUpgradeStatic { /** The default size of the cache. Should be one less than a power of 2. */ static cacheSize: number; /** The cache to store the values of certain upgrade levels */ - cache: LRUCache; + cache: LRUCache; /** @returns The data of the upgrade. */ protected dataPointerFn: () => UpgradeData; /** @returns The data of the upgrade. */ @@ -247,29 +237,11 @@ declare class UpgradeStatic implements IUpgradeStatic { * Constructs a new static upgrade object. * @param init - The upgrade object to initialize. * @param dataPointer - A function or reference that returns the pointer of the data / frontend. - * @param cacheSize - The size of the cache. Should be one less than a power of 2. See {@link cache} + * @param cacheSize - The size of the cache. Should be one less than a power of 2. See {@link cache}. Set to `0` to disable caching. */ constructor(init: UpgradeInit, dataPointer: Pointer, cacheSize?: number); - /** - * Gets the cached data of the upgrade. - * @param type - The type of the cache. "sum" or "el" - * @param start - The starting level of the upgrade. - * @param end - The ending level or quantity to reach for the upgrade. - * @returns The data of the upgrade. - */ - getCached(type: "sum", start: ESource, end: ESource): UpgradeCachedSum | undefined; - getCached(type: "el", start: ESource): UpgradeCachedEL | undefined; - /** - * Sets the cached data of the upgrade. - * @param type - The type of the cache. "sum" or "el" - * @param start - The starting level of the upgrade. - * @param end - The ending level or quantity to reach for the upgrade. - * @param cost - The cost of the upgrade. - */ - setCached(type: "sum", start: ESource, end: ESource, cost: ESource): UpgradeCachedSum; - setCached(type: "el", level: ESource, cost: ESource): UpgradeCachedEL; } -export type { IUpgradeStatic, IUpgradeData, UpgradeInit, UpgradeInitArrayType, ConvertInitToStatic }; +export type { IUpgradeStatic, IUpgradeData, UpgradeInit, UpgradeInitArrayType }; export { UpgradeData, UpgradeStatic, calculateUpgrade }; -export type { DecimalJSONString, UpgradeCachedELName, UpgradeCachedSumName, UpgradeCached, UpgradeCachedEL, UpgradeCachedSum }; +export type { DecimalJSONString, UpgradeCachedELName, UpgradeCachedSumName, UpgradeCached }; export { decimalToJSONString, upgradeToCacheNameEL }; diff --git a/dist/types/classes/numericalAnalysis.d.ts b/dist/types/classes/numericalAnalysis.d.ts index 6e98d2d..4ba3395 100644 --- a/dist/types/classes/numericalAnalysis.d.ts +++ b/dist/types/classes/numericalAnalysis.d.ts @@ -17,17 +17,29 @@ import { E } from "../E/eMain"; * - At 100 iterations, the time it takes to calculate is ~2 ms but with marginal accuracy improvements. * - At 1000 iterations, the time it takes to calculate is ~7 ms but with very marginal accuracy improvements. * - At 10000 iterations, the time it takes to calculate is ~30 ms. - * @default 35 + * @default 30 */ -declare const DEFAULT_ITERATIONS = 35; +declare const DEFAULT_ITERATIONS = 30; /** * Represents different methods to calculate the mean. * Mode 1 `"arithmetic"` `(a+b)/2` is a bit faster but way less accurate for large numbers. * Mode 2 `"geometric"` `sqrt(ab)` is more accurate, and is the default. */ type MeanMode = "arithmetic" | "geometric" | 1 | 2; +/** + * The configuration object for the {@link equalsTolerance} function. + */ interface EqualsToleranceConfig { + /** + * Whether to log the values (a, b, tolerance, config, diff, result) to the console. + * - `true` - Log the values to the console. + * - `false` - Do not log the values to the console. + * - `"onlyOnFail"` - Only log the values to the console if the result is `false`. + */ verbose: boolean | "onlyOnFail"; + /** + * The mode/mean method to use. See {@link MeanMode} + */ mode: MeanMode; } /** @@ -41,17 +53,18 @@ interface EqualsToleranceConfig { declare function equalsTolerance(a: ESource, b: ESource, tolerance: ESource, config?: Partial): boolean; /** * Approximates the inverse of a function at `n` using the bisection / binary search method. - * @param f - The function to approximate the inverse of. It must be monotonically increasing. + * @param f - The function to approximate the inverse of. It must be monotonically increasing and satisfy `f(n) >= n` for all `n >= 0`. * @param n - The value to approximate the inverse at. * @param mode - The mode/mean method to use. See {@link MeanMode} * @param iterations - The amount of iterations to perform. Defaults to {@link DEFAULT_ITERATIONS}. + * @param tolerance - The tolerance to approximate the inverse with. Defaults to {@link DEFAULT_TOLERANCE}. * @returns An object containing the approximate inverse value `"value"` (defaults to the lower bound), the lower bound `"lowerBound"`, and the upper bound `"upperBound"`. * @example * const f = (x) => x.pow(2); * const inverse = inverseFunctionApprox(f, 16); * console.log(inverse.value); // ~3.9999999999999996 */ -declare function inverseFunctionApprox(f: (x: E) => E, n: ESource, mode?: MeanMode, iterations?: number): { +declare function inverseFunctionApprox(f: (x: E) => E, n: ESource, mode?: MeanMode, iterations?: number, tolerance?: number): { value: E; lowerBound: E; upperBound: E; @@ -62,7 +75,7 @@ declare function inverseFunctionApprox(f: (x: E) => E, n: ESource, mode?: MeanMo * @param f - The function `f(n)` to calculate the sum. * @param b - The upper limit for the sum. * @param a - The lower limit for the sum. Defaults to `0`. The order is reversed because `a` is optional. Deal with it. - * @param epsilon - The maximum error tolerance, geometrically. Defaults to `1e-3`. + * @param epsilon - The maximum error tolerance, geometrically. Defaults to {@link DEFAULT_TOLERANCE}. * @returns The calculated sum of `f(n)`. */ declare function calculateSumLoop(f: (n: E) => E, b: ESource, a?: ESource, epsilon?: ESource): E; @@ -81,7 +94,7 @@ declare function calculateSumApprox(f: (n: E) => E, b: ESource, a?: ESource, ite * @param f - The function `f(n)` to calculate the sum. * @param b - The upper limit for the sum. * @param a - The lower limit for the sum. Defaults to `0`. The order is reversed because `a` is optional. Deal with it. - * @param epsilon - The maximum error tolerance, geometrically. Defaults to `1e-3`. Only used if `b - a` is less than or equal to {@link DEFAULT_ITERATIONS}. + * @param epsilon - The maximum error tolerance, geometrically. Defaults to {@link DEFAULT_TOLERANCE}. Only used if `b - a` is less than or equal to {@link DEFAULT_ITERATIONS}. * @param iterations - The amount of iterations to perform. Defaults to {@link DEFAULT_ITERATIONS}. Only used if `b - a` is greater than {@link DEFAULT_ITERATIONS}. * @returns - The calculated sum of `f(n)`. * @example @@ -91,10 +104,10 @@ declare function calculateSumApprox(f: (n: E) => E, b: ESource, a?: ESource, ite */ declare function calculateSum(f: (n: E) => E, b: ESource, a?: ESource, epsilon?: ESource, iterations?: number): E; /** - * Function to round a number to the nearest power of a specified base. Warning: Experimental. + * Function to round a number to the nearest power of a specified base. Warning: Experimental, not tested on negative numbers / parameters. * @param x - The number to round. - * @param acc - The accuracy to round to (power) - * @param sig - The significant figures to round to. + * @param base - The power base to round to. + * @param acc - The accuracy / significant figures to round to. * @param max - The maximum power to round to. * @returns - The rounded number. * @example @@ -103,6 +116,6 @@ declare function calculateSum(f: (n: E) => E, b: ESource, a?: ESource, epsilon?: * console.log(roundingBase(123456789, 10, 2, 10)); // 123000000 * console.log(roundingBase(245, 2, 0, 10)); // 256 */ -declare function roundingBase(x: ESource, acc?: ESource, sig?: ESource, max?: ESource): E; +declare function roundingBase(x: ESource, base?: ESource, acc?: ESource, max?: ESource): E; export { equalsTolerance, inverseFunctionApprox, calculateSumLoop, calculateSumApprox, calculateSum, roundingBase, DEFAULT_ITERATIONS }; export type { MeanMode, EqualsToleranceConfig }; diff --git a/dist/types/game/hookGame.d.ts b/dist/types/game/hookGame.d.ts index 62dcf83..f83afde 100644 --- a/dist/types/game/hookGame.d.ts +++ b/dist/types/game/hookGame.d.ts @@ -94,6 +94,6 @@ declare const eMathGameWeb: { calculateSumApprox: typeof eMath.calculateSumApprox; calculateSum: typeof eMath.calculateSum; roundingBase: typeof eMath.roundingBase; - DEFAULT_ITERATIONS: 35; + DEFAULT_ITERATIONS: 30; }; export { eMathGameWeb as eMath }; diff --git a/src/classes/Upgrade.ts b/src/classes/Upgrade.ts index 656329c..d39cffe 100644 --- a/src/classes/Upgrade.ts +++ b/src/classes/Upgrade.ts @@ -13,7 +13,9 @@ import type { CurrencyStatic } from "./Currency"; /** * Calculates the cost and how many upgrades you can buy * Uses {@link inverseFunctionApprox} to calculate the maximum affordable quantity. - * The priority is: `target === 1` > `costBulk` > `el` + * The priority is: `target === 1` > `costBulk` > `el`. + * For sum upgrades, this function has a max time complexity of O(n^2) where n is the number of iterations. + * For el upgrades, this function has a max time complexity of O(n) where n is the number of iterations. * @param value - The current value of the currency. * @param upgrade - The upgrade object to calculate. * @param start - The starting level of the upgrade. Defaults the current level of the upgrade. diff --git a/src/classes/numericalAnalysis.ts b/src/classes/numericalAnalysis.ts index e41b4f2..fba628f 100644 --- a/src/classes/numericalAnalysis.ts +++ b/src/classes/numericalAnalysis.ts @@ -18,9 +18,9 @@ import { E } from "../E/eMain"; * - At 100 iterations, the time it takes to calculate is ~2 ms but with marginal accuracy improvements. * - At 1000 iterations, the time it takes to calculate is ~7 ms but with very marginal accuracy improvements. * - At 10000 iterations, the time it takes to calculate is ~30 ms. - * @default 35 + * @default 30 */ -const DEFAULT_ITERATIONS = 35; +const DEFAULT_ITERATIONS = 30; /** * The default tolerance to compare the values with. @@ -96,7 +96,7 @@ function equalsTolerance (a: ESource, b: ESource, tolerance: ESource, config?: P /** * Approximates the inverse of a function at `n` using the bisection / binary search method. - * @param f - The function to approximate the inverse of. It must be monotonically increasing. + * @param f - The function to approximate the inverse of. It must be monotonically increasing and satisfy `f(n) >= n` for all `n >= 0`. * @param n - The value to approximate the inverse at. * @param mode - The mode/mean method to use. See {@link MeanMode} * @param iterations - The amount of iterations to perform. Defaults to {@link DEFAULT_ITERATIONS}. @@ -134,9 +134,12 @@ function inverseFunctionApprox (f: (x: E) => E, n: ESource, mode: MeanMode = "ge } // console.log({ lowerBound, upperBound, iterations }); + // Perform the bisection / binary search for (let i = 0; i < iterations; i++) { let mid: E; + + // Determine the mean value switch (mode) { case "arithmetic": case 1: @@ -146,19 +149,22 @@ function inverseFunctionApprox (f: (x: E) => E, n: ESource, mode: MeanMode = "ge case 2: mid = lowerBound.mul(upperBound).sqrt(); break; - // case "pow": - // mid = lowerBound.pow(upperBound).ssqrt(); } const midValue = f(mid); // console.log({ lowerBound, upperBound, mid, midValue, n, i }); + + // Stop the loop if the bounds are close enough if (equalsTolerance(lowerBound, upperBound, tolerance, { verbose: false, mode: "geometric" })) { - // Stop the loop if the bounds are close // console.log("bounds close", { lowerBound, upperBound, mid, midValue, n, i }); break; - } else if (midValue.lt(n)) { + } + + if (midValue.lt(n)) { + // If the value is less than the target, set the lower bound to the mid value lowerBound = mid; } else { + // If the value is greater than the target, set the upper bound to the mid value upperBound = mid; } } @@ -214,14 +220,17 @@ function calculateSumLoop (f: (n: E) => E, b: ESource, a: ESource = 0, epsilon: * @returns The calculated sum of `f(n)`. */ function calculateSumApprox (f: (n: E) => E, b: ESource, a: ESource = 0, iterations: number = DEFAULT_ITERATIONS): E { + // Initialize the values a = E(a); b = E(b); let sum = E(0); const intervalWidth = b.sub(a).div(iterations); + for (let i = 0; i < iterations; i++) { const x0 = a.add(intervalWidth.mul(i)); const x1 = a.add(intervalWidth.mul(i + 1)); + sum = sum.add(f(x0).add(f(x1)).div(2).mul(intervalWidth)); } return sum; @@ -251,10 +260,10 @@ function calculateSum (f: (n: E) => E, b: ESource, a: ESource = 0, epsilon?: ESo } /** - * Function to round a number to the nearest power of a specified base. Warning: Experimental. + * Function to round a number to the nearest power of a specified base. Warning: Experimental, not tested on negative numbers / parameters. * @param x - The number to round. - * @param acc - The accuracy to round to (power) - * @param sig - The significant figures to round to. + * @param base - The power base to round to. + * @param acc - The accuracy / significant figures to round to. * @param max - The maximum power to round to. * @returns - The rounded number. * @example @@ -263,16 +272,18 @@ function calculateSum (f: (n: E) => E, b: ESource, a: ESource = 0, epsilon?: ESo * console.log(roundingBase(123456789, 10, 2, 10)); // 123000000 * console.log(roundingBase(245, 2, 0, 10)); // 256 */ -function roundingBase (x: ESource, acc: ESource = 10, sig: ESource = 0, max: ESource = 1000): E { +function roundingBase (x: ESource, base: ESource = 10, acc: ESource = 0, max: ESource = 1000): E { x = E(x); // If the number is too large, don't round it - if (x.gte(E.pow(acc, max))) return x; + if (x.gte(E.pow(base, max))) return x; + /** The power of the number, rounded. acc^power = x */ - const powerN = E.floor(E.log(x, acc)); - let out = x.div(E.pow(acc, powerN)); - out = out.mul(E.pow(acc, sig)).round(); - out = out.div(E.pow(acc, sig)); - out = out.mul(E.pow(acc, powerN)); + const powerN = E.floor(E.log(x, base)); + + let out = x.div(E.pow(base, powerN)); + out = out.mul(E.pow(base, acc)).round(); + out = out.div(E.pow(base, acc)); + out = out.mul(E.pow(base, powerN)); return out; }