a-calc 0.0.32 → 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/index.core.js +1 -1
- package/browser/index.html +16 -15
- package/browser/index.js +1 -1
- package/cjs/index.js +1 -1
- package/es/index.js +1 -1
- package/package.json +6 -6
package/browser/index.core.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var a_calc=function(r){"use strict";function t(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var u=t(
|
|
1
|
+
var a_calc=function(r){"use strict";function t(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var u=t(BigNumber);function o(r,t){if(!(r instanceof t))throw new TypeError("Cannot call a class as a function")}function n(r,t){for(var e=0;e<t.length;e++){var n=t[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,n.key,n)}}function i(r,t,e){return t&&n(r.prototype,t),e&&n(r,e),Object.defineProperty(r,"prototype",{writable:!1}),r}function a(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(t&&t.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),t&&f(r,t)}function l(r){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)})(r)}function f(r,t){return(f=Object.setPrototypeOf||function(r,t){return r.__proto__=t,r})(r,t)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(r){return!1}}function s(r,t,e){return(s=c()?Reflect.construct:function(r,t,e){var n=[null];n.push.apply(n,t);t=new(Function.bind.apply(r,n));return e&&f(t,e.prototype),t}).apply(null,arguments)}function p(r){var e="function"==typeof Map?new Map:void 0;return(p=function(r){if(null===r||-1===Function.toString.call(r).indexOf("[native code]"))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(r))return e.get(r);e.set(r,t)}function t(){return s(r,arguments,l(this).constructor)}return t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),f(t,r)})(r)}function h(r,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");t=r;if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function d(e){var n=c();return function(){var r,t=l(e);return h(this,n?(r=l(this).constructor,Reflect.construct(t,arguments,r)):t.apply(this,arguments))}}function v(r){return function(r){if(Array.isArray(r))return y(r)}(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||function(r,t){if(r){if("string"==typeof r)return y(r,t);var e=Object.prototype.toString.call(r).slice(8,-1);return"Map"===(e="Object"===e&&r.constructor?r.constructor.name:e)||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?y(r,t):void 0}}(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}function g(r){return-1<"+-*/%()".indexOf(r)}function b(r){switch(r){case"+":case"-":return 1;case"*":case"/":case"%":return 2;default:return 0}}function w(r){var t={expr:"",fmt:null,data:null},e="",n=r[0];if(1===r.length)"string"==typeof n?e=n:"number"==typeof n?e=n.toString():Array.isArray(n)&&(e=n[0]);else if(1<r.length){n=r[r.length-1];if(l=n,"[object Object]"!==Object.prototype.toString.call(l)||Array.isArray(l))for(var o=v(r.shift());o.length||r.length;)var i=0===o.length?"":o.shift(),a=0===r.length?"":r.shift(),e=e+i+(a="number"==typeof a?a.toString():a);else e=r[0],t.data=n}var l=e.split("|");return 1===l.length?t.expr=l[0]:(t.expr=l[0],""!==(n=l[1]).trim()&&(t.fmt=n)),t}function m(r,t){var e="",n=(e=u.default.isBigNumber(r)?r.toFixed():"string"!=typeof r?r.toString():r,null),r=null,o=null,i=t.match(/(<=|>=|=)\s*(\d+)/);if(i&&(r=i[1],n=Number(i[2])),t.includes(",")&&(o=!0),null!==n){var i=e.split("."),t=i[0],a=1===i.length?"":i[1],l=a.length;switch(r){case"<=":a=l<=n?a:a.slice(0,n);break;case"=":l<n?a+="0".repeat(n-l):n<l&&(a=a.slice(0,n));break;case">=":a=n<=l?a:a+"0".repeat(n-l)}e=""===a?t:"".concat(t,".").concat(a)}return e=null!==o?1<(i=e.split(".")).length?((r=i[0]).includes("-")?i[0]=r[0]+r.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):i[0]=r.replace(/(?=(?!^)(?:\d{3})+$)/g,","),i.join(".")):(t=i[0]).includes("-")?t[0]+t.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):t.replace(/(?=(?!^)(?:\d{3})+$)/g,","):e}function O(r){for(var t=[],e=0,n=null,o=r.length;e<o;)if(n=r[e],/\s/.test(n))e++;else if("+-".includes(n)){var i=t[t.length-1];if(0===t.length||"+-".includes(i)||"("===i){for(var a=n,n=r[++e];/[a-zA-Z\d._]/.test(n);)a+=n,n=r[++e];t.push(a)}else t.push(n),e++}else if("*/%()".includes(n))t.push(n),e++;else if(/[a-zA-Z_]/.test(n)){for(var l="";/[a-zA-Z0-9_]/.test(n)&&(l+=n,!(++e>=o));)n=r[e];t.push(l)}else if(/\d/.test(n)){for(var u="";/[\d.]/.test(n)&&(u+=n,!(++e>=o));)n=r[e];t.push(u)}return t}var j=function(){a(n,p(Error));var e=d(n);function n(r){var t;return o(this,n),(t=e.call(this,r)).name="CalculatorError",t.message=r,t}return i(n)}(),E=function(){a(n,p(Error));var e=d(n);function n(r){var t;return o(this,n),(t=e.call(this,r)).name="TokensFillError",t.message=r,t}return i(n)}();function _(r,t){var e=t._fillData;return void 0===t._fillData&&(e=t),r.map(function(r){if(/^[a-zA-z_][\w_]*$/.test(r)){var t=e[r];if(void 0!==t)return"number"==typeof t?t.toString():t;throw new E("错误的参数:".concat(r," 请确认他存在"))}return r})}function A(r){for(var t,e=[],n=[],o=r;0<o.length;){var i=o.shift();if(g(i))if("("===i)e.push(i);else if(")"===i){for(var a=e.pop();"("!==a&&0<e.length;)n.push(a),a=e.pop();if("("!==a)throw"error: unmatched ()"}else{for(;t=e[e.length-1],b(i)<=b(t)&&0<e.length;)n.push(e.pop());e.push(i)}else n.push(i)}if(0<e.length){if(")"===e[e.length-1]||"("===e[e.length-1])throw"error: unmatched ()";for(;0<e.length;)n.push(e.pop())}return n}function x(r){for(var t=[];0<r.length;){var e=r.shift();if(g(e)){if(t.length<2)throw new j("错误的栈长度, 可能是无法计算的表达式");var n=t.pop(),o=t.pop();if("string"==typeof n&&!u.default.isBigNumber(n)){if(!/^[+-]*[\d.]+$/.test(n))throw new j("".concat(n,"不是一个合法的数字"));n=new u.default(n)}if("string"==typeof o&&!u.default.isBigNumber(o)){if(!/^[+-]*[\d.]+$/.test(o))throw new j("".concat(o,"不是一个合法的数字"));o=new u.default(o)}switch(e){case"+":t.push(o.plus(n));break;case"-":t.push(o.minus(n));break;case"*":t.push(o.times(n));break;case"/":t.push(o.div(n));break;case"%":t.push(o.mod(n))}}else t.push(e)}if(1!==t.length)throw"unvalid expression";return t[0]}return r.calc=function(){for(var r=arguments.length,t=new Array(r),e=0;e<r;e++)t[e]=arguments[e];var n=w(t),o=O(n.expr),i=null;if(null!==n.data)if(null===(i=void 0!==n.data._fillData?n.data:i)||void 0===i.fillError&&void 0===i.error)o=_(o,n.data);else try{o=_(o,n.data)}catch(r){if(r instanceof E)return void 0!==i.warn&&!0===i.warn&&console.warn(r),i.fillError||i.error;throw r}var o=A(o),a=null;if(null!==i){if(void 0!==i.calcError||void 0!==i.error)try{a=x(o)}catch(r){if(r instanceof j)return void 0!==i.warn&&!0===i.warn&&console.warn(r),void 0!==i.calcError?i.calcError:i.error;throw r}}else a=x(o);return a=null!==n.fmt?m(a,n.fmt):null!==a?a.toFixed():null},r.fmt=function(){for(var r=arguments.length,t=new Array(r),e=0;e<r;e++)t[e]=arguments[e];var n=w(t),o=O(n.expr),i=null;if(2<o.length)throw new Error("fmt并非用于计算, 不能传入多个标识:".concat(n.expr));if(1!==o.length)throw new Error("fmt接收了一个无法被解析的标识");if(null!==n.data)if(null===(i=void 0!==n.data._fillData?n.data:i)||void 0===i.fillError&&void 0===i.error)o=_(o,n.data);else try{o=_(o,n.data)}catch(r){if(r instanceof TokensFillError)return i.fillError||i.error;throw r}if(null===n.fmt)throw"表达式没有格式化部分";return m(o[0],n.fmt)},r.version="0.0.36",Object.defineProperty(r,"__esModule",{value:!0}),r}({});
|
package/browser/index.html
CHANGED
|
@@ -9,21 +9,22 @@
|
|
|
9
9
|
<script>
|
|
10
10
|
const {calc, fmt} = a_calc
|
|
11
11
|
|
|
12
|
-
console.log(calc("
|
|
13
|
-
console.log(
|
|
14
|
-
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
console.log(calc("0.
|
|
20
|
-
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
// console.log(calc("1 * 2 / *8 + a9 - 8 % 7",{_fillData:{a9: 10},error:"-"}))
|
|
13
|
+
// console.log(calc("a + b",{a: 1, b: 3}))
|
|
14
|
+
// console.log(fmt("100|=5"))
|
|
15
|
+
// let a = 0.000001
|
|
16
|
+
// let b = 888.789
|
|
17
|
+
// console.log(calc("a + b", {a,b}))
|
|
18
|
+
//
|
|
19
|
+
// console.log(calc("0.1 + 0.2 * 0.3 / 0.4 * (0.5 + 0.6)"))
|
|
20
|
+
// console.log(calc("0.11111 + 0.11111 | <=4"))
|
|
21
|
+
//
|
|
22
|
+
// // console.log(fmt("123"))
|
|
23
|
+
//
|
|
24
|
+
// a = 0.1
|
|
25
|
+
// b = 0.2
|
|
26
|
+
// let c = calc("a + b + 1 |= 2",{a,b})
|
|
27
|
+
// console.log(c)
|
|
27
28
|
</script>
|
|
28
29
|
</body>
|
|
29
30
|
</html>
|
package/browser/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var a_calc=function(n){"use strict";function s(n){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(n)}function k(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")}function U(n,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(n,r.key,r)}}function I(n,e,t){return e&&U(n.prototype,e),t&&U(n,t),Object.defineProperty(n,"prototype",{writable:!1}),n}function L(n,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");n.prototype=Object.create(e&&e.prototype,{constructor:{value:n,writable:!0,configurable:!0}}),Object.defineProperty(n,"prototype",{writable:!1}),e&&o(n,e)}function i(n){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)})(n)}function o(n,e){return(o=Object.setPrototypeOf||function(n,e){return n.__proto__=e,n})(n,e)}function C(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(n){return!1}}function $(n,e,t){return($=C()?Reflect.construct:function(n,e,t){var r=[null];r.push.apply(r,e);e=new(Function.bind.apply(n,r));return t&&o(e,t.prototype),e}).apply(null,arguments)}function e(n){var t="function"==typeof Map?new Map:void 0;return(e=function(n){if(null===n||-1===Function.toString.call(n).indexOf("[native code]"))return n;if("function"!=typeof n)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(n))return t.get(n);t.set(n,e)}function e(){return $(n,arguments,i(this).constructor)}return e.prototype=Object.create(n.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),o(e,n)})(n)}function H(n,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");e=n;if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function B(t){var r=C();return function(){var n,e=i(t);return H(this,r?(n=i(this).constructor,Reflect.construct(e,arguments,n)):e.apply(this,arguments))}}function V(n){return function(n){if(Array.isArray(n))return r(n)}(n)||function(n){if("undefined"!=typeof Symbol&&null!=n[Symbol.iterator]||null!=n["@@iterator"])return Array.from(n)}(n)||function(n,e){if(n){if("string"==typeof n)return r(n,e);var t=Object.prototype.toString.call(n).slice(8,-1);return"Map"===(t="Object"===t&&n.constructor?n.constructor.name:t)||"Set"===t?Array.from(n):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?r(n,e):void 0}}(n)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=n[t];return r}function z(n){return-1<"+-*/%()".indexOf(n)}function W(n){switch(n){case"+":case"-":return 1;case"*":case"/":case"%":return 2;default:return 0}}function J(n){var e={expr:"",fmt:null,data:null},t="",r=n[0];if(1===n.length)"string"==typeof r?t=r:"number"==typeof r?t=r.toString():Array.isArray(r)&&(t=r[0]);else if(1<n.length){r=n[n.length-1];if(u=r,"[object Object]"!==Object.prototype.toString.call(u)||Array.isArray(u))for(var i=V(n.shift());i.length||n.length;)var o=0===i.length?"":i.shift(),s=0===n.length?"":n.shift(),t=t+o+(s="number"==typeof s?s.toString():s);else t=n[0],e.data=r}var u=t.split("|");return 1===u.length?e.expr=u[0]:(e.expr=u[0],""!==(r=u[1]).trim()&&(e.fmt=r)),e}var G,u,c=9e15,p=1e9,g="0123456789abcdef",f="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",a="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",K={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-c,maxE:c,crypto:!1},y=!0,l="[DecimalError] ",m=l+"Invalid argument: ",Q=l+"Precision limit exceeded",X=l+"crypto unavailable",t="[object Decimal]",q=Math.floor,w=Math.pow,Y=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,nn=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,en=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,tn=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,F=1e7,D=7,rn=f.length-1,on=a.length-1,h={toStringTag:t};function b(n){var e,t,r,i=n.length-1,o="",s=n[0];if(0<i){for(o+=s,e=1;e<i;e++)r=n[e]+"",(t=D-r.length)&&(o+=S(t)),o+=r;s=n[e],(t=D-(r=s+"").length)&&(o+=S(t))}else if(0===s)return"0";for(;s%10==0;)s/=10;return o+s}function v(n,e,t){if(n!==~~n||n<e||t<n)throw Error(m+n)}function N(n,e,t,r){for(var i,o,s=n[0];10<=s;s/=10)--e;return--e<0?(e+=D,i=0):(i=Math.ceil((e+1)/D),e%=D),s=w(10,D-e),o=n[i]%s|0,null==r?e<3?(0==e?o=o/100|0:1==e&&(o=o/10|0),t<4&&99999==o||3<t&&49999==o||5e4==o||0==o):(t<4&&o+1==s||3<t&&o+1==s/2)&&(n[i+1]/s/100|0)==w(10,e-2)-1||(o==s/2||0==o)&&0==(n[i+1]/s/100|0):e<4?(0==e?o=o/1e3|0:1==e?o=o/100|0:2==e&&(o=o/10|0),(r||t<4)&&9999==o||!r&&3<t&&4999==o):((r||t<4)&&o+1==s||!r&&3<t&&o+1==s/2)&&(n[i+1]/s/1e3|0)==w(10,e-3)-1}function E(n,e,t){for(var r,i,o=[0],s=0,u=n.length;s<u;){for(i=o.length;i--;)o[i]*=e;for(o[0]+=g.indexOf(n.charAt(s++)),r=0;r<o.length;r++)o[r]>t-1&&(void 0===o[r+1]&&(o[r+1]=0),o[r+1]+=o[r]/t|0,o[r]%=t)}return o.reverse()}h.absoluteValue=h.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),P(n)},h.ceil=function(){return P(new this.constructor(this),this.e+1,2)},h.clampedTo=h.clamp=function(n,e){var t=this.constructor;if(n=new t(n),e=new t(e),!n.s||!e.s)return new t(NaN);if(n.gt(e))throw Error(m+e);return this.cmp(n)<0?n:0<this.cmp(e)?e:new t(this)},h.comparedTo=h.cmp=function(n){var e,t,r=this,i=r.d,o=(n=new r.constructor(n)).d,s=r.s,u=n.s;if(!i||!o)return s&&u?s!==u?s:i===o?0:!i^s<0?1:-1:NaN;if(!i[0]||!o[0])return i[0]?s:o[0]?-u:0;if(s!==u)return s;if(r.e!==n.e)return r.e>n.e^s<0?1:-1;for(e=0,t=(u=i.length)<(r=o.length)?u:r;e<t;++e)if(i[e]!==o[e])return i[e]>o[e]^s<0?1:-1;return u===r?0:r<u^s<0?1:-1},h.cosine=h.cos=function(){var n,e,t=this,r=t.constructor;return t.d?t.d[0]?(n=r.precision,e=r.rounding,r.precision=n+Math.max(t.e,t.sd())+D,r.rounding=1,t=function(n,e){var t,r;if(e.isZero())return e;r=(r=e.d.length)<32?(t=Math.ceil(r/3),(1/T(4,t)).toString()):(t=16,"2.3283064365386962890625e-10");n.precision+=t,e=R(n,1,e.times(r),new n(1));for(var i=t;i--;){var o=e.times(e);e=o.times(o).minus(o).times(8).plus(1)}return n.precision-=t,e}(r,mn(r,t)),r.precision=n,r.rounding=e,P(2==u||3==u?t.neg():t,n,e,!0)):new r(1):new r(NaN)},h.cubeRoot=h.cbrt=function(){var n,e,t,r,i,o,s,u,c,f,a=this,l=a.constructor;if(!a.isFinite()||a.isZero())return new l(a);for(y=!1,(o=a.s*w(a.s*a,1/3))&&Math.abs(o)!=1/0?r=new l(o.toString()):(t=b(a.d),(o=((n=a.e)-t.length+1)%3)&&(t+=1==o||-2==o?"0":"00"),o=w(t,1/3),n=q((n+1)/3)-(n%3==(n<0?-1:2)),(r=new l(t=o==1/0?"5e"+n:(t=o.toExponential()).slice(0,t.indexOf("e")+1)+n)).s=a.s),s=(n=l.precision)+3;;)if(f=(c=(u=r).times(u).times(u)).plus(a),r=x(f.plus(a).times(u),f.plus(c),s+2,1),b(u.d).slice(0,s)===(t=b(r.d)).slice(0,s)){if("9999"!=(t=t.slice(s-3,s+1))&&(i||"4999"!=t)){+t&&(+t.slice(1)||"5"!=t.charAt(0))||(P(r,n+1,1),e=!r.times(r).times(r).eq(a));break}if(!i&&(P(u,n+1,0),u.times(u).times(u).eq(a))){r=u;break}s+=4,i=1}return y=!0,P(r,n,l.rounding,e)},h.decimalPlaces=h.dp=function(){var n,e=this.d,t=NaN;if(e){if(t=((n=e.length-1)-q(this.e/D))*D,n=e[n])for(;n%10==0;n/=10)t--;t<0&&(t=0)}return t},h.dividedBy=h.div=function(n){return x(this,new this.constructor(n))},h.dividedToIntegerBy=h.divToInt=function(n){var e=this.constructor;return P(x(this,new e(n),0,1,1),e.precision,e.rounding)},h.equals=h.eq=function(n){return 0===this.cmp(n)},h.floor=function(){return P(new this.constructor(this),this.e+1,3)},h.greaterThan=h.gt=function(n){return 0<this.cmp(n)},h.greaterThanOrEqualTo=h.gte=function(n){n=this.cmp(n);return 1==n||0===n},h.hyperbolicCosine=h.cosh=function(){var n,e,t,r=(u=this).constructor,i=new r(1);if(!u.isFinite())return new r(u.s?1/0:NaN);if(u.isZero())return i;e=r.precision,t=r.rounding,r.precision=e+Math.max(u.e,u.sd())+4,r.rounding=1;for(var o,s=(s=u.d.length)<32?(1/T(4,n=Math.ceil(s/3))).toString():(n=16,"2.3283064365386962890625e-10"),u=R(r,1,u.times(s),new r(1),!0),c=n,f=new r(8);c--;)o=u.times(u),u=i.minus(o.times(f.minus(o.times(f))));return P(u,r.precision=e,r.rounding=t,!0)},h.hyperbolicSine=h.sinh=function(){var n,e,t,r=(s=this).constructor;if(!s.isFinite()||s.isZero())return new r(s);if(n=r.precision,e=r.rounding,r.precision=n+Math.max(s.e,s.sd())+4,r.rounding=1,(t=s.d.length)<3)s=R(r,2,s,s,!0);else for(var i,o=1.4*Math.sqrt(t),s=R(r,2,s=s.times(1/T(5,o=16<o?16:0|o)),s,!0),u=new r(5),c=new r(16),f=new r(20);o--;)i=s.times(s),s=s.times(u.plus(i.times(c.times(i).plus(f))));return P(s,r.precision=n,r.rounding=e,!0)},h.hyperbolicTangent=h.tanh=function(){var n,e,t=this,r=t.constructor;return t.isFinite()?t.isZero()?new r(t):(n=r.precision,e=r.rounding,r.precision=n+7,r.rounding=1,x(t.sinh(),t.cosh(),r.precision=n,r.rounding=e)):new r(t.s)},h.inverseCosine=h.acos=function(){var n=this,e=n.constructor,t=n.abs().cmp(1),r=e.precision,i=e.rounding;return-1!==t?0===t?n.isNeg()?d(e,r,i):new e(0):new e(NaN):n.isZero()?d(e,r+4,i).times(.5):(e.precision=r+6,e.rounding=1,n=n.asin(),t=d(e,r+4,i).times(.5),e.precision=r,e.rounding=i,t.minus(n))},h.inverseHyperbolicCosine=h.acosh=function(){var n,e,t=this,r=t.constructor;return t.lte(1)?new r(t.eq(1)?0:NaN):t.isFinite()?(n=r.precision,e=r.rounding,r.precision=n+Math.max(Math.abs(t.e),t.sd())+4,r.rounding=1,y=!1,t=t.times(t).minus(1).sqrt().plus(t),y=!0,r.precision=n,r.rounding=e,t.ln()):new r(t)},h.inverseHyperbolicSine=h.asinh=function(){var n,e,t=this,r=t.constructor;return!t.isFinite()||t.isZero()?new r(t):(n=r.precision,e=r.rounding,r.precision=n+2*Math.max(Math.abs(t.e),t.sd())+6,r.rounding=1,y=!1,t=t.times(t).plus(1).sqrt().plus(t),y=!0,r.precision=n,r.rounding=e,t.ln())},h.inverseHyperbolicTangent=h.atanh=function(){var n,e,t,r=this,i=r.constructor;return r.isFinite()?0<=r.e?new i(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(n=i.precision,e=i.rounding,t=r.sd(),Math.max(t,n)<2*-r.e-1?P(new i(r),n,e,!0):(i.precision=t=t-r.e,r=x(r.plus(1),new i(1).minus(r),t+n,1),i.precision=n+4,i.rounding=1,r=r.ln(),i.precision=n,i.rounding=e,r.times(.5))):new i(NaN)},h.inverseSine=h.asin=function(){var n,e,t,r=this,i=r.constructor;return r.isZero()?new i(r):(n=r.abs().cmp(1),e=i.precision,t=i.rounding,-1!==n?0===n?((n=d(i,e+4,t).times(.5)).s=r.s,n):new i(NaN):(i.precision=e+6,i.rounding=1,r=r.div(new i(1).minus(r.times(r)).sqrt().plus(1)).atan(),i.precision=e,i.rounding=t,r.times(2)))},h.inverseTangent=h.atan=function(){var n,e,t,r,i,o,s,u,c,f=this,a=f.constructor,l=a.precision,h=a.rounding;if(f.isFinite()){if(f.isZero())return new a(f);if(f.abs().eq(1)&&l+4<=on)return(s=d(a,l+4,h).times(.25)).s=f.s,s}else{if(!f.s)return new a(NaN);if(l+4<=on)return(s=d(a,l+4,h).times(.5)).s=f.s,s}for(a.precision=u=l+10,a.rounding=1,n=t=Math.min(28,u/D+2|0);n;--n)f=f.div(f.times(f).plus(1).sqrt().plus(1));for(y=!1,e=Math.ceil(u/D),r=1,c=f.times(f),s=new a(f),i=f;-1!==n;)if(i=i.times(c),o=s.minus(i.div(r+=2)),i=i.times(c),void 0!==(s=o.plus(i.div(r+=2))).d[e])for(n=e;s.d[n]===o.d[n]&&n--;);return t&&(s=s.times(2<<t-1)),y=!0,P(s,a.precision=l,a.rounding=h,!0)},h.isFinite=function(){return!!this.d},h.isInteger=h.isInt=function(){return!!this.d&&q(this.e/D)>this.d.length-2},h.isNaN=function(){return!this.s},h.isNegative=h.isNeg=function(){return this.s<0},h.isPositive=h.isPos=function(){return 0<this.s},h.isZero=function(){return!!this.d&&0===this.d[0]},h.lessThan=h.lt=function(n){return this.cmp(n)<0},h.lessThanOrEqualTo=h.lte=function(n){return this.cmp(n)<1},h.logarithm=h.log=function(n){var e,t,r,i,o,s,u,c,f=this,a=f.constructor,l=a.precision,h=a.rounding;if(null==n)n=new a(10),e=!0;else{if(t=(n=new a(n)).d,n.s<0||!t||!t[0]||n.eq(1))return new a(NaN);e=n.eq(10)}if(t=f.d,f.s<0||!t||!t[0]||f.eq(1))return new a(t&&!t[0]?-1/0:1!=f.s?NaN:t?0:1/0);if(e)if(1<t.length)o=!0;else{for(i=t[0];i%10==0;)i/=10;o=1!==i}if(y=!1,s=_(f,u=l+5),r=e?A(a,u+10):_(n,u),N((c=x(s,r,u,1)).d,i=l,h))do{if(s=_(f,u+=10),r=e?A(a,u+10):_(n,u),c=x(s,r,u,1),!o){+b(c.d).slice(i+1,i+15)+1==1e14&&(c=P(c,l+1,0));break}}while(N(c.d,i+=10,h));return y=!0,P(c,l,h)},h.minus=h.sub=function(n){var e,t,r,i,o,s,u,c,f,a,l,h=this,d=h.constructor;if(n=new d(n),!h.d||!n.d)return h.s&&n.s?h.d?n.s=-n.s:n=new d(n.d||h.s!==n.s?h:NaN):n=new d(NaN),n;if(h.s!=n.s)return n.s=-n.s,h.plus(n);if(f=h.d,l=n.d,u=d.precision,c=d.rounding,!f[0]||!l[0]){if(l[0])n.s=-n.s;else{if(!f[0])return new d(3===c?-0:0);n=new d(h)}return y?P(n,u,c):n}if(t=q(n.e/D),h=q(h.e/D),f=f.slice(),o=h-t){for(s=(a=o<0)?(e=f,o=-o,l.length):(e=l,t=h,f.length),(r=Math.max(Math.ceil(u/D),s)+2)<o&&(o=r,e.length=1),e.reverse(),r=o;r--;)e.push(0);e.reverse()}else{for((a=(r=f.length)<(s=l.length))&&(s=r),r=0;r<s;r++)if(f[r]!=l[r]){a=f[r]<l[r];break}o=0}for(a&&(e=f,f=l,l=e,n.s=-n.s),s=f.length,r=l.length-s;0<r;--r)f[s++]=0;for(r=l.length;o<r;){if(f[--r]<l[r]){for(i=r;i&&0===f[--i];)f[i]=F-1;--f[i],f[r]+=F}f[r]-=l[r]}for(;0===f[--s];)f.pop();for(;0===f[0];f.shift())--t;return f[0]?(n.d=f,n.e=M(f,t),y?P(n,u,c):n):new d(3===c?-0:0)},h.modulo=h.mod=function(n){var e,t=this,r=t.constructor;return n=new r(n),!t.d||!n.s||n.d&&!n.d[0]?new r(NaN):!n.d||t.d&&!t.d[0]?P(new r(t),r.precision,r.rounding):(y=!1,9==r.modulo?(e=x(t,n.abs(),0,3,1)).s*=n.s:e=x(t,n,0,r.modulo,1),e=e.times(n),y=!0,t.minus(e))},h.naturalExponential=h.exp=function(){return dn(this)},h.naturalLogarithm=h.ln=function(){return _(this)},h.negated=h.neg=function(){var n=new this.constructor(this);return n.s=-n.s,P(n)},h.plus=h.add=function(n){var e,t,r,i,o,s,u,c,f=this,a=f.constructor;if(n=new a(n),!f.d||!n.d)return f.s&&n.s?f.d||(n=new a(n.d||f.s===n.s?f:NaN)):n=new a(NaN),n;if(f.s!=n.s)return n.s=-n.s,f.minus(n);if(u=f.d,c=n.d,o=a.precision,s=a.rounding,!u[0]||!c[0])return c[0]||(n=new a(f)),y?P(n,o,s):n;if(a=q(f.e/D),f=q(n.e/D),u=u.slice(),r=a-f){for((i=(i=r<0?(t=u,r=-r,c.length):(t=c,f=a,u.length))<(a=Math.ceil(o/D))?a+1:i+1)<r&&(r=i,t.length=1),t.reverse();r--;)t.push(0);t.reverse()}for((i=u.length)-(r=c.length)<0&&(r=i,t=c,c=u,u=t),e=0;r;)e=(u[--r]=u[r]+c[r]+e)/F|0,u[r]%=F;for(e&&(u.unshift(e),++f),i=u.length;0==u[--i];)u.pop();return n.d=u,n.e=M(u,f),y?P(n,o,s):n},h.precision=h.sd=function(n){var e;if(void 0!==n&&n!==!!n&&1!==n&&0!==n)throw Error(m+n);return this.d?(e=fn(this.d),n&&this.e+1>e&&(e=this.e+1)):e=NaN,e},h.round=function(){var n=this.constructor;return P(new n(this),this.e+1,n.rounding)},h.sine=h.sin=function(){var n,e,t=this,r=t.constructor;return t.isFinite()?t.isZero()?new r(t):(n=r.precision,e=r.rounding,r.precision=n+Math.max(t.e,t.sd())+D,r.rounding=1,t=function(n,e){var t,r=e.d.length;if(r<3)return e.isZero()?e:R(n,2,e,e);t=16<(t=1.4*Math.sqrt(r))?16:0|t,e=e.times(1/T(5,t)),e=R(n,2,e,e);for(var i,o=new n(5),s=new n(16),u=new n(20);t--;)i=e.times(e),e=e.times(o.plus(i.times(s.times(i).minus(u))));return e}(r,mn(r,t)),r.precision=n,r.rounding=e,P(2<u?t.neg():t,n,e,!0)):new r(NaN)},h.squareRoot=h.sqrt=function(){var n,e,t,r,i,o,s=this,u=s.d,c=s.e,f=s.s,a=s.constructor;if(1!==f||!u||!u[0])return new a(!f||f<0&&(!u||u[0])?NaN:u?s:1/0);for(y=!1,r=0==(f=Math.sqrt(+s))||f==1/0?(((e=b(u)).length+c)%2==0&&(e+="0"),f=Math.sqrt(e),c=q((c+1)/2)-(c<0||c%2),new a(e=f==1/0?"5e"+c:(e=f.toExponential()).slice(0,e.indexOf("e")+1)+c)):new a(f.toString()),t=(c=a.precision)+3;;)if(r=(o=r).plus(x(s,o,t+2,1)).times(.5),b(o.d).slice(0,t)===(e=b(r.d)).slice(0,t)){if("9999"!=(e=e.slice(t-3,t+1))&&(i||"4999"!=e)){+e&&(+e.slice(1)||"5"!=e.charAt(0))||(P(r,c+1,1),n=!r.times(r).eq(s));break}if(!i&&(P(o,c+1,0),o.times(o).eq(s))){r=o;break}t+=4,i=1}return y=!0,P(r,c,a.rounding,n)},h.tangent=h.tan=function(){var n,e,t=this,r=t.constructor;return t.isFinite()?t.isZero()?new r(t):(n=r.precision,e=r.rounding,r.precision=n+10,r.rounding=1,(t=t.sin()).s=1,t=x(t,new r(1).minus(t.times(t)).sqrt(),n+10,0),r.precision=n,r.rounding=e,P(2==u||4==u?t.neg():t,n,e,!0)):new r(NaN)},h.times=h.mul=function(n){var e,t,r,i,o,s,u,c,f,a=this.constructor,l=this.d,h=(n=new a(n)).d;if(n.s*=this.s,!(l&&l[0]&&h&&h[0]))return new a(!n.s||l&&!l[0]&&!h||h&&!h[0]&&!l?NaN:l&&h?0*n.s:n.s/0);for(t=q(this.e/D)+q(n.e/D),(c=l.length)<(f=h.length)&&(o=l,l=h,h=o,s=c,c=f,f=s),o=[],r=s=c+f;r--;)o.push(0);for(r=f;0<=--r;){for(e=0,i=c+r;r<i;)u=o[i]+h[r]*l[i-r-1]+e,o[i--]=u%F|0,e=u/F|0;o[i]=(o[i]+e)%F|0}for(;!o[--s];)o.pop();return e?++t:o.shift(),n.d=o,n.e=M(o,t),y?P(n,a.precision,a.rounding):n},h.toBinary=function(n,e){return wn(this,2,n,e)},h.toDecimalPlaces=h.toDP=function(n,e){var t=this.constructor,r=new t(this);return void 0===n?r:(v(n,0,p),void 0===e?e=t.rounding:v(e,0,8),P(r,n+r.e+1,e))},h.toExponential=function(n,e){var t=this,r=t.constructor,r=void 0===n?O(t,!0):(v(n,0,p),void 0===e?e=r.rounding:v(e,0,8),O(t=P(new r(t),n+1,e),!0,n+1));return t.isNeg()&&!t.isZero()?"-"+r:r},h.toFixed=function(n,e){var t=this,r=t.constructor,e=void 0===n?O(t):(v(n,0,p),void 0===e?e=r.rounding:v(e,0,8),O(r=P(new r(t),n+t.e+1,e),!1,n+r.e+1));return t.isNeg()&&!t.isZero()?"-"+e:e},h.toFraction=function(n){var e,t,r,i,o,s,u,c,f,a,l=this,h=l.d,d=l.constructor;if(!h)return new d(l);if(c=t=new d(1),r=u=new d(0),o=(e=new d(r)).e=fn(h)-l.e-1,e.d[0]=w(10,(f=o%D)<0?D+f:f),null==n)n=0<o?e:c;else{if(!(s=new d(n)).isInt()||s.lt(c))throw Error(m+s);n=s.gt(e)?0<o?e:c:s}for(y=!1,s=new d(b(h)),f=d.precision,d.precision=o=h.length*D*2;a=x(s,e,0,1,1),1!=(i=t.plus(a.times(r))).cmp(n);)t=r,r=i,i=c,c=u.plus(a.times(i)),u=i,i=e,e=s.minus(a.times(i)),s=i;return i=x(n.minus(t),r,0,1,1),u=u.plus(i.times(c)),t=t.plus(i.times(r)),u.s=c.s=l.s,h=x(c,r,o,1).minus(l).abs().cmp(x(u,t,o,1).minus(l).abs())<1?[c,r]:[u,t],d.precision=f,y=!0,h},h.toHexadecimal=h.toHex=function(n,e){return wn(this,16,n,e)},h.toNearest=function(n,e){var t=(r=this).constructor,r=new t(r);if(null==n){if(!r.d)return r;n=new t(1),e=t.rounding}else{if(n=new t(n),void 0===e?e=t.rounding:v(e,0,8),!r.d)return n.s?r:n;if(!n.d)return n.s&&(n.s=r.s),n}return n.d[0]?(y=!1,r=x(r,n,0,e,1).times(n),y=!0,P(r)):(n.s=r.s,r=n),r},h.toNumber=function(){return+this},h.toOctal=function(n,e){return wn(this,8,n,e)},h.toPower=h.pow=function(n){var e,t,r,i,o,s,u=this,c=u.constructor,f=+(n=new c(n));if(!(u.d&&n.d&&u.d[0]&&n.d[0]))return new c(w(+u,f));if((u=new c(u)).eq(1))return u;if(r=c.precision,o=c.rounding,n.eq(1))return P(u,r,o);if((e=q(n.e/D))>=n.d.length-1&&(t=f<0?-f:f)<=9007199254740991)return i=an(c,u,t,r),n.s<0?new c(1).div(i):P(i,r,o);if((s=u.s)<0){if(e<n.d.length-1)return new c(NaN);if(0==(1&n.d[e])&&(s=1),0==u.e&&1==u.d[0]&&1==u.d.length)return u.s=s,u}return(e=0!=(t=w(+u,f))&&isFinite(t)?new c(t+"").e:q(f*(Math.log("0."+b(u.d))/Math.LN10+u.e+1)))>c.maxE+1||e<c.minE-1?new c(0<e?s/0:0):(y=!1,c.rounding=u.s=1,t=Math.min(12,(e+"").length),(i=(i=dn(n.times(_(u,r+t)),r)).d&&N((i=P(i,r+5,1)).d,r,o)&&+b((i=P(dn(n.times(_(u,(e=r+10)+t)),e),e+5,1)).d).slice(r+1,r+15)+1==1e14?P(i,r+1,0):i).s=s,y=!0,P(i,r,c.rounding=o))},h.toPrecision=function(n,e){var t=this,r=t.constructor,e=void 0===n?O(t,t.e<=r.toExpNeg||t.e>=r.toExpPos):(v(n,1,p),void 0===e?e=r.rounding:v(e,0,8),O(t=P(new r(t),n,e),n<=t.e||t.e<=r.toExpNeg,n));return t.isNeg()&&!t.isZero()?"-"+e:e},h.toSignificantDigits=h.toSD=function(n,e){var t=this.constructor;return void 0===n?(n=t.precision,e=t.rounding):(v(n,1,p),void 0===e?e=t.rounding:v(e,0,8)),P(new t(this),n,e)},h.toString=function(){var n=this,e=n.constructor,e=O(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()&&!n.isZero()?"-"+e:e},h.truncated=h.trunc=function(){return P(new this.constructor(this),this.e+1,1)},h.valueOf=h.toJSON=function(){var n=this,e=n.constructor,e=O(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()?"-"+e:e};var x=function(n,e,t,r,i,o){var s,u,c,f,a,l,h,d,p,g,m,w,v,y,b,N,E,x,O,M=n.constructor,A=n.s==e.s?1:-1,S=n.d,_=e.d;if(!(S&&S[0]&&_&&_[0]))return new M(n.s&&e.s&&(S?!_||S[0]!=_[0]:_)?S&&0==S[0]||!_?0*A:A/0:NaN);for(u=o?(a=1,n.e-e.e):(o=F,q(n.e/(a=D))-q(e.e/a)),x=_.length,N=S.length,p=(A=new M(A)).d=[],c=0;_[c]==(S[c]||0);c++);if(_[c]>(S[c]||0)&&u--,null==t?(v=t=M.precision,r=M.rounding):v=i?t+(n.e-e.e)+1:t,v<0)p.push(1),l=!0;else{if(v=v/a+2|0,c=0,1==x){for(_=_[f=0],v++;(c<N||f)&&v--;c++)y=f*o+(S[c]||0),p[c]=y/_|0,f=y%_|0;l=f||c<N}else{for(1<(f=o/(_[0]+1)|0)&&(_=sn(_,f,o),S=sn(S,f,o),x=_.length,N=S.length),b=x,m=(g=S.slice(0,x)).length;m<x;)g[m++]=0;for((O=_.slice()).unshift(0),E=_[0],_[1]>=o/2&&++E;f=0,(s=un(_,g,x,m))<0?(w=g[0],1<(f=(w=x!=m?w*o+(g[1]||0):w)/E|0)?1==(s=un(h=sn(_,f=o<=f?o-1:f,o),g,d=h.length,m=g.length))&&(f--,cn(h,x<d?O:_,d,o)):(0==f&&(s=f=1),h=_.slice()),(d=h.length)<m&&h.unshift(0),cn(g,h,m,o),-1==s&&(s=un(_,g,x,m=g.length))<1&&(f++,cn(g,x<m?O:_,m,o)),m=g.length):0===s&&(f++,g=[0]),p[c++]=f,s&&g[0]?g[m++]=S[b]||0:(g=[S[b]],m=1),(b++<N||void 0!==g[0])&&v--;);l=void 0!==g[0]}p[0]||p.shift()}if(1==a)A.e=u,G=l;else{for(c=1,f=p[0];10<=f;f/=10)c++;A.e=c+u*a-1,P(A,i?t+A.e+1:t,r,l)}return A};function sn(n,e,t){var r,i=0,o=n.length;for(n=n.slice();o--;)r=n[o]*e+i,n[o]=r%t|0,i=r/t|0;return i&&n.unshift(i),n}function un(n,e,t,r){var i,o;if(t!=r)o=r<t?1:-1;else for(i=o=0;i<t;i++)if(n[i]!=e[i]){o=n[i]>e[i]?1:-1;break}return o}function cn(n,e,t,r){for(var i=0;t--;)n[t]-=i,i=n[t]<e[t]?1:0,n[t]=i*r+n[t]-e[t];for(;!n[0]&&1<n.length;)n.shift()}function P(n,e,t,r){var i,o,s,u,c,f,a,l,h=n.constructor;n:if(null!=e){if(!(a=n.d))return n;for(i=1,u=a[0];10<=u;u/=10)i++;if((o=e-i)<0)o+=D,s=e,c=(f=a[l=0])/w(10,i-s-1)%10|0;else if(l=Math.ceil((o+1)/D),(u=a.length)<=l){if(!r)break n;for(;u++<=l;)a.push(0);f=c=0,s=(o%=D)-D+(i=1)}else{for(f=u=a[l],i=1;10<=u;u/=10)i++;c=(s=(o%=D)-D+i)<0?0:f/w(10,i-s-1)%10|0}if(r=r||e<0||void 0!==a[l+1]||(s<0?f:f%w(10,i-s-1)),c=t<4?(c||r)&&(0==t||t==(n.s<0?3:2)):5<c||5==c&&(4==t||r||6==t&&(0<o?0<s?f/w(10,i-s):0:a[l-1])%10&1||t==(n.s<0?8:7)),e<1||!a[0])return a.length=0,c?(e-=n.e+1,a[0]=w(10,(D-e%D)%D),n.e=-e||0):a[0]=n.e=0,n;if(0==o?(a.length=l,u=1,l--):(a.length=l+1,u=w(10,D-o),a[l]=0<s?(f/w(10,i-s)%w(10,s)|0)*u:0),c)for(;;){if(0==l){for(o=1,s=a[0];10<=s;s/=10)o++;for(s=a[0]+=u,u=1;10<=s;s/=10)u++;o!=u&&(n.e++,a[0]==F&&(a[0]=1));break}if(a[l]+=u,a[l]!=F)break;a[l--]=0,u=1}for(o=a.length;0===a[--o];)a.pop()}return y&&(n.e>h.maxE?(n.d=null,n.e=NaN):n.e<h.minE&&(n.e=0,n.d=[0])),n}function O(n,e,t){if(!n.isFinite())return pn(n);var r,i=n.e,o=b(n.d),s=o.length;return e?(t&&0<(r=t-s)?o=o.charAt(0)+"."+o.slice(1)+S(r):1<s&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(n.e<0?"e":"e+")+n.e):i<0?(o="0."+S(-i-1)+o,t&&0<(r=t-s)&&(o+=S(r))):s<=i?(o+=S(i+1-s),t&&0<(r=t-i-1)&&(o=o+"."+S(r))):((r=i+1)<s&&(o=o.slice(0,r)+"."+o.slice(r)),t&&0<(r=t-s)&&(i+1===s&&(o+="."),o+=S(r))),o}function M(n,e){var t=n[0];for(e*=D;10<=t;t/=10)e++;return e}function A(n,e,t){if(rn<e)throw y=!0,t&&(n.precision=t),Error(Q);return P(new n(f),e,1,!0)}function d(n,e,t){if(on<e)throw Error(Q);return P(new n(a),e,t,!0)}function fn(n){var e=n.length-1,t=e*D+1;if(e=n[e]){for(;e%10==0;e/=10)t--;for(e=n[0];10<=e;e/=10)t++}return t}function S(n){for(var e="";n--;)e+="0";return e}function an(n,e,t,r){var i,o=new n(1),s=Math.ceil(r/D+4);for(y=!1;;){if(t%2&&vn((o=o.times(e)).d,s)&&(i=!0),0===(t=q(t/2))){t=o.d.length-1,i&&0===o.d[t]&&++o.d[t];break}vn((e=e.times(e)).d,s)}return y=!0,o}function ln(n){return 1&n.d[n.d.length-1]}function hn(n,e,t){for(var r,i=new n(e[0]),o=0;++o<e.length;){if(!(r=new n(e[o])).s){i=r;break}i[t](r)&&(i=r)}return i}function dn(n,e){var t,r,i,o,s,u,c,f=0,a=0,l=0,h=n.constructor,d=h.rounding,p=h.precision;if(!n.d||!n.d[0]||17<n.e)return new h(n.d?n.d[0]?n.s<0?0:1/0:1:n.s?n.s<0?0:n:NaN);for(c=null==e?(y=!1,p):e,u=new h(.03125);-2<n.e;)n=n.times(u),l+=5;for(c+=r=Math.log(w(2,l))/Math.LN10*2+5|0,t=o=s=new h(1),h.precision=c;;){if(o=P(o.times(n),c,1),t=t.times(++a),b((u=s.plus(x(o,t,c,1))).d).slice(0,c)===b(s.d).slice(0,c)){for(i=l;i--;)s=P(s.times(s),c,1);if(null!=e)return h.precision=p,s;if(!(f<3&&N(s.d,c-r,d,f)))return P(s,h.precision=p,d,y=!0);h.precision=c+=10,t=o=u=new h(1),a=0,f++}s=u}}function _(n,e){var t,r,i,o,s,u,c,f,a,l,h,d=1,p=n,g=p.d,m=p.constructor,w=m.rounding,v=m.precision;if(p.s<0||!g||!g[0]||!p.e&&1==g[0]&&1==g.length)return new m(g&&!g[0]?-1/0:1!=p.s?NaN:g?0:p);if(a=null==e?(y=!1,v):e,m.precision=a+=10,r=(t=b(g)).charAt(0),!(Math.abs(o=p.e)<15e14))return f=A(m,a+2,v).times(o+""),p=_(new m(r+"."+t.slice(1)),a-10).plus(f),m.precision=v,null==e?P(p,v,w,y=!0):p;for(;r<7&&1!=r||1==r&&3<t.charAt(1);)r=(t=b((p=p.times(n)).d)).charAt(0),d++;for(o=p.e,1<r?(p=new m("0."+t),o++):p=new m(r+"."+t.slice(1)),c=s=p=x((l=p).minus(1),p.plus(1),a,1),h=P(p.times(p),a,1),i=3;;){if(s=P(s.times(h),a,1),b((f=c.plus(x(s,new m(i),a,1))).d).slice(0,a)===b(c.d).slice(0,a)){if(c=c.times(2),0!==o&&(c=c.plus(A(m,a+2,v).times(o+""))),c=x(c,new m(d),a,1),null!=e)return m.precision=v,c;if(!N(c.d,a-10,w,u))return P(c,m.precision=v,w,y=!0);m.precision=a+=10,f=s=p=x(l.minus(1),l.plus(1),a,1),h=P(p.times(p),a,1),i=u=1}c=f,i+=2}}function pn(n){return String(n.s*n.s/0)}function gn(n,e){var t,r,i;for(0<(r=(e=-1<(t=e.indexOf("."))?e.replace(".",""):e).search(/e/i))?(t<0&&(t=r),t+=+e.slice(r+1),e=e.substring(0,r)):t<0&&(t=e.length),r=0;48===e.charCodeAt(r);r++);for(i=e.length;48===e.charCodeAt(i-1);--i);if(e=e.slice(r,i)){if(i-=r,n.e=t=t-r-1,n.d=[],r=(t+1)%D,t<0&&(r+=D),r<i){for(r&&n.d.push(+e.slice(0,r)),i-=D;r<i;)n.d.push(+e.slice(r,r+=D));e=e.slice(r),r=D-e.length}else r-=i;for(;r--;)e+="0";n.d.push(+e),y&&(n.e>n.constructor.maxE?(n.d=null,n.e=NaN):n.e<n.constructor.minE&&(n.e=0,n.d=[0]))}else n.e=0,n.d=[0];return n}function R(n,e,t,r,i){var o,s,u,c,f=n.precision,a=Math.ceil(f/D);for(y=!1,c=t.times(t),u=new n(r);;){if(s=x(u.times(c),new n(e++*e++),f,1),u=i?r.plus(s):r.minus(s),r=x(s.times(c),new n(e++*e++),f,1),void 0!==(s=u.plus(r)).d[a]){for(o=a;s.d[o]===u.d[o]&&o--;);if(-1==o)break}o=u,u=r,r=s,s=o}return y=!0,s.d.length=a+1,s}function T(n,e){for(var t=n;--e;)t*=n;return t}function mn(n,e){var t,r=e.s<0,n=d(n,n.precision,1),i=n.times(.5);if((e=e.abs()).lte(i))return u=r?4:1,e;if((t=e.divToInt(n)).isZero())u=r?3:2;else{if((e=e.minus(t.times(n))).lte(i))return u=ln(t)?r?2:3:r?4:1,e;u=ln(t)?r?1:4:r?3:2}return e.minus(n).abs()}function wn(n,e,t,r){var i,o,s,u,c,f,a,l,h=n.constructor,d=void 0!==t;if(d?(v(t,1,p),void 0===r?r=h.rounding:v(r,0,8)):(t=h.precision,r=h.rounding),n.isFinite()){for(d?(i=2,16==e?t=4*t-3:8==e&&(t=3*t-2)):i=e,0<=(s=(f=O(n)).indexOf("."))&&(f=f.replace(".",""),(l=new h(1)).e=f.length-s,l.d=E(O(l),10,i),l.e=l.d.length),o=u=(a=E(f,10,i)).length;0==a[--u];)a.pop();if(a[0]){if(s<0?o--:((n=new h(n)).d=a,n.e=o,a=(n=x(n,l,t,r,0,i)).d,o=n.e,c=G),s=a[t],h=i/2,c=c||void 0!==a[t+1],c=r<4?(void 0!==s||c)&&(0===r||r===(n.s<0?3:2)):h<s||s===h&&(4===r||c||6===r&&1&a[t-1]||r===(n.s<0?8:7)),a.length=t,c)for(;++a[--t]>i-1;)a[t]=0,t||(++o,a.unshift(1));for(u=a.length;!a[u-1];--u);for(s=0,f="";s<u;s++)f+=g.charAt(a[s]);if(d){if(1<u)if(16==e||8==e){for(s=16==e?4:3,--u;u%s;u++)f+="0";for(u=(a=E(f,i,e)).length;!a[u-1];--u);for(s=1,f="1.";s<u;s++)f+=g.charAt(a[s])}else f=f.charAt(0)+"."+f.slice(1);f=f+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)f="0"+f;f="0."+f}else if(++o>u)for(o-=u;o--;)f+="0";else o<u&&(f=f.slice(0,o)+"."+f.slice(o))}else f=d?"0p+0":"0";f=(16==e?"0x":2==e?"0b":8==e?"0o":"")+f}else f=pn(n);return n.s<0?"-"+f:f}function vn(n,e){return n.length>e&&(n.length=e,1)}function yn(n){return new this(n).abs()}function bn(n){return new this(n).acos()}function Nn(n){return new this(n).acosh()}function En(n,e){return new this(n).plus(e)}function xn(n){return new this(n).asin()}function On(n){return new this(n).asinh()}function Mn(n){return new this(n).atan()}function An(n){return new this(n).atanh()}function Sn(n,e){n=new this(n),e=new this(e);var t,r=this.precision,i=this.rounding,o=r+4;return n.s&&e.s?n.d||e.d?!e.d||n.isZero()?(t=e.s<0?d(this,r,i):new this(0)).s=n.s:!n.d||e.isZero()?(t=d(this,o,1).times(.5)).s=n.s:t=e.s<0?(this.precision=o,this.rounding=1,t=this.atan(x(n,e,o,1)),e=d(this,o,1),this.precision=r,this.rounding=i,n.s<0?t.minus(e):t.plus(e)):this.atan(x(n,e,o,1)):(t=d(this,o,1).times(0<e.s?.25:.75)).s=n.s:t=new this(NaN),t}function _n(n){return new this(n).cbrt()}function qn(n){return P(n=new this(n),n.e+1,2)}function Fn(n,e,t){return new this(n).clamp(e,t)}function Dn(n){if(!n||"object"!==s(n))throw Error(l+"Object expected");for(var e,t,r=!0===n.defaults,i=["precision",1,p,"rounding",0,8,"toExpNeg",-c,0,"toExpPos",0,c,"maxE",0,c,"minE",-c,0,"modulo",0,9],o=0;o<i.length;o+=3)if(e=i[o],r&&(this[e]=K[e]),void 0!==(t=n[e])){if(!(q(t)===t&&i[o+1]<=t&&t<=i[o+2]))throw Error(m+e+": "+t);this[e]=t}if(e="crypto",r&&(this[e]=K[e]),void 0!==(t=n[e])){if(!0!==t&&!1!==t&&0!==t&&1!==t)throw Error(m+e+": "+t);if(t){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw Error(X);this[e]=!0}else this[e]=!1}return this}function Pn(n){return new this(n).cos()}function Rn(n){return new this(n).cosh()}function Tn(n,e){return new this(n).div(e)}function Zn(n){return new this(n).exp()}function jn(n){return P(n=new this(n),n.e+1,3)}function kn(){var n,e,t=new this(0);for(y=!1,n=0;n<arguments.length;)if((e=new this(arguments[n++])).d)t.d&&(t=t.plus(e.times(e)));else{if(e.s)return y=!0,new this(1/0);t=e}return y=!0,t.sqrt()}function Un(n){return n instanceof Z||n&&n.toStringTag===t||!1}function In(n){return new this(n).ln()}function Ln(n,e){return new this(n).log(e)}function Cn(n){return new this(n).log(2)}function $n(n){return new this(n).log(10)}function Hn(){return hn(this,arguments,"lt")}function Bn(){return hn(this,arguments,"gt")}function Vn(n,e){return new this(n).mod(e)}function zn(n,e){return new this(n).mul(e)}function Wn(n,e){return new this(n).pow(e)}function Jn(n){var e,t,r,i,o=0,s=new this(1),u=[];if(void 0===n?n=this.precision:v(n,1,p),r=Math.ceil(n/D),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(r));o<r;)429e7<=(i=e[o])?e[o]=crypto.getRandomValues(new Uint32Array(1))[0]:u[o++]=i%1e7;else{if(!crypto.randomBytes)throw Error(X);for(e=crypto.randomBytes(r*=4);o<r;)214e7<=(i=e[o]+(e[o+1]<<8)+(e[o+2]<<16)+((127&e[o+3])<<24))?crypto.randomBytes(4).copy(e,o):(u.push(i%1e7),o+=4);o=r/4}else for(;o<r;)u[o++]=1e7*Math.random()|0;for(r=u[--o],n%=D,r&&n&&(i=w(10,D-n),u[o]=(r/i|0)*i);0===u[o];o--)u.pop();if(o<0)u=[t=0];else{for(t=-1;0===u[0];t-=D)u.shift();for(r=1,i=u[0];10<=i;i/=10)r++;r<D&&(t-=D-r)}return s.e=t,s.d=u,s}function Gn(n){return P(n=new this(n),n.e+1,this.rounding)}function Kn(n){return(n=new this(n)).d?n.d[0]?n.s:0*n.s:n.s||NaN}function Qn(n){return new this(n).sin()}function Xn(n){return new this(n).sinh()}function Yn(n){return new this(n).sqrt()}function ne(n,e){return new this(n).sub(e)}function ee(){var n=0,e=arguments,t=new this(e[n]);for(y=!1;t.s&&++n<e.length;)t=t.plus(e[n]);return y=!0,P(t,this.precision,this.rounding)}function te(n){return new this(n).tan()}function re(n){return new this(n).tanh()}function ie(n){return P(n=new this(n),n.e+1,1)}h[Symbol.for("nodejs.util.inspect.custom")]=h.toString,h[Symbol.toStringTag]="Decimal";var Z=h.constructor=function n(e){var t,r,i;function o(n){var e,t,r,i=this;if(!(i instanceof o))return new o(n);if(i.constructor=o,Un(n))return i.s=n.s,void(y?!n.d||n.e>o.maxE?(i.e=NaN,i.d=null):n.e<o.minE?(i.e=0,i.d=[0]):(i.e=n.e,i.d=n.d.slice()):(i.e=n.e,i.d=n.d&&n.d.slice()));if("number"===(r=s(n))){if(0===n)return i.s=1/n<0?-1:1,i.e=0,void(i.d=[0]);if(n<0?(n=-n,i.s=-1):i.s=1,n===~~n&&n<1e7){for(e=0,t=n;10<=t;t/=10)e++;return void(y?o.maxE<e?(i.e=NaN,i.d=null):e<o.minE?(i.e=0,i.d=[0]):(i.e=e,i.d=[n]):(i.e=e,i.d=[n]))}return 0*n!=0?(n||(i.s=NaN),i.e=NaN,void(i.d=null)):gn(i,n.toString())}if("string"!==r)throw Error(m+n);return 45===(t=n.charCodeAt(0))?(n=n.slice(1),i.s=-1):(43===t&&(n=n.slice(1)),i.s=1),(tn.test(n)?gn:function(n,e){var t,r,i,o,s,u,c,f;if(-1<e.indexOf("_")){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),tn.test(e))return gn(n,e)}else if("Infinity"===e||"NaN"===e)return+e||(n.s=NaN),n.e=NaN,n.d=null,n;if(nn.test(e))t=16,e=e.toLowerCase();else if(Y.test(e))t=2;else{if(!en.test(e))throw Error(m+e);t=8}for(o=(e=0<(o=e.search(/p/i))?(c=+e.slice(o+1),e.substring(2,o)):e.slice(2)).indexOf("."),r=n.constructor,(s=0<=o)&&(o=(u=(e=e.replace(".","")).length)-o,i=an(r,new r(t),o,2*o)),o=e=(f=E(e,t,F)).length-1;0===f[o];--o)f.pop();return o<0?new r(0*n.s):(n.e=M(f,e),n.d=f,y=!1,s&&(n=x(n,i,4*u)),c&&(n=n.times(Math.abs(c)<54?w(2,c):Z.pow(2,c))),y=!0,n)})(i,n)}if(o.prototype=h,o.ROUND_UP=0,o.ROUND_DOWN=1,o.ROUND_CEIL=2,o.ROUND_FLOOR=3,o.ROUND_HALF_UP=4,o.ROUND_HALF_DOWN=5,o.ROUND_HALF_EVEN=6,o.ROUND_HALF_CEIL=7,o.ROUND_HALF_FLOOR=8,o.EUCLID=9,o.config=o.set=Dn,o.clone=n,o.isDecimal=Un,o.abs=yn,o.acos=bn,o.acosh=Nn,o.add=En,o.asin=xn,o.asinh=On,o.atan=Mn,o.atanh=An,o.atan2=Sn,o.cbrt=_n,o.ceil=qn,o.clamp=Fn,o.cos=Pn,o.cosh=Rn,o.div=Tn,o.exp=Zn,o.floor=jn,o.hypot=kn,o.ln=In,o.log=Ln,o.log10=$n,o.log2=Cn,o.max=Hn,o.min=Bn,o.mod=Vn,o.mul=zn,o.pow=Wn,o.random=Jn,o.round=Gn,o.sign=Kn,o.sin=Qn,o.sinh=Xn,o.sqrt=Yn,o.sub=ne,o.sum=ee,o.tan=te,o.tanh=re,o.trunc=ie,(e=void 0===e?{}:e)&&!0!==e.defaults)for(i=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<i.length;)e.hasOwnProperty(r=i[t++])||(e[r]=this[r]);return o.config(e),o}(K);function oe(n,e){var t="",r=(t=Z.isDecimal(n)?n.toFixed():"string"!=typeof n?n.toString():n,null),n=null,i=null,o=e.match(/(<=|>=|=)\s*(\d+)/);if(o&&(n=o[1],r=Number(o[2])),e.includes(",")&&(i=!0),null!==r){var o=t.split("."),e=o[0],s=1===o.length?"":o[1],u=s.length;switch(n){case"<=":s=u<=r?s:s.slice(0,r);break;case"=":u<r?s+="0".repeat(r-u):r<u&&(s=s.slice(0,r));break;case">=":s=r<=u?s:s+"0".repeat(r-u)}t=""===s?e:"".concat(e,".").concat(s)}return t=null!==i?1<(o=t.split(".")).length?((n=o[0]).includes("-")?o[0]=n[0]+n.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):o[0]=n.replace(/(?=(?!^)(?:\d{3})+$)/g,","),o.join(".")):(e=o[0]).includes("-")?e[0]+e.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):e.replace(/(?=(?!^)(?:\d{3})+$)/g,","):t}function se(n){for(var e=[],t=0,r=null,i=n.length;t<i;)if(r=n[t],/\s/.test(r))t++;else if("+-".includes(r)){var o=e[e.length-1];if(0===e.length||"+-".includes(o)||"("===o){for(var s=r,r=n[++t];/[a-zA-Z\d._]/.test(r);)s+=r,r=n[++t];e.push(s)}else e.push(r),t++}else if("*/%()".includes(r))e.push(r),t++;else if(/[a-zA-Z_]/.test(r)){for(var u="";/[a-zA-Z0-9_]/.test(r)&&(u+=r,!(++t>=i));)r=n[t];e.push(u)}else if(/\d/.test(r)){for(var c="";/[\d.]/.test(r)&&(c+=r,!(++t>=i));)r=n[t];e.push(c)}return e}var f=new Z(f),a=new Z(a),ue=function(){L(r,e(Error));var t=B(r);function r(n){var e;return k(this,r),(e=t.call(this,n)).name="CalculatorError",e.message=n,e}return I(r)}(),ce=function(){L(r,e(Error));var t=B(r);function r(n){var e;return k(this,r),(e=t.call(this,n)).name="TokensFillError",e.message=n,e}return I(r)}();function j(n,e){var t=e._fillData;return void 0===e._fillData&&(t=e),n.map(function(n){if(/^[a-zA-z_][\w_]*$/.test(n)){var e=t[n];if(void 0!==e)return"number"==typeof e?e.toString():e;throw new ce("错误的参数:".concat(n," 请确认他存在"))}return n})}function fe(n){for(var e,t=[],r=[],i=n;0<i.length;){var o=i.shift();if(z(o))if("("===o)t.push(o);else if(")"===o){for(var s=t.pop();"("!==s&&0<t.length;)r.push(s),s=t.pop();if("("!==s)throw"error: unmatched ()"}else{for(;e=t[t.length-1],W(o)<=W(e)&&0<t.length;)r.push(t.pop());t.push(o)}else r.push(o)}if(0<t.length){if(")"===t[t.length-1]||"("===t[t.length-1])throw"error: unmatched ()";for(;0<t.length;)r.push(t.pop())}return r}function ae(n){for(var e=[];0<n.length;){var t=n.shift();if(z(t)){if(e.length<2)throw new ue("错误的栈长度, 可能是无法计算的表达式");var r=e.pop(),i=e.pop();switch("string"==typeof r&&(r=new Z(r)),"string"==typeof i&&(i=new Z(i)),t){case"+":e.push(i.add(r));break;case"-":e.push(i.sub(r));break;case"*":e.push(i.mul(r));break;case"/":e.push(i.div(r));break;case"%":e.push(i.mod(r))}}else e.push(t)}if(1!==e.length)throw"unvalid expression";return e[0]}return n.calc=function(){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];var r=J(e),i=se(r.expr),o=null;if(null!==r.data)if(null===(o=void 0!==r.data._fillData?r.data:o)||void 0===o.fillError&&void 0===o.error)i=j(i,r.data);else try{i=j(i,r.data)}catch(n){if(n instanceof ce)return o.fillError||o.error;throw n}var i=fe(i),s=null;if(null!==o){if(void 0!==o.calcError||void 0!==o.error)try{s=ae(i)}catch(n){if(n instanceof ue)return void 0!==o.calcError?o.calcError:o.error;throw n}}else s=ae(i);return s=null!==r.fmt?oe(s,r.fmt):null!==s?s.toFixed():null},n.fmt=function(){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];var r=J(e),i=se(r.expr),o=null;if(2<i.length)throw new Error("fmt并非用于计算, 不能传入多个标识:".concat(r.expr));if(1!==i.length)throw new Error("fmt接收了一个无法被解析的标识");if(null!==r.data)if(null===(o=void 0!==r.data._fillData?r.data:o)||void 0===o.fillError&&void 0===o.error)i=j(i,r.data);else try{i=j(i,r.data)}catch(n){if(n instanceof TokensFillError)return o.fillError||o.error;throw n}if(null===r.fmt)throw"表达式没有格式化部分";return oe(i[0],r.fmt)},n.version="0.0.30",Object.defineProperty(n,"__esModule",{value:!0}),n}({});
|
|
1
|
+
var a_calc=function(e){"use strict";function C(e){return(C="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function n(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function r(e,r,t){return r&&n(e.prototype,r),t&&n(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function o(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),r&&l(e,r)}function u(e){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function l(e,r){return(l=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e})(e,r)}function f(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function s(e,r,t){return(s=f()?Reflect.construct:function(e,r,t){var n=[null];n.push.apply(n,r);r=new(Function.bind.apply(e,n));return t&&l(r,t.prototype),r}).apply(null,arguments)}function c(e){var t="function"==typeof Map?new Map:void 0;return(c=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return s(e,arguments,u(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),l(r,e)})(e)}function y(e,r){if(r&&("object"==typeof r||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");r=e;if(void 0===r)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function a(t){var n=f();return function(){var e,r=u(t);return y(this,n?(e=u(this).constructor,Reflect.construct(r,arguments,e)):r.apply(this,arguments))}}function b(e){return function(e){if(Array.isArray(e))return h(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,r){if(e){if("string"==typeof e)return h(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Map"===(t="Object"===t&&e.constructor?e.constructor.name:t)||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?h(e,r):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function p(e){return-1<"+-*/%()".indexOf(e)}function g(e){switch(e){case"+":case"-":return 1;case"*":case"/":case"%":return 2;default:return 0}}function d(e){var r={expr:"",fmt:null,data:null},t="",n=e[0];if(1===e.length)"string"==typeof n?t=n:"number"==typeof n?t=n.toString():Array.isArray(n)&&(t=n[0]);else if(1<e.length){n=e[e.length-1];if(l=n,"[object Object]"!==Object.prototype.toString.call(l)||Array.isArray(l))for(var i=b(e.shift());i.length||e.length;)var o=0===i.length?"":i.shift(),u=0===e.length?"":e.shift(),t=t+o+(u="number"==typeof u?u.toString():u);else t=e[0],r.data=n}var l=t.split("|");return 1===l.length?r.expr=l[0]:(r.expr=l[0],""!==(n=l[1]).trim()&&(r.fmt=n)),r}var re=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,M=Math.ceil,k=Math.floor,F="[BigNumber Error] ",$=F+"Number primitive has more than 15 significant digits: ",G=1e14,z=14,q=9007199254740991,H=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],V=1e7,W=1e9;function Z(e){var r=0|e;return 0<e||e===r?r:r-1}function X(e){for(var r,t,n=1,i=e.length,o=e[0]+"";n<i;){for(r=e[n++]+"",t=z-r.length;t--;r="0"+r);o+=r}for(i=o.length;48===o.charCodeAt(--i););return o.slice(0,i+1||1)}function Y(e,r){var t,n,i=e.c,o=r.c,u=e.s,l=r.s,e=e.e,r=r.e;if(!u||!l)return null;if(t=i&&!i[0],n=o&&!o[0],t||n)return t?n?0:-l:u;if(u!=l)return u;if(t=u<0,n=e==r,!i||!o)return n?0:!i^t?1:-1;if(!n)return r<e^t?1:-1;for(l=(e=i.length)<(r=o.length)?e:r,u=0;u<l;u++)if(i[u]!=o[u])return i[u]>o[u]^t?1:-1;return e==r?0:r<e^t?1:-1}function J(e,r,t,n){if(e<r||t<e||e!==k(e))throw Error(F+(n||"Argument")+("number"==typeof e?e<r||t<e?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function K(e){var r=e.c.length-1;return Z(e.e/z)==r&&e.c[r]%2!=0}function Q(e,r){return(1<e.length?e.charAt(0)+"."+e.slice(1):e)+(r<0?"e":"e+")+r}function ee(e,r,t){var n,i;if(r<0){for(i=t+".";++r;i+=t);e=i+e}else if(++r>(n=e.length)){for(i=t,r-=n;--r;i+=t);e+=i}else r<n&&(e=e.slice(0,r)+"."+e.slice(r));return e}var w=function U(e){var w,a,h,r,s,m,u,l,f,c,p,t=P.prototype={constructor:P,toString:null,valueOf:null},g=new P(1),v=20,y=4,d=-7,b=21,O=-1e7,E=1e7,N=!1,i=1,A=0,S={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},_="0123456789abcdefghijklmnopqrstuvwxyz",x=!0;function P(e,r){var t,n,i,o,u,l,f,s,c=this;if(!(c instanceof P))return new P(e,r);if(null==r){if(e&&!0===e._isBigNumber)return c.s=e.s,void(!e.c||e.e>E?c.c=c.e=null:e.e<O?c.c=[c.e=0]:(c.e=e.e,c.c=e.c.slice()));if((l="number"==typeof e)&&0*e==0){if(c.s=1/e<0?(e=-e,-1):1,e===~~e){for(o=0,u=e;10<=u;u/=10,o++);return void(E<o?c.c=c.e=null:(c.e=o,c.c=[e]))}s=String(e)}else{if(!re.test(s=String(e)))return h(c,s,l);c.s=45==s.charCodeAt(0)?(s=s.slice(1),-1):1}0<(u=(s=-1<(o=s.indexOf("."))?s.replace(".",""):s).search(/e/i))?(o<0&&(o=u),o+=+s.slice(u+1),s=s.substring(0,u)):o<0&&(o=s.length)}else{if(J(r,2,_.length,"Base"),10==r&&x)return I(c=new P(e),v+c.e+1,y);if(s=String(e),l="number"==typeof e){if(0*e!=0)return h(c,s,l,r);if(c.s=1/e<0?(s=s.slice(1),-1):1,P.DEBUG&&15<s.replace(/^0\.0*|\./,"").length)throw Error($+e)}else c.s=45===s.charCodeAt(0)?(s=s.slice(1),-1):1;for(t=_.slice(0,r),o=u=0,f=s.length;u<f;u++)if(t.indexOf(n=s.charAt(u))<0){if("."==n){if(o<u){o=f;continue}}else if(!i&&(s==s.toUpperCase()&&(s=s.toLowerCase())||s==s.toLowerCase()&&(s=s.toUpperCase()))){i=!0,u=-1,o=0;continue}return h(c,String(e),l,r)}l=!1,-1<(o=(s=a(s,r,10,c.s)).indexOf("."))?s=s.replace(".",""):o=s.length}for(u=0;48===s.charCodeAt(u);u++);for(f=s.length;48===s.charCodeAt(--f););if(s=s.slice(u,++f)){if(f-=u,l&&P.DEBUG&&15<f&&(q<e||e!==k(e)))throw Error($+c.s*e);if((o=o-u-1)>E)c.c=c.e=null;else if(o<O)c.c=[c.e=0];else{if(c.e=o,c.c=[],u=(o+1)%z,o<0&&(u+=z),u<f){for(u&&c.c.push(+s.slice(0,u)),f-=z;u<f;)c.c.push(+s.slice(u,u+=z));u=z-(s=s.slice(u)).length}else u-=f;for(;u--;s+="0");c.c.push(+s)}}else c.c=[c.e=0]}function R(e,r,t,n){for(var i,o,u=[0],l=0,f=e.length;l<f;){for(o=u.length;o--;u[o]*=r);for(u[0]+=n.indexOf(e.charAt(l++)),i=0;i<u.length;i++)u[i]>t-1&&(null==u[i+1]&&(u[i+1]=0),u[i+1]+=u[i]/t|0,u[i]%=t)}return u.reverse()}function D(e,r,t){var n,i,o,u=0,l=e.length,f=r%V,s=r/V|0;for(e=e.slice();l--;)u=((i=f*(o=e[l]%V)+(n=s*o+(o=e[l]/V|0)*f)%V*V+u)/t|0)+(n/V|0)+s*o,e[l]=i%t;return e=u?[u].concat(e):e}function j(e,r,t,n){var i,o;if(t!=n)o=n<t?1:-1;else for(i=o=0;i<t;i++)if(e[i]!=r[i]){o=e[i]>r[i]?1:-1;break}return o}function B(e,r,t,n){for(var i=0;t--;)e[t]-=i,i=e[t]<r[t]?1:0,e[t]=i*n+e[t]-r[t];for(;!e[0]&&1<e.length;e.splice(0,1));}function n(e,r,t,n){var i,o,u,l;if(null==t?t=y:J(t,0,8),!e.c)return e.toString();if(i=e.c[0],o=e.e,null==r)l=X(e.c),l=1==n||2==n&&(o<=d||b<=o)?Q(l,o):ee(l,o,"0");else if(t=(e=I(new P(e),r,t)).e,u=(l=X(e.c)).length,1==n||2==n&&(r<=t||t<=d)){for(;u<r;l+="0",u++);l=Q(l,t)}else if(r-=o,l=ee(l,t,"0"),u<t+1){if(0<--r)for(l+=".";r--;l+="0");}else if(0<(r+=t-u))for(t+1==u&&(l+=".");r--;l+="0");return e.s<0&&i?"-"+l:l}function o(e,r){for(var t,n=1,i=new P(e[0]);n<e.length;n++){if(!(t=new P(e[n])).s){i=t;break}r.call(i,t)&&(i=t)}return i}function T(e,r,t){for(var n=1,i=r.length;!r[--i];r.pop());for(i=r[0];10<=i;i/=10,n++);return(t=n+t*z-1)>E?e.c=e.e=null:t<O?e.c=[e.e=0]:(e.e=t,e.c=r),e}function I(e,r,t,n){var i,o,u,l,f,s,c,a=e.c,h=H;if(a){e:{for(i=1,l=a[0];10<=l;l/=10,i++);if((o=r-i)<0)o+=z,u=r,c=(f=a[s=0])/h[i-u-1]%10|0;else if((s=M((o+1)/z))>=a.length){if(!n)break e;for(;a.length<=s;a.push(0));f=c=0,u=(o%=z)-z+(i=1)}else{for(f=l=a[s],i=1;10<=l;l/=10,i++);c=(u=(o%=z)-z+i)<0?0:f/h[i-u-1]%10|0}if(n=n||r<0||null!=a[s+1]||(u<0?f:f%h[i-u-1]),n=t<4?(c||n)&&(0==t||t==(e.s<0?3:2)):5<c||5==c&&(4==t||n||6==t&&(0<o?0<u?f/h[i-u]:0:a[s-1])%10&1||t==(e.s<0?8:7)),r<1||!a[0])return a.length=0,n?(r-=e.e+1,a[0]=h[(z-r%z)%z],e.e=-r||0):a[0]=e.e=0,e;if(0==o?(a.length=s,l=1,s--):(a.length=s+1,l=h[z-o],a[s]=0<u?k(f/h[i-u]%h[u])*l:0),n)for(;;){if(0==s){for(o=1,u=a[0];10<=u;u/=10,o++);for(u=a[0]+=l,l=1;10<=u;u/=10,l++);o!=l&&(e.e++,a[0]==G&&(a[0]=1));break}if(a[s]+=l,a[s]!=G)break;a[s--]=0,l=1}for(o=a.length;0===a[--o];a.pop());}e.e>E?e.c=e.e=null:e.e<O&&(e.c=[e.e=0])}return e}function L(e){var r,t=e.e;return null===t?e.toString():(r=X(e.c),r=t<=d||b<=t?Q(r,t):ee(r,t,"0"),e.s<0?"-"+r:r)}return P.clone=U,P.ROUND_UP=0,P.ROUND_DOWN=1,P.ROUND_CEIL=2,P.ROUND_FLOOR=3,P.ROUND_HALF_UP=4,P.ROUND_HALF_DOWN=5,P.ROUND_HALF_EVEN=6,P.ROUND_HALF_CEIL=7,P.ROUND_HALF_FLOOR=8,P.EUCLID=9,P.config=P.set=function(e){var r,t;if(null!=e){if("object"!=C(e))throw Error(F+"Object expected: "+e);if(e.hasOwnProperty(r="DECIMAL_PLACES")&&(J(t=e[r],0,W,r),v=t),e.hasOwnProperty(r="ROUNDING_MODE")&&(J(t=e[r],0,8,r),y=t),e.hasOwnProperty(r="EXPONENTIAL_AT")&&((t=e[r])&&t.pop?(J(t[0],-W,0,r),J(t[1],0,W,r),d=t[0],b=t[1]):(J(t,-W,W,r),d=-(b=t<0?-t:t))),e.hasOwnProperty(r="RANGE"))if((t=e[r])&&t.pop)J(t[0],-W,-1,r),J(t[1],1,W,r),O=t[0],E=t[1];else{if(J(t,-W,W,r),!t)throw Error(F+r+" cannot be zero: "+t);O=-(E=t<0?-t:t)}if(e.hasOwnProperty(r="CRYPTO")){if((t=e[r])!==!!t)throw Error(F+r+" not true or false: "+t);if(t){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw N=!t,Error(F+"crypto unavailable");N=t}else N=t}if(e.hasOwnProperty(r="MODULO_MODE")&&(J(t=e[r],0,9,r),i=t),e.hasOwnProperty(r="POW_PRECISION")&&(J(t=e[r],0,W,r),A=t),e.hasOwnProperty(r="FORMAT")){if("object"!=C(t=e[r]))throw Error(F+r+" not an object: "+t);S=t}if(e.hasOwnProperty(r="ALPHABET")){if("string"!=typeof(t=e[r])||/^.?$|[+\-.\s]|(.).*\1/.test(t))throw Error(F+r+" invalid: "+t);x="0123456789"==t.slice(0,10),_=t}}return{DECIMAL_PLACES:v,ROUNDING_MODE:y,EXPONENTIAL_AT:[d,b],RANGE:[O,E],CRYPTO:N,MODULO_MODE:i,POW_PRECISION:A,FORMAT:S,ALPHABET:_}},P.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!P.DEBUG)return!0;var r,t,n=e.c,i=e.e,o=e.s;e:if("[object Array]"=={}.toString.call(n)){if((1===o||-1===o)&&-W<=i&&i<=W&&i===k(i))if(0===n[0]){if(0===i&&1===n.length)return!0}else if((r=(i+1)%z)<1&&(r+=z),String(n[0]).length==r){for(r=0;r<n.length;r++)if((t=n[r])<0||G<=t||t!==k(t))break e;if(0!==t)return!0}}else if(null===n&&null===i&&(null===o||1===o||-1===o))return!0;throw Error(F+"Invalid BigNumber: "+e)},P.maximum=P.max=function(){return o(arguments,t.lt)},P.minimum=P.min=function(){return o(arguments,t.gt)},P.random=(r=9007199254740992,s=Math.random()*r&2097151?function(){return k(Math.random()*r)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var r,t,n,i,o,u=0,l=[],f=new P(g);if(null==e?e=v:J(e,0,W),i=M(e/z),N)if(crypto.getRandomValues){for(r=crypto.getRandomValues(new Uint32Array(i*=2));u<i;)9e15<=(o=131072*r[u]+(r[u+1]>>>11))?(t=crypto.getRandomValues(new Uint32Array(2)),r[u]=t[0],r[u+1]=t[1]):(l.push(o%1e14),u+=2);u=i/2}else{if(!crypto.randomBytes)throw N=!1,Error(F+"crypto unavailable");for(r=crypto.randomBytes(i*=7);u<i;)9e15<=(o=281474976710656*(31&r[u])+1099511627776*r[u+1]+4294967296*r[u+2]+16777216*r[u+3]+(r[u+4]<<16)+(r[u+5]<<8)+r[u+6])?crypto.randomBytes(7).copy(r,u):(l.push(o%1e14),u+=7);u=i/7}if(!N)for(;u<i;)(o=s())<9e15&&(l[u++]=o%1e14);for(i=l[--u],e%=z,i&&e&&(l[u]=k(i/(o=H[z-e]))*o);0===l[u];l.pop(),u--);if(u<0)l=[n=0];else{for(n=-1;0===l[0];l.splice(0,1),n-=z);for(u=1,o=l[0];10<=o;o/=10,u++);u<z&&(n-=z-u)}return f.e=n,f.c=l,f}),P.sum=function(){for(var e=1,r=arguments,t=new P(r[0]);e<r.length;)t=t.plus(r[e++]);return t},m="0123456789",a=function(e,r,t,n,i){var o,u,l,f,s,c,a,h,p=e.indexOf("."),g=v,d=y;for(0<=p&&(f=A,A=0,e=e.replace(".",""),c=(h=new P(r)).pow(e.length-p),A=f,h.c=R(ee(X(c.c),c.e,"0"),10,t,m),h.e=h.c.length),l=f=(a=R(e,r,t,i?(o=_,m):(o=m,_))).length;0==a[--f];a.pop());if(!a[0])return o.charAt(0);if(p<0?--l:(c.c=a,c.e=l,c.s=n,a=(c=w(c,h,g,d,t)).c,s=c.r,l=c.e),p=a[u=l+g+1],f=t/2,s=s||u<0||null!=a[u+1],s=d<4?(null!=p||s)&&(0==d||d==(c.s<0?3:2)):f<p||p==f&&(4==d||s||6==d&&1&a[u-1]||d==(c.s<0?8:7)),u<1||!a[0])e=s?ee(o.charAt(1),-g,o.charAt(0)):o.charAt(0);else{if(a.length=u,s)for(--t;++a[--u]>t;)a[u]=0,u||(++l,a=[1].concat(a));for(f=a.length;!a[--f];);for(p=0,e="";p<=f;e+=o.charAt(a[p++]));e=ee(e,l,o.charAt(0))}return e},w=function(e,r,t,n,i){var o,u,l,f,s,c,a,h,p,g,d,w,m,v,y,b,O,E=e.s==r.s?1:-1,N=e.c,A=r.c;if(!(N&&N[0]&&A&&A[0]))return new P(e.s&&r.s&&(N?!A||N[0]!=A[0]:A)?N&&0==N[0]||!A?0*E:E/0:NaN);for(p=(h=new P(E)).c=[],E=t+(u=e.e-r.e)+1,i||(i=G,u=Z(e.e/z)-Z(r.e/z),E=E/z|0),l=0;A[l]==(N[l]||0);l++);if(A[l]>(N[l]||0)&&u--,E<0)p.push(1),f=!0;else{for(v=N.length,b=A.length,E+=2,1<(s=k(i/(A[l=0]+1)))&&(A=D(A,s,i),N=D(N,s,i),b=A.length,v=N.length),m=b,d=(g=N.slice(0,b)).length;d<b;g[d++]=0);O=A.slice(),O=[0].concat(O),y=A[0],A[1]>=i/2&&y++;do{if(s=0,(o=j(A,g,b,d))<0){if(w=g[0],b!=d&&(w=w*i+(g[1]||0)),1<(s=k(w/y)))for(a=(c=D(A,s=i<=s?i-1:s,i)).length,d=g.length;1==j(c,g,a,d);)s--,B(c,b<a?O:A,a,i),a=c.length,o=1;else 0==s&&(o=s=1),a=(c=A.slice()).length;if(B(g,c=a<d?[0].concat(c):c,d,i),d=g.length,-1==o)for(;j(A,g,b,d)<1;)s++,B(g,b<d?O:A,d,i),d=g.length}else 0===o&&(s++,g=[0])}while(p[l++]=s,g[0]?g[d++]=N[m]||0:(g=[N[m]],d=1),(m++<v||null!=g[0])&&E--);f=null!=g[0],p[0]||p.splice(0,1)}if(i==G){for(l=1,E=p[0];10<=E;E/=10,l++);I(h,t+(h.e=l+u*z-1)+1,n,f)}else h.e=u,h.r=+f;return h},u=/^(-?)0([xbo])(?=\w[\w.]*$)/i,l=/^([^.]+)\.$/,f=/^\.([^.]+)$/,c=/^-?(Infinity|NaN)$/,p=/^\s*\+(?=[\w.])|^\s+|\s+$/g,h=function(e,r,t,n){var i,o=t?r:r.replace(p,"");if(c.test(o))e.s=isNaN(o)?null:o<0?-1:1;else{if(!t&&(o=o.replace(u,function(e,r,t){return i="x"==(t=t.toLowerCase())?16:"b"==t?2:8,n&&n!=i?e:r}),n&&(i=n,o=o.replace(l,"$1").replace(f,"0.$1")),r!=o))return new P(o,i);if(P.DEBUG)throw Error(F+"Not a"+(n?" base "+n:"")+" number: "+r);e.s=null}e.c=e.e=null},t.absoluteValue=t.abs=function(){var e=new P(this);return e.s<0&&(e.s=1),e},t.comparedTo=function(e,r){return Y(this,new P(e,r))},t.decimalPlaces=t.dp=function(e,r){var t,n;if(null!=e)return J(e,0,W),null==r?r=y:J(r,0,8),I(new P(this),e+this.e+1,r);if(!(e=this.c))return null;if(t=((n=e.length-1)-Z(this.e/z))*z,n=e[n])for(;n%10==0;n/=10,t--);return t=t<0?0:t},t.dividedBy=t.div=function(e,r){return w(this,new P(e,r),v,y)},t.dividedToIntegerBy=t.idiv=function(e,r){return w(this,new P(e,r),0,1)},t.exponentiatedBy=t.pow=function(e,r){var t,n,i,o,u,l,f,s,c=this;if((e=new P(e)).c&&!e.isInteger())throw Error(F+"Exponent not an integer: "+L(e));if(null!=r&&(r=new P(r)),u=14<e.e,!c.c||!c.c[0]||1==c.c[0]&&!c.e&&1==c.c.length||!e.c||!e.c[0])return s=new P(Math.pow(+L(c),u?2-K(e):+L(e))),r?s.mod(r):s;if(l=e.s<0,r){if(r.c?!r.c[0]:!r.s)return new P(NaN);(n=!l&&c.isInteger()&&r.isInteger())&&(c=c.mod(r))}else{if(9<e.e&&(0<c.e||c.e<-1||(0==c.e?1<c.c[0]||u&&24e7<=c.c[1]:c.c[0]<8e13||u&&c.c[0]<=9999975e7)))return o=c.s<0&&K(e)?-0:0,-1<c.e&&(o=1/o),new P(l?1/o:o);A&&(o=M(A/z+2))}for(f=u?(t=new P(.5),l&&(e.s=1),K(e)):(i=Math.abs(+L(e)))%2,s=new P(g);;){if(f){if(!(s=s.times(c)).c)break;o?s.c.length>o&&(s.c.length=o):n&&(s=s.mod(r))}if(i){if(0===(i=k(i/2)))break;f=i%2}else if(I(e=e.times(t),e.e+1,1),14<e.e)f=K(e);else{if(0==(i=+L(e)))break;f=i%2}c=c.times(c),o?c.c&&c.c.length>o&&(c.c.length=o):n&&(c=c.mod(r))}return n?s:(l&&(s=g.div(s)),r?s.mod(r):o?I(s,A,y,void 0):s)},t.integerValue=function(e){var r=new P(this);return null==e?e=y:J(e,0,8),I(r,r.e+1,e)},t.isEqualTo=t.eq=function(e,r){return 0===Y(this,new P(e,r))},t.isFinite=function(){return!!this.c},t.isGreaterThan=t.gt=function(e,r){return 0<Y(this,new P(e,r))},t.isGreaterThanOrEqualTo=t.gte=function(e,r){return 1===(r=Y(this,new P(e,r)))||0===r},t.isInteger=function(){return!!this.c&&Z(this.e/z)>this.c.length-2},t.isLessThan=t.lt=function(e,r){return Y(this,new P(e,r))<0},t.isLessThanOrEqualTo=t.lte=function(e,r){return-1===(r=Y(this,new P(e,r)))||0===r},t.isNaN=function(){return!this.s},t.isNegative=function(){return this.s<0},t.isPositive=function(){return 0<this.s},t.isZero=function(){return!!this.c&&0==this.c[0]},t.minus=function(e,r){var t,n,i,o,u=this,l=u.s;if(r=(e=new P(e,r)).s,!l||!r)return new P(NaN);if(l!=r)return e.s=-r,u.plus(e);var f=u.e/z,s=e.e/z,c=u.c,a=e.c;if(!f||!s){if(!c||!a)return c?(e.s=-r,e):new P(a?u:NaN);if(!c[0]||!a[0])return a[0]?(e.s=-r,e):new P(c[0]?u:3==y?-0:0)}if(f=Z(f),s=Z(s),c=c.slice(),l=f-s){for((i=(o=l<0)?(l=-l,c):(s=f,a)).reverse(),r=l;r--;i.push(0));i.reverse()}else for(n=(o=(l=c.length)<(r=a.length))?l:r,l=r=0;r<n;r++)if(c[r]!=a[r]){o=c[r]<a[r];break}if(o&&(i=c,c=a,a=i,e.s=-e.s),0<(r=(n=a.length)-(t=c.length)))for(;r--;c[t++]=0);for(r=G-1;l<n;){if(c[--n]<a[n]){for(t=n;t&&!c[--t];c[t]=r);--c[t],c[n]+=G}c[n]-=a[n]}for(;0==c[0];c.splice(0,1),--s);return c[0]?T(e,c,s):(e.s=3==y?-1:1,e.c=[e.e=0],e)},t.modulo=t.mod=function(e,r){var t,n=this;return e=new P(e,r),!n.c||!e.s||e.c&&!e.c[0]?new P(NaN):!e.c||n.c&&!n.c[0]?new P(n):(9==i?(r=e.s,e.s=1,t=w(n,e,0,3),e.s=r,t.s*=r):t=w(n,e,0,i),(e=n.minus(t.times(e))).c[0]||1!=i||(e.s=n.s),e)},t.multipliedBy=t.times=function(e,r){var t,n,i,o,u,l,f,s,c,a,h,p=this,g=p.c,d=(e=new P(e,r)).c;if(!(g&&d&&g[0]&&d[0]))return!p.s||!e.s||g&&!g[0]&&!d||d&&!d[0]&&!g?e.c=e.e=e.s=null:(e.s*=p.s,g&&d?(e.c=[0],e.e=0):e.c=e.e=null),e;for(r=Z(p.e/z)+Z(e.e/z),e.s*=p.s,(l=g.length)<(p=d.length)&&(h=g,g=d,d=h,n=l,l=p,p=n),n=l+p,h=[];n--;h.push(0));for(n=p;0<=--n;){for(c=d[n]%1e7,a=d[n]/1e7|(t=0),i=n+(o=l);n<i;)t=((f=c*(f=g[--o]%1e7)+(u=a*f+(s=g[o]/1e7|0)*c)%1e7*1e7+h[i]+t)/1e14|0)+(u/1e7|0)+a*s,h[i--]=f%1e14;h[i]=t}return t?++r:h.splice(0,1),T(e,h,r)},t.negated=function(){var e=new P(this);return e.s=-e.s||null,e},t.plus=function(e,r){var t,n=this,i=n.s;if(r=(e=new P(e,r)).s,!i||!r)return new P(NaN);if(i!=r)return e.s=-r,n.minus(e);var o=n.e/z,u=e.e/z,l=n.c,f=e.c;if(!o||!u){if(!l||!f)return new P(i/0);if(!l[0]||!f[0])return f[0]?e:new P(l[0]?n:0*i)}if(o=Z(o),u=Z(u),l=l.slice(),i=o-u){for((t=0<i?(u=o,f):(i=-i,l)).reverse();i--;t.push(0));t.reverse()}for((i=l.length)-(r=f.length)<0&&(t=f,f=l,l=t,r=i),i=0;r;)i=(l[--r]=l[r]+f[r]+i)/G|0,l[r]=G===l[r]?0:l[r]%G;return i&&(l=[i].concat(l),++u),T(e,l,u)},t.precision=t.sd=function(e,r){var t,n;if(null!=e&&e!==!!e)return J(e,1,W),null==r?r=y:J(r,0,8),I(new P(this),e,r);if(!(r=this.c))return null;if(t=(n=r.length-1)*z+1,n=r[n]){for(;n%10==0;n/=10,t--);for(n=r[0];10<=n;n/=10,t++);}return t=e&&this.e+1>t?this.e+1:t},t.shiftedBy=function(e){return J(e,-q,q),this.times("1e"+e)},t.squareRoot=t.sqrt=function(){var e,r,t,n,i,o=this,u=o.c,l=o.s,f=o.e,s=v+4,c=new P("0.5");if(1!==l||!u||!u[0])return new P(!l||l<0&&(!u||u[0])?NaN:u?o:1/0);if((t=0==(l=Math.sqrt(+L(o)))||l==1/0?(((r=X(u)).length+f)%2==0&&(r+="0"),l=Math.sqrt(+r),f=Z((f+1)/2)-(f<0||f%2),new P(r=l==1/0?"5e"+f:(r=l.toExponential()).slice(0,r.indexOf("e")+1)+f)):new P(l+"")).c[0])for((l=(f=t.e)+s)<3&&(l=0);;)if(i=t,t=c.times(i.plus(w(o,i,s,1))),X(i.c).slice(0,l)===(r=X(t.c)).slice(0,l)){if(t.e<f&&--l,"9999"!=(r=r.slice(l-3,l+1))&&(n||"4999"!=r)){+r&&(+r.slice(1)||"5"!=r.charAt(0))||(I(t,t.e+v+2,1),e=!t.times(t).eq(o));break}if(!n&&(I(i,i.e+v+2,0),i.times(i).eq(o))){t=i;break}s+=4,l+=4,n=1}return I(t,t.e+v+1,y,e)},t.toExponential=function(e,r){return null!=e&&(J(e,0,W),e++),n(this,e,r,1)},t.toFixed=function(e,r){return null!=e&&(J(e,0,W),e=e+this.e+1),n(this,e,r)},t.toFormat=function(e,r,t){if(null==t)null!=e&&r&&"object"==C(r)?(t=r,r=null):e&&"object"==C(e)?(t=e,e=r=null):t=S;else if("object"!=C(t))throw Error(F+"Argument not an object: "+t);if(e=this.toFixed(e,r),this.c){var n,r=e.split("."),i=+t.groupSize,o=+t.secondaryGroupSize,u=t.groupSeparator||"",l=r[0],r=r[1],f=this.s<0,s=f?l.slice(1):l,c=s.length;if(o&&(n=i,i=o,c-=o=n),0<i&&0<c){for(l=s.substr(0,n=c%i||i);n<c;n+=i)l+=u+s.substr(n,i);0<o&&(l+=u+s.slice(n)),f&&(l="-"+l)}e=r?l+(t.decimalSeparator||"")+((o=+t.fractionGroupSize)?r.replace(new RegExp("\\d{"+o+"}\\B","g"),"$&"+(t.fractionGroupSeparator||"")):r):l}return(t.prefix||"")+e+(t.suffix||"")},t.toFraction=function(e){var r,t,n,i,o,u,l,f,s,c,a=this,h=a.c;if(null!=e&&(!(l=new P(e)).isInteger()&&(l.c||1!==l.s)||l.lt(g)))throw Error(F+"Argument "+(l.isInteger()?"out of range: ":"not an integer: ")+L(l));if(!h)return new P(a);for(r=new P(g),s=t=new P(g),n=f=new P(g),h=X(h),o=r.e=h.length-a.e-1,r.c[0]=H[(u=o%z)<0?z+u:u],e=!e||0<l.comparedTo(r)?0<o?r:s:l,u=E,E=1/0,l=new P(h),f.c[0]=0;c=w(l,r,0,1),1!=(i=t.plus(c.times(n))).comparedTo(e);)t=n,n=i,s=f.plus(c.times(i=s)),f=i,r=l.minus(c.times(i=r)),l=i;return i=w(e.minus(t),n,0,1),f=f.plus(i.times(s)),t=t.plus(i.times(n)),f.s=s.s=a.s,h=w(s,n,o*=2,y).minus(a).abs().comparedTo(w(f,t,o,y).minus(a).abs())<1?[s,n]:[f,t],E=u,h},t.toNumber=function(){return+L(this)},t.toPrecision=function(e,r){return null!=e&&J(e,1,W),n(this,e,r,2)},t.toString=function(e){var r,t=this,n=t.s,i=t.e;return null===i?n?(r="Infinity",n<0&&(r="-"+r)):r="NaN":(r=null==e?i<=d||b<=i?Q(X(t.c),i):ee(X(t.c),i,"0"):10===e&&x?ee(X((t=I(new P(t),v+i+1,y)).c),t.e,"0"):(J(e,2,_.length,"Base"),a(ee(X(t.c),i,"0"),10,e,n,!0)),n<0&&t.c[0]&&(r="-"+r)),r},t.valueOf=t.toJSON=function(){return L(this)},t._isBigNumber=!0,t[Symbol.toStringTag]="BigNumber",t[Symbol.for("nodejs.util.inspect.custom")]=t.valueOf,null!=e&&P.set(e),P}();function O(e,r){var t="",n=(t=w.isBigNumber(e)?e.toFixed():"string"!=typeof e?e.toString():e,null),e=null,i=null,o=r.match(/(<=|>=|=)\s*(\d+)/);if(o&&(e=o[1],n=Number(o[2])),r.includes(",")&&(i=!0),null!==n){var o=t.split("."),r=o[0],u=1===o.length?"":o[1],l=u.length;switch(e){case"<=":u=l<=n?u:u.slice(0,n);break;case"=":l<n?u+="0".repeat(n-l):n<l&&(u=u.slice(0,n));break;case">=":u=n<=l?u:u+"0".repeat(n-l)}t=""===u?r:"".concat(r,".").concat(u)}return t=null!==i?1<(o=t.split(".")).length?((e=o[0]).includes("-")?o[0]=e[0]+e.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):o[0]=e.replace(/(?=(?!^)(?:\d{3})+$)/g,","),o.join(".")):(r=o[0]).includes("-")?r[0]+r.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):r.replace(/(?=(?!^)(?:\d{3})+$)/g,","):t}function E(e){for(var r=[],t=0,n=null,i=e.length;t<i;)if(n=e[t],/\s/.test(n))t++;else if("+-".includes(n)){var o=r[r.length-1];if(0===r.length||"+-".includes(o)||"("===o){for(var u=n,n=e[++t];/[a-zA-Z\d._]/.test(n);)u+=n,n=e[++t];r.push(u)}else r.push(n),t++}else if("*/%()".includes(n))r.push(n),t++;else if(/[a-zA-Z_]/.test(n)){for(var l="";/[a-zA-Z0-9_]/.test(n)&&(l+=n,!(++t>=i));)n=e[t];r.push(l)}else if(/\d/.test(n)){for(var f="";/[\d.]/.test(n)&&(f+=n,!(++t>=i));)n=e[t];r.push(f)}return r}var m=function(){o(n,c(Error));var t=a(n);function n(e){var r;return i(this,n),(r=t.call(this,e)).name="CalculatorError",r.message=e,r}return r(n)}(),N=function(){o(n,c(Error));var t=a(n);function n(e){var r;return i(this,n),(r=t.call(this,e)).name="TokensFillError",r.message=e,r}return r(n)}();function v(e,r){var t=r._fillData;return void 0===r._fillData&&(t=r),e.map(function(e){if(/^[a-zA-z_][\w_]*$/.test(e)){var r=t[e];if(void 0!==r)return"number"==typeof r?r.toString():r;throw new N("错误的参数:".concat(e," 请确认他存在"))}return e})}function A(e){for(var r,t=[],n=[],i=e;0<i.length;){var o=i.shift();if(p(o))if("("===o)t.push(o);else if(")"===o){for(var u=t.pop();"("!==u&&0<t.length;)n.push(u),u=t.pop();if("("!==u)throw"error: unmatched ()"}else{for(;r=t[t.length-1],g(o)<=g(r)&&0<t.length;)n.push(t.pop());t.push(o)}else n.push(o)}if(0<t.length){if(")"===t[t.length-1]||"("===t[t.length-1])throw"error: unmatched ()";for(;0<t.length;)n.push(t.pop())}return n}function S(e){for(var r=[];0<e.length;){var t=e.shift();if(p(t)){if(r.length<2)throw new m("错误的栈长度, 可能是无法计算的表达式");var n=r.pop(),i=r.pop();if("string"==typeof n&&!w.isBigNumber(n)){if(!/^[+-]*[\d.]+$/.test(n))throw new m("".concat(n,"不是一个合法的数字"));n=new w(n)}if("string"==typeof i&&!w.isBigNumber(i)){if(!/^[+-]*[\d.]+$/.test(i))throw new m("".concat(i,"不是一个合法的数字"));i=new w(i)}switch(t){case"+":r.push(i.plus(n));break;case"-":r.push(i.minus(n));break;case"*":r.push(i.times(n));break;case"/":r.push(i.div(n));break;case"%":r.push(i.mod(n))}}else r.push(t)}if(1!==r.length)throw"unvalid expression";return r[0]}return e.calc=function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];var n=d(r),i=E(n.expr),o=null;if(null!==n.data)if(null===(o=void 0!==n.data._fillData?n.data:o)||void 0===o.fillError&&void 0===o.error)i=v(i,n.data);else try{i=v(i,n.data)}catch(e){if(e instanceof N)return void 0!==o.warn&&!0===o.warn&&console.warn(e),o.fillError||o.error;throw e}var i=A(i),u=null;if(null!==o){if(void 0!==o.calcError||void 0!==o.error)try{u=S(i)}catch(e){if(e instanceof m)return void 0!==o.warn&&!0===o.warn&&console.warn(e),void 0!==o.calcError?o.calcError:o.error;throw e}}else u=S(i);return u=null!==n.fmt?O(u,n.fmt):null!==u?u.toFixed():null},e.fmt=function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];var n=d(r),i=E(n.expr),o=null;if(2<i.length)throw new Error("fmt并非用于计算, 不能传入多个标识:".concat(n.expr));if(1!==i.length)throw new Error("fmt接收了一个无法被解析的标识");if(null!==n.data)if(null===(o=void 0!==n.data._fillData?n.data:o)||void 0===o.fillError&&void 0===o.error)i=v(i,n.data);else try{i=v(i,n.data)}catch(e){if(e instanceof TokensFillError)return o.fillError||o.error;throw e}if(null===n.fmt)throw"表达式没有格式化部分";return O(i[0],n.fmt)},e.version="0.0.36",Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|
package/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var BigNumber=require("bignumber.js");function _interopDefaultLegacy(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var BigNumber__default=_interopDefaultLegacy(BigNumber);function _classCallCheck(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(r,e){for(var t=0;t<e.length;t++){var n=e[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,n.key,n)}}function _createClass(r,e,t){return e&&_defineProperties(r.prototype,e),t&&_defineProperties(r,t),Object.defineProperty(r,"prototype",{writable:!1}),r}function _inherits(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),e&&_setPrototypeOf(r,e)}function _getPrototypeOf(r){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)})(r)}function _setPrototypeOf(r,e){return(_setPrototypeOf=Object.setPrototypeOf||function(r,e){return r.__proto__=e,r})(r,e)}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(r){return!1}}function _construct(r,e,t){return(_construct=_isNativeReflectConstruct()?Reflect.construct:function(r,e,t){var n=[null];n.push.apply(n,e);e=new(Function.bind.apply(r,n));return t&&_setPrototypeOf(e,t.prototype),e}).apply(null,arguments)}function _isNativeFunction(r){return-1!==Function.toString.call(r).indexOf("[native code]")}function _wrapNativeSuper(r){var t="function"==typeof Map?new Map:void 0;return(_wrapNativeSuper=function(r){if(null===r||!_isNativeFunction(r))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(r))return t.get(r);t.set(r,e)}function e(){return _construct(r,arguments,_getPrototypeOf(this).constructor)}return e.prototype=Object.create(r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(e,r)})(r)}function _assertThisInitialized(r){if(void 0===r)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function _possibleConstructorReturn(r,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(r)}function _createSuper(t){var n=_isNativeReflectConstruct();return function(){var r,e=_getPrototypeOf(t);return _possibleConstructorReturn(this,n?(r=_getPrototypeOf(this).constructor,Reflect.construct(e,arguments,r)):e.apply(this,arguments))}}function _toConsumableArray(r){return _arrayWithoutHoles(r)||_iterableToArray(r)||_unsupportedIterableToArray(r)||_nonIterableSpread()}function _arrayWithoutHoles(r){if(Array.isArray(r))return _arrayLikeToArray(r)}function _iterableToArray(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}function _unsupportedIterableToArray(r,e){if(r){if("string"==typeof r)return _arrayLikeToArray(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);return"Map"===(t="Object"===t&&r.constructor?r.constructor.name:t)||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,e):void 0}}function _arrayLikeToArray(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,n=new Array(e);t<e;t++)n[t]=r[t];return n}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function isOperator(r){return-1<"+-*/%()".indexOf(r)}function getPrioraty(r){switch(r){case"+":case"-":return 1;case"*":case"/":case"%":return 2;default:return 0}}function prioraty(r,e){return getPrioraty(r)<=getPrioraty(e)}function isObj(r){return"[object Object]"===Object.prototype.toString.call(r)&&!Array.isArray(r)}function parseArgs(r){var e={expr:"",fmt:null,data:null},t="",n=r[0];if(1===r.length)"string"==typeof n?t=n:"number"==typeof n?t=n.toString():Array.isArray(n)&&(t=n[0]);else if(1<r.length){n=r[r.length-1];if(isObj(n))t=r[0],e.data=n;else for(var o=_toConsumableArray(r.shift());o.length||r.length;)var i=0===o.length?"":o.shift(),a=0===r.length?"":r.shift(),t=t+i+(a="number"==typeof a?a.toString():a)}var n=t.split("|");return 1===n.length?e.expr=n[0]:(e.expr=n[0],""!==(n=n[1]).trim()&&(e.fmt=n)),e}function format(r,e){var t="",n=(t=BigNumber__default.default.isBigNumber(r)?r.toFixed():"string"!=typeof r?r.toString():r,null),r=null,o=null,i=e.match(/(<=|>=|=)\s*(\d+)/);if(i&&(r=i[1],n=Number(i[2])),e.includes(",")&&(o=!0),null!==n){var i=t.split("."),e=i[0],a=1===i.length?"":i[1],l=a.length;switch(r){case"<=":a=l<=n?a:a.slice(0,n);break;case"=":l<n?a+="0".repeat(n-l):n<l&&(a=a.slice(0,n));break;case">=":a=n<=l?a:a+"0".repeat(n-l)}t=""===a?e:"".concat(e,".").concat(a)}return t=null!==o?1<(i=t.split(".")).length?((r=i[0]).includes("-")?i[0]=r[0]+r.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):i[0]=r.replace(/(?=(?!^)(?:\d{3})+$)/g,","),i.join(".")):(e=i[0]).includes("-")?e[0]+e.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):e.replace(/(?=(?!^)(?:\d{3})+$)/g,","):t}function tokenizer(r){for(var e=[],t=0,n=null,o=r.length;t<o;)if(n=r[t],/\s/.test(n))t++;else if("+-".includes(n)){var i=e[e.length-1];if(0===e.length||"+-".includes(i)||"("===i){for(var a=n,n=r[++t];/[a-zA-Z\d._]/.test(n);)a+=n,n=r[++t];e.push(a)}else e.push(n),t++}else if("*/%()".includes(n))e.push(n),t++;else if(/[a-zA-Z_]/.test(n)){for(var l="";/[a-zA-Z0-9_]/.test(n)&&(l+=n,!(++t>=o));)n=r[t];e.push(l)}else if(/\d/.test(n)){for(var u="";/[\d.]/.test(n)&&(u+=n,!(++t>=o));)n=r[t];e.push(u)}return e}var CalculatorError=function(){_inherits(n,_wrapNativeSuper(Error));var t=_createSuper(n);function n(r){var e;return _classCallCheck(this,n),(e=t.call(this,r)).name="CalculatorError",e.message=r,e}return _createClass(n)}(),TokensFillError$1=function(){_inherits(n,_wrapNativeSuper(Error));var t=_createSuper(n);function n(r){var e;return _classCallCheck(this,n),(e=t.call(this,r)).name="TokensFillError",e.message=r,e}return _createClass(n)}();function fillTokens(r,e){var t=e._fillData;return void 0===e._fillData&&(t=e),r.map(function(r){if(/^[a-zA-z_][\w_]*$/.test(r)){var e=t[r];if(void 0!==e)return"number"==typeof e?e.toString():e;throw new TokensFillError$1("错误的参数:".concat(r," 请确认他存在"))}return r})}function fmt(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];var n=parseArgs(e),o=tokenizer(n.expr),i=null;if(2<o.length)throw new Error("fmt并非用于计算, 不能传入多个标识:".concat(n.expr));if(1!==o.length)throw new Error("fmt接收了一个无法被解析的标识");if(null!==n.data)if(null===(i=void 0!==n.data._fillData?n.data:i)||void 0===i.fillError&&void 0===i.error)o=fillTokens(o,n.data);else try{o=fillTokens(o,n.data)}catch(r){if(r instanceof TokensFillError)return i.fillError||i.error;throw r}if(null===n.fmt)throw"表达式没有格式化部分";return format(o[0],n.fmt)}var version="0.0.36";function token2postfix(r){for(var e=[],t=[],n=r;0<n.length;){var o=n.shift();if(isOperator(o))if("("===o)e.push(o);else if(")"===o){for(var i=e.pop();"("!==i&&0<e.length;)t.push(i),i=e.pop();if("("!==i)throw"error: unmatched ()"}else{for(;prioraty(o,e[e.length-1])&&0<e.length;)t.push(e.pop());e.push(o)}else t.push(o)}if(0<e.length){if(")"===e[e.length-1]||"("===e[e.length-1])throw"error: unmatched ()";for(;0<e.length;)t.push(e.pop())}return t}function evalPostfix(r){for(var e=[];0<r.length;){var t=r.shift();if(isOperator(t)){if(e.length<2)throw new CalculatorError("错误的栈长度, 可能是无法计算的表达式");var n=e.pop(),o=e.pop();if("string"==typeof n&&!BigNumber__default.default.isBigNumber(n)){if(!/^[+-]*[\d.]+$/.test(n))throw new CalculatorError("".concat(n,"不是一个合法的数字"));n=new BigNumber__default.default(n)}if("string"==typeof o&&!BigNumber__default.default.isBigNumber(o)){if(!/^[+-]*[\d.]+$/.test(o))throw new CalculatorError("".concat(o,"不是一个合法的数字"));o=new BigNumber__default.default(o)}switch(t){case"+":e.push(o.plus(n));break;case"-":e.push(o.minus(n));break;case"*":e.push(o.times(n));break;case"/":e.push(o.div(n));break;case"%":e.push(o.mod(n))}}else e.push(t)}if(1!==e.length)throw"unvalid expression";return e[0]}function calc(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];var n=parseArgs(e),o=tokenizer(n.expr),i=null;if(null!==n.data)if(null===(i=void 0!==n.data._fillData?n.data:i)||void 0===i.fillError&&void 0===i.error)o=fillTokens(o,n.data);else try{o=fillTokens(o,n.data)}catch(r){if(r instanceof TokensFillError$1)return void 0!==i.warn&&!0===i.warn&&console.warn(r),i.fillError||i.error;throw r}var o=token2postfix(o),a=null;if(null!==i){if(void 0!==i.calcError||void 0!==i.error)try{a=evalPostfix(o)}catch(r){if(r instanceof CalculatorError)return void 0!==i.warn&&!0===i.warn&&console.warn(r),void 0!==i.calcError?i.calcError:i.error;throw r}}else a=evalPostfix(o);return a=null!==n.fmt?format(a,n.fmt):null!==a?a.toFixed():null}exports.calc=calc,exports.fmt=fmt,exports.version=version;
|
package/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigNumber from"bignumber.js";function _classCallCheck(r,t){if(!(r instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(r,t){for(var e=0;e<t.length;e++){var n=t[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,n.key,n)}}function _createClass(r,t,e){return t&&_defineProperties(r.prototype,t),e&&_defineProperties(r,e),Object.defineProperty(r,"prototype",{writable:!1}),r}function _inherits(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(t&&t.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),t&&_setPrototypeOf(r,t)}function _getPrototypeOf(r){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)})(r)}function _setPrototypeOf(r,t){return(_setPrototypeOf=Object.setPrototypeOf||function(r,t){return r.__proto__=t,r})(r,t)}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(r){return!1}}function _construct(r,t,e){return(_construct=_isNativeReflectConstruct()?Reflect.construct:function(r,t,e){var n=[null];n.push.apply(n,t);t=new(Function.bind.apply(r,n));return e&&_setPrototypeOf(t,e.prototype),t}).apply(null,arguments)}function _isNativeFunction(r){return-1!==Function.toString.call(r).indexOf("[native code]")}function _wrapNativeSuper(r){var e="function"==typeof Map?new Map:void 0;return(_wrapNativeSuper=function(r){if(null===r||!_isNativeFunction(r))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(r))return e.get(r);e.set(r,t)}function t(){return _construct(r,arguments,_getPrototypeOf(this).constructor)}return t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(t,r)})(r)}function _assertThisInitialized(r){if(void 0===r)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function _possibleConstructorReturn(r,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(r)}function _createSuper(e){var n=_isNativeReflectConstruct();return function(){var r,t=_getPrototypeOf(e);return _possibleConstructorReturn(this,n?(r=_getPrototypeOf(this).constructor,Reflect.construct(t,arguments,r)):t.apply(this,arguments))}}function _toConsumableArray(r){return _arrayWithoutHoles(r)||_iterableToArray(r)||_unsupportedIterableToArray(r)||_nonIterableSpread()}function _arrayWithoutHoles(r){if(Array.isArray(r))return _arrayLikeToArray(r)}function _iterableToArray(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}function _unsupportedIterableToArray(r,t){if(r){if("string"==typeof r)return _arrayLikeToArray(r,t);var e=Object.prototype.toString.call(r).slice(8,-1);return"Map"===(e="Object"===e&&r.constructor?r.constructor.name:e)||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?_arrayLikeToArray(r,t):void 0}}function _arrayLikeToArray(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function isOperator(r){return-1<"+-*/%()".indexOf(r)}function getPrioraty(r){switch(r){case"+":case"-":return 1;case"*":case"/":case"%":return 2;default:return 0}}function prioraty(r,t){return getPrioraty(r)<=getPrioraty(t)}function isObj(r){return"[object Object]"===Object.prototype.toString.call(r)&&!Array.isArray(r)}function parseArgs(r){var t={expr:"",fmt:null,data:null},e="",n=r[0];if(1===r.length)"string"==typeof n?e=n:"number"==typeof n?e=n.toString():Array.isArray(n)&&(e=n[0]);else if(1<r.length){n=r[r.length-1];if(isObj(n))e=r[0],t.data=n;else for(var o=_toConsumableArray(r.shift());o.length||r.length;)var i=0===o.length?"":o.shift(),a=0===r.length?"":r.shift(),e=e+i+(a="number"==typeof a?a.toString():a)}var n=e.split("|");return 1===n.length?t.expr=n[0]:(t.expr=n[0],""!==(n=n[1]).trim()&&(t.fmt=n)),t}function format(r,t){var e="",n=(e=BigNumber.isBigNumber(r)?r.toFixed():"string"!=typeof r?r.toString():r,null),r=null,o=null,i=t.match(/(<=|>=|=)\s*(\d+)/);if(i&&(r=i[1],n=Number(i[2])),t.includes(",")&&(o=!0),null!==n){var i=e.split("."),t=i[0],a=1===i.length?"":i[1],l=a.length;switch(r){case"<=":a=l<=n?a:a.slice(0,n);break;case"=":l<n?a+="0".repeat(n-l):n<l&&(a=a.slice(0,n));break;case">=":a=n<=l?a:a+"0".repeat(n-l)}e=""===a?t:"".concat(t,".").concat(a)}return e=null!==o?1<(i=e.split(".")).length?((r=i[0]).includes("-")?i[0]=r[0]+r.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):i[0]=r.replace(/(?=(?!^)(?:\d{3})+$)/g,","),i.join(".")):(t=i[0]).includes("-")?t[0]+t.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):t.replace(/(?=(?!^)(?:\d{3})+$)/g,","):e}function tokenizer(r){for(var t=[],e=0,n=null,o=r.length;e<o;)if(n=r[e],/\s/.test(n))e++;else if("+-".includes(n)){var i=t[t.length-1];if(0===t.length||"+-".includes(i)||"("===i){for(var a=n,n=r[++e];/[a-zA-Z\d._]/.test(n);)a+=n,n=r[++e];t.push(a)}else t.push(n),e++}else if("*/%()".includes(n))t.push(n),e++;else if(/[a-zA-Z_]/.test(n)){for(var l="";/[a-zA-Z0-9_]/.test(n)&&(l+=n,!(++e>=o));)n=r[e];t.push(l)}else if(/\d/.test(n)){for(var u="";/[\d.]/.test(n)&&(u+=n,!(++e>=o));)n=r[e];t.push(u)}return t}var CalculatorError=function(){_inherits(n,_wrapNativeSuper(Error));var e=_createSuper(n);function n(r){var t;return _classCallCheck(this,n),(t=e.call(this,r)).name="CalculatorError",t.message=r,t}return _createClass(n)}(),TokensFillError$1=function(){_inherits(n,_wrapNativeSuper(Error));var e=_createSuper(n);function n(r){var t;return _classCallCheck(this,n),(t=e.call(this,r)).name="TokensFillError",t.message=r,t}return _createClass(n)}();function fillTokens(r,t){var e=t._fillData;return void 0===t._fillData&&(e=t),r.map(function(r){if(/^[a-zA-z_][\w_]*$/.test(r)){var t=e[r];if(void 0!==t)return"number"==typeof t?t.toString():t;throw new TokensFillError$1("错误的参数:".concat(r," 请确认他存在"))}return r})}function fmt(){for(var r=arguments.length,t=new Array(r),e=0;e<r;e++)t[e]=arguments[e];var n=parseArgs(t),o=tokenizer(n.expr),i=null;if(2<o.length)throw new Error("fmt并非用于计算, 不能传入多个标识:".concat(n.expr));if(1!==o.length)throw new Error("fmt接收了一个无法被解析的标识");if(null!==n.data)if(null===(i=void 0!==n.data._fillData?n.data:i)||void 0===i.fillError&&void 0===i.error)o=fillTokens(o,n.data);else try{o=fillTokens(o,n.data)}catch(r){if(r instanceof TokensFillError)return i.fillError||i.error;throw r}if(null===n.fmt)throw"表达式没有格式化部分";return format(o[0],n.fmt)}var version="0.0.36";function token2postfix(r){for(var t=[],e=[],n=r;0<n.length;){var o=n.shift();if(isOperator(o))if("("===o)t.push(o);else if(")"===o){for(var i=t.pop();"("!==i&&0<t.length;)e.push(i),i=t.pop();if("("!==i)throw"error: unmatched ()"}else{for(;prioraty(o,t[t.length-1])&&0<t.length;)e.push(t.pop());t.push(o)}else e.push(o)}if(0<t.length){if(")"===t[t.length-1]||"("===t[t.length-1])throw"error: unmatched ()";for(;0<t.length;)e.push(t.pop())}return e}function evalPostfix(r){for(var t=[];0<r.length;){var e=r.shift();if(isOperator(e)){if(t.length<2)throw new CalculatorError("错误的栈长度, 可能是无法计算的表达式");var n=t.pop(),o=t.pop();if("string"==typeof n&&!BigNumber.isBigNumber(n)){if(!/^[+-]*[\d.]+$/.test(n))throw new CalculatorError("".concat(n,"不是一个合法的数字"));n=new BigNumber(n)}if("string"==typeof o&&!BigNumber.isBigNumber(o)){if(!/^[+-]*[\d.]+$/.test(o))throw new CalculatorError("".concat(o,"不是一个合法的数字"));o=new BigNumber(o)}switch(e){case"+":t.push(o.plus(n));break;case"-":t.push(o.minus(n));break;case"*":t.push(o.times(n));break;case"/":t.push(o.div(n));break;case"%":t.push(o.mod(n))}}else t.push(e)}if(1!==t.length)throw"unvalid expression";return t[0]}function calc(){for(var r=arguments.length,t=new Array(r),e=0;e<r;e++)t[e]=arguments[e];var n=parseArgs(t),o=tokenizer(n.expr),i=null;if(null!==n.data)if(null===(i=void 0!==n.data._fillData?n.data:i)||void 0===i.fillError&&void 0===i.error)o=fillTokens(o,n.data);else try{o=fillTokens(o,n.data)}catch(r){if(r instanceof TokensFillError$1)return void 0!==i.warn&&!0===i.warn&&console.warn(r),i.fillError||i.error;throw r}var o=token2postfix(o),a=null;if(null!==i){if(void 0!==i.calcError||void 0!==i.error)try{a=evalPostfix(o)}catch(r){if(r instanceof CalculatorError)return void 0!==i.warn&&!0===i.warn&&console.warn(r),void 0!==i.calcError?i.calcError:i.error;throw r}}else a=evalPostfix(o);return a=null!==n.fmt?format(a,n.fmt):null!==a?a.toFixed():null}export{calc,fmt,version};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "a-calc",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
4
4
|
"description": "JavaScript的字符串四则运算库, 支持格式化操作例如: 千分位格式化, 灵活指定小数点位数",
|
|
5
|
-
"main": "./
|
|
5
|
+
"main": "./cjs/index.js",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"import": "./es/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
],
|
|
36
36
|
"repository": {
|
|
37
37
|
"type": "git",
|
|
38
|
-
"url": "git+https://github.com/Autumn-one/a-calc
|
|
38
|
+
"url": "git+https://github.com/Autumn-one/a-calc.git"
|
|
39
39
|
},
|
|
40
40
|
"keywords": [
|
|
41
41
|
"四则运算",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"author": "Autumn",
|
|
48
48
|
"license": "MPL-2.0",
|
|
49
49
|
"bugs": {
|
|
50
|
-
"url": "https://github.com/Autumn-one/a-calc
|
|
50
|
+
"url": "https://github.com/Autumn-one/a-calc/issues"
|
|
51
51
|
},
|
|
52
|
-
"homepage": "https://github.com/Autumn-one/a-calc
|
|
52
|
+
"homepage": "https://github.com/Autumn-one/a-calc#readme",
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@babel/core": "^7.17.10",
|
|
55
55
|
"@babel/preset-env": "^7.17.10",
|
|
@@ -68,6 +68,6 @@
|
|
|
68
68
|
"rollup-plugin-uglify": "^6.0.4"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"
|
|
71
|
+
"bignumber.js": "^9.0.2"
|
|
72
72
|
}
|
|
73
73
|
}
|