-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathjs-big-decimal.min.js
1 lines (1 loc) · 11.4 KB
/
js-big-decimal.min.js
1
var bigDecimal;!function(){"use strict";var n={165:function(n,e){Object.defineProperty(e,"__esModule",{value:!0}),e.abs=void 0,e.abs=function(n){return"number"!=typeof n&&"bigint"!=typeof n||(n=n.toString()),"-"==n[0]?n.substring(1):n}},217:function(n,e){function t(n){if(u(n))return n;for(var e="",t=n.length,r=n.split(".")[1],i=r?r.length:0,a=0;a<t;a++)n[a]>="0"&&n[a]<="9"?e+=9-parseInt(n[a]):e+=n[a];return o(e,i>0?"0."+new Array(i).join("0")+"1":"1")}function r(n){var e=n.split(".");for(e[0]||(e[0]="0");"0"==e[0][0]&&e[0].length>1;)e[0]=e[0].substring(1);return e[0]+(e[1]?"."+e[1]:"")}function i(n,e){var t=n.split("."),r=e.split("."),i=t[0].length,o=r[0].length;return i>o?r[0]=new Array(Math.abs(i-o)+1).join("0")+(r[0]?r[0]:""):t[0]=new Array(Math.abs(i-o)+1).join("0")+(t[0]?t[0]:""),i=t[1]?t[1].length:0,o=r[1]?r[1].length:0,(i||o)&&(i>o?r[1]=(r[1]?r[1]:"")+new Array(Math.abs(i-o)+1).join("0"):t[1]=(t[1]?t[1]:"")+new Array(Math.abs(i-o)+1).join("0")),[n=t[0]+(t[1]?"."+t[1]:""),e=r[0]+(r[1]?"."+r[1]:"")]}function o(n,e){var t;n=(t=i(n,e))[0],e=t[1];for(var r="",o=0,u=n.length-1;u>=0;u--)if("."!==n[u]){var a=parseInt(n[u])+parseInt(e[u])+o;r=a%10+r,o=Math.floor(a/10)}else r="."+r;return o?o.toString()+r:r}function u(n){return/^0[0]*[.]{0,1}[0]*$/.test(n)}Object.defineProperty(e,"__esModule",{value:!0}),e.pad=e.trim=e.add=void 0,e.add=function(n,e){var a;void 0===e&&(e="0");var s=0,d=-1;"-"==n[0]&&(u(n=n.substring(1))||(s++,d=1,n.length)),"-"==e[0]&&(u(e=e.substring(1))||(s++,d=2,e.length)),n=r(n),e=r(e),n=(a=i(r(n),r(e)))[0],e=a[1],1==s&&(1===d?n=t(n):2===d&&(e=t(e)));var l=o(n,e);return s?2==s?"-"+r(l):n.length<l.length?r(l.substring(1)):"-"+r(t(l)):r(l)},e.trim=r,e.pad=i},664:function(n,e,t){Object.defineProperty(e,"__esModule",{value:!0}),e.compareTo=void 0;var r=t(217),i=t(859);e.compareTo=function(n,e){var t,o,u=!1;if(t=[n,e].map((function(n){return(0,i.stripTrailingZero)(n)})),n=t[0],e=t[1],"-"==n[0]&&"-"!=e[0])return-1;if("-"!=n[0]&&"-"==e[0])return 1;if("-"==n[0]&&"-"==e[0]&&(n=n.substr(1),e=e.substr(1),u=!0),n=(o=(0,r.pad)(n,e))[0],e=o[1],0==n.localeCompare(e))return 0;for(var a=0;a<n.length;a++)if(n[a]!=e[a])return n[a]>e[a]?u?-1:1:u?1:-1;return 0}},415:function(n,e,t){Object.defineProperty(e,"__esModule",{value:!0}),e.divide=void 0;var r=t(217),i=t(350),o=t(916);e.divide=function(n,e,t,u){if(void 0===t&&(t=8),void 0===u&&(u=o.RoundingModes.HALF_EVEN),0==e)throw new Error("Cannot divide by 0");if(n=n.toString(),e=e.toString(),n=n.replace(/(\.\d*?[1-9])0+$/g,"$1").replace(/\.0+$/,""),e=e.replace(/(\.\d*?[1-9])0+$/g,"$1").replace(/\.0+$/,""),0==n)return"0";var a=0;"-"==e[0]&&(e=e.substring(1),a++),"-"==n[0]&&(n=n.substring(1),a++);var s=e.indexOf(".")>0?e.length-e.indexOf(".")-1:-1;if(e=(0,r.trim)(e.replace(".","")),s>=0){var d=n.indexOf(".")>0?n.length-n.indexOf(".")-1:-1;if(-1==d)n=(0,r.trim)(n+new Array(s+1).join("0"));else if(s>d)n=n.replace(".",""),n=(0,r.trim)(n+new Array(s-d+1).join("0"));else if(s<d){var l=(n=n.replace(".","")).length-d+s;n=(0,r.trim)(n.substring(0,l)+"."+n.substring(l))}else s==d&&(n=(0,r.trim)(n.replace(".","")))}var f=0,g=e.length,v="",p=n.indexOf(".")>-1&&n.indexOf(".")<g?n.substring(0,g+1):n.substring(0,g);if(n=n.indexOf(".")>-1&&n.indexOf(".")<g?n.substring(g+1):n.substring(g),p.indexOf(".")>-1){var c=p.length-p.indexOf(".")-1;g>(p=p.replace(".","")).length&&(c+=g-p.length,p+=new Array(g-p.length+1).join("0")),f=c,v="0."+new Array(c).join("0")}for(t+=2;f<=t;){for(var h=0;parseInt(p)>=parseInt(e);)p=(0,r.add)(p,"-"+e),h++;v+=h,n?("."==n[0]&&(v+=".",f++,n=n.substring(1)),p+=n.substring(0,1),n=n.substring(1)):(f||(v+="."),f++,p+="0")}return(1==a?"-":"")+(0,r.trim)((0,i.roundOff)(v,t-2,u))}},213:function(n,e,t){Object.defineProperty(e,"__esModule",{value:!0}),e.modulus=void 0;var r=t(415),i=t(350),o=t(182),u=t(26),a=t(916);function s(n){if(-1!=n.indexOf("."))throw new Error("Modulus of non-integers not supported")}e.modulus=function(n,e){if(0==e)throw new Error("Cannot divide by 0");n=n.toString(),e=e.toString(),s(n),s(e);var t="";return"-"==n[0]&&(t="-",n=n.substr(1)),"-"==e[0]&&(e=e.substr(1)),t+(0,u.subtract)(n,(0,o.multiply)(e,(0,i.roundOff)((0,r.divide)(n,e),0,a.RoundingModes.FLOOR)))}},182:function(n,e,t){Object.defineProperty(e,"__esModule",{value:!0}),e.multiply=void 0;var r=t(859);e.multiply=function(n,e){n=n.toString(),e=e.toString();var t=0;"-"==n[0]&&(t++,n=n.substr(1)),"-"==e[0]&&(t++,e=e.substr(1)),n=(0,r.stripTrailingZero)(n),e=(0,r.stripTrailingZero)(e);var i=0,o=0;-1!=n.indexOf(".")&&(i=n.length-n.indexOf(".")-1),-1!=e.indexOf(".")&&(o=e.length-e.indexOf(".")-1);var u=i+o;if(n=(0,r.stripTrailingZero)(n.replace(".","")),e=(0,r.stripTrailingZero)(e.replace(".","")),n.length<e.length){var a=n;n=e,e=a}if("0"==e)return"0";for(var s,d,l=e.length,f=0,g=[],v=l-1,p="",c=0;c<l;c++)g[c]=n.length-1;for(c=0;c<2*n.length;c++){for(var h=0,b=e.length-1;b>=v&&b>=0;b--)g[b]>-1&&g[b]<n.length&&(h+=parseInt(n[g[b]--])*parseInt(e[b]));h+=f,f=Math.floor(h/10),p=h%10+p,v--}return p=(0,r.stripTrailingZero)((s=p,0==(d=u)?s:(s=d>=s.length?new Array(d-s.length+1).join("0")+s:s).substr(0,s.length-d)+"."+s.substr(s.length-d,d))),1==t&&(p="-"+p),p}},350:function(n,e,t){Object.defineProperty(e,"__esModule",{value:!0}),e.roundOff=void 0;var r=t(916);function i(n,e,t,i){if(!n||n===new Array(n.length+1).join("0"))return!1;if(i===r.RoundingModes.DOWN||!t&&i===r.RoundingModes.FLOOR||t&&i===r.RoundingModes.CEILING)return!1;if(i===r.RoundingModes.UP||t&&i===r.RoundingModes.FLOOR||!t&&i===r.RoundingModes.CEILING)return!0;var o="5"+new Array(n.length).join("0");if(n>o)return!0;if(n<o)return!1;switch(i){case r.RoundingModes.HALF_DOWN:return!1;case r.RoundingModes.HALF_UP:return!0;case r.RoundingModes.HALF_EVEN:default:return parseInt(e[e.length-1])%2==1}}function o(n,e){void 0===e&&(e=0),e||(e=1),"number"==typeof n&&n.toString();for(var t="",r=n.length-1;r>=0;r--){var i=parseInt(n[r])+e;10==i?(e=1,i=0):e=0,t+=i}return e&&(t+=e),t.split("").reverse().join("")}e.roundOff=function n(e,t,u){if(void 0===t&&(t=0),void 0===u&&(u=r.RoundingModes.HALF_EVEN),u===r.RoundingModes.UNNECESSARY)throw new Error("UNNECESSARY Rounding Mode has not yet been implemented");"number"!=typeof e&&"bigint"!=typeof e||(e=e.toString());var a=!1;"-"===e[0]&&(a=!0,e=e.substring(1));var s=e.split("."),d=s[0],l=s[1];if(t<0){if(t=-t,d.length<=t)return"0";var f=d.substr(0,d.length-t);return(a?"-":"")+(f=n(e=f+"."+d.substr(d.length-t)+l,0,u))+new Array(t+1).join("0")}if(0==t){d.length;return i(s[1],d,a,u)&&(d=o(d)),(a&&parseInt(d)?"-":"")+d}if(!s[1])return(a?"-":"")+d+"."+new Array(t+1).join("0");if(s[1].length<t)return(a?"-":"")+d+"."+s[1]+new Array(t-s[1].length+1).join("0");l=s[1].substring(0,t);var g=s[1].substring(t);return g&&i(g,l,a,u)&&(l=o(l)).length>t?(a?"-":"")+o(d,parseInt(l[0]))+"."+l.substring(1):(a&&(parseInt(d)||parseInt(l))?"-":"")+d+"."+l}},916:function(n,e){Object.defineProperty(e,"__esModule",{value:!0}),e.RoundingModes=void 0,function(n){n[n.CEILING=0]="CEILING",n[n.DOWN=1]="DOWN",n[n.FLOOR=2]="FLOOR",n[n.HALF_DOWN=3]="HALF_DOWN",n[n.HALF_EVEN=4]="HALF_EVEN",n[n.HALF_UP=5]="HALF_UP",n[n.UNNECESSARY=6]="UNNECESSARY",n[n.UP=7]="UP"}(e.RoundingModes||(e.RoundingModes={}))},859:function(n,e){Object.defineProperty(e,"__esModule",{value:!0}),e.stripTrailingZero=void 0,e.stripTrailingZero=function(n){var e="-"===n[0];for(e&&(n=n.substr(1));"0"==n[0];)n=n.substr(1);if(-1!=n.indexOf("."))for(;"0"==n[n.length-1];)n=n.substr(0,n.length-1);return""==n||"."==n?n="0":"."==n[n.length-1]&&(n=n.substr(0,n.length-1)),"."==n[0]&&(n="0"+n),e&&"0"!=n&&(n="-"+n),n}},26:function(n,e,t){Object.defineProperty(e,"__esModule",{value:!0}),e.negate=e.subtract=void 0;var r=t(217);function i(n){return n="-"==n[0]?n.substr(1):"-"+n}e.subtract=function(n,e){return n=n.toString(),e=i(e=e.toString()),(0,r.add)(n,e)},e.negate=i}},e={};function t(r){var i=e[r];if(void 0!==i)return i.exports;var o=e[r]={exports:{}};return n[r](o,o.exports,t),o.exports}var r={};!function(){var n=r;var e=t(217),i=t(165),o=t(350),u=t(182),a=t(415),s=t(213),d=t(664),l=t(26),f=t(916),g=t(859),v=function(){function n(e){void 0===e&&(e="0"),this.value=n.validate(e)}return n.validate=function(n){if(n){if(n=n.toString(),isNaN(n))throw Error("Parameter is not a number: "+n);"+"==n[0]&&(n=n.substring(1))}else n="0";if(n.startsWith(".")?n="0"+n:n.startsWith("-.")&&(n="-0"+n.substr(1)),/e/i.test(n)){var t=n.split(/[eE]/),r=t[0],i=t[1],o="";"-"==(r=(0,e.trim)(r))[0]&&(o="-",r=r.substring(1)),r.indexOf(".")>=0?(i=parseInt(i)+r.indexOf("."),r=r.replace(".","")):i=parseInt(i)+r.length,n=r.length<i?o+r+new Array(i-r.length+1).join("0"):r.length>=i&&i>0?o+(0,e.trim)(r.substring(0,i))+(r.length>i?"."+r.substring(i):""):o+"0."+new Array(1-i).join("0")+r}return n},n.prototype.getValue=function(){return this.value},n.prototype.setValue=function(e){this.value=n.validate(e)},n.getPrettyValue=function(e,t,r){void 0===t&&(t=3),void 0===r&&(r=",");var i="-"==(e=n.validate(e)).charAt(0);i&&(e=e.substring(1));for(var o=e.indexOf("."),u="",a=o=o>0?o:e.length;a>0;)a<t?(t=a,a=0):a-=t,u=e.substring(a,a+t)+(a<o-t&&a>=0?r:"")+u;return(i?"-":"")+u+e.substring(o)},n.prototype.getPrettyValue=function(e,t){return void 0===e&&(e=3),void 0===t&&(t=","),n.getPrettyValue(this.value,e,t)},n.round=function(e,t,r){if(void 0===t&&(t=0),void 0===r&&(r=f.RoundingModes.HALF_EVEN),e=n.validate(e),isNaN(t))throw Error("Precision is not a number: "+t);return(0,o.roundOff)(e,t,r)},n.prototype.round=function(e,t){if(void 0===e&&(e=0),void 0===t&&(t=f.RoundingModes.HALF_EVEN),isNaN(e))throw Error("Precision is not a number: "+e);return new n((0,o.roundOff)(this.value,e,t))},n.abs=function(e){return e=n.validate(e),(0,i.abs)(e)},n.prototype.abs=function(){return new n((0,i.abs)(this.value))},n.floor=function(e){return-1===(e=n.validate(e)).indexOf(".")?e:n.round(e,0,f.RoundingModes.FLOOR)},n.prototype.floor=function(){return-1===this.value.indexOf(".")?new n(this.value):new n(this.value).round(0,f.RoundingModes.FLOOR)},n.ceil=function(e){return-1===(e=n.validate(e)).indexOf(".")?e:n.round(e,0,f.RoundingModes.CEILING)},n.prototype.ceil=function(){return-1===this.value.indexOf(".")?new n(this.value):new n(this.value).round(0,f.RoundingModes.CEILING)},n.add=function(t,r){return t=n.validate(t),r=n.validate(r),(0,e.add)(t,r)},n.prototype.add=function(t){return new n((0,e.add)(this.value,t.getValue()))},n.subtract=function(e,t){return e=n.validate(e),t=n.validate(t),(0,l.subtract)(e,t)},n.prototype.subtract=function(e){return new n((0,l.subtract)(this.value,e.getValue()))},n.multiply=function(e,t){return e=n.validate(e),t=n.validate(t),(0,u.multiply)(e,t)},n.prototype.multiply=function(e){return new n((0,u.multiply)(this.value,e.getValue()))},n.divide=function(e,t,r,i){return e=n.validate(e),t=n.validate(t),(0,a.divide)(e,t,r,i)},n.prototype.divide=function(e,t,r){return new n((0,a.divide)(this.value,e.getValue(),t,r))},n.modulus=function(e,t){return e=n.validate(e),t=n.validate(t),(0,s.modulus)(e,t)},n.prototype.modulus=function(e){return new n((0,s.modulus)(this.value,e.getValue()))},n.compareTo=function(e,t){return e=n.validate(e),t=n.validate(t),(0,d.compareTo)(e,t)},n.prototype.compareTo=function(n){return(0,d.compareTo)(this.value,n.getValue())},n.negate=function(e){return e=n.validate(e),(0,l.negate)(e)},n.prototype.negate=function(){return new n((0,l.negate)(this.value))},n.stripTrailingZero=function(e){return e=n.validate(e),(0,g.stripTrailingZero)(e)},n.prototype.stripTrailingZero=function(){return new n((0,g.stripTrailingZero)(this.value))},n.RoundingModes=f.RoundingModes,n}();n.default=v}(),bigDecimal=r.default}();