diff --git a/CHANGELOG.md b/CHANGELOG.md index dea6a73..f1cb0a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ + #### 9.0.1 * 15/12/2017 * #80 Typings: correct return type. diff --git a/decimal.d.ts b/decimal.d.ts index 0b0446b..16a688e 100644 --- a/decimal.d.ts +++ b/decimal.d.ts @@ -194,6 +194,7 @@ export declare class Decimal { squareRoot(): Decimal; sqrt(): Decimal; + nthRoot(root: Decimal): Decimal; tangent() : Decimal; tan() : Decimal; diff --git a/decimal.js b/decimal.js index d69768e..d72d09f 100644 --- a/decimal.js +++ b/decimal.js @@ -1690,105 +1690,111 @@ }; - /* - * Return a new Decimal whose value is the square root of this Decimal, rounded to `precision` - * significant digits using rounding mode `rounding`. - * - * sqrt(-n) = N - * sqrt(N) = N - * sqrt(-I) = N - * sqrt(I) = I - * sqrt(0) = 0 - * sqrt(-0) = -0 - * - */ - P.squareRoot = P.sqrt = function () { - var m, n, sd, r, rep, t, - x = this, - d = x.d, - e = x.e, - s = x.s, - Ctor = x.constructor; + /* + * Return a new Decimal whose value is the square root of this Decimal, rounded to `precision` + * significant digits using rounding mode `rounding`. + */ +P.squareRoot = P.sqrt = function () { + return this.nthRoot(2); +}; - // Negative/NaN/Infinity/zero? - if (s !== 1 || !d || !d[0]) { - return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0); - } +/* + * Return a new Decimal whose value is the nth root of this Decimal, rounded to `precision` + * significant digits using rounding mode `rounding`. + */ +P.nthRoot = function (root) { + var m, n, sd, r, rep, t, + x = this, + d = x.d, + e = x.e, + s = x.s, + Ctor = x.constructor; - external = false; + // Negative/NaN/Infinity/zero? + if (s !== 1 || !d || !d[0]) { + return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0); + } - // Initial estimate. - s = Math.sqrt(+x); + external = false; - // Math.sqrt underflow/overflow? - // Pass x to Math.sqrt as integer, then adjust the exponent of the result. - if (s == 0 || s == 1 / 0) { - n = digitsToString(d); + // Initial estimate. + s = Math.pow(+x, 1/root); - if ((n.length + e) % 2 == 0) n += '0'; - s = Math.sqrt(n); - e = mathfloor((e + 1) / 2) - (e < 0 || e % 2); + // Math.sqrt underflow/overflow? + // Pass x to Math.sqrt as integer, then adjust the exponent of the result. + if (s == 0 || s == 1 / 0) { + n = digitsToString(d); - if (s == 1 / 0) { - n = '1e' + e; - } else { - n = s.toExponential(); - n = n.slice(0, n.indexOf('e') + 1) + e; - } + if ((n.length + e) % 2 == 0) n += '0'; + s = Math.pow(n, 1/root); + e = mathfloor((e + 1) / 2) - (e < 0 || e % 2); - r = new Ctor(n); + if (s == 1 / 0) { + n = '1e' + e; } else { - r = new Ctor(s.toString()); + n = s.toExponential(); + n = n.slice(0, n.indexOf('e') + 1) + e; } - sd = (e = Ctor.precision) + 3; + r = new Ctor(n); + } else { + r = new Ctor(s.toString()); + } - // Newton-Raphson iteration. - for (;;) { - t = r; - r = t.plus(divide(x, t, sd + 2, 1)).times(0.5); + sd = (e = Ctor.precision) + 3 * root - // TODO? Replace with for-loop and checkRoundingDigits. - if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) { - n = n.slice(sd - 3, sd + 1); + root = new Ctor(root.toString()); - // The 4th rounding digit may be in error by -1 so if the 4 rounding digits are 9999 or - // 4999, i.e. approaching a rounding boundary, continue the iteration. - if (n == '9999' || !rep && n == '4999') { + /* + Algorithm from https://rosettacode.org/wiki/Nth_root#JavaScript + */ + for (;;) { + t = r; + //divide(x, t, sd + 2, 1) + r = root.minus(1).times(t).plus(divide(x,t.pow(root.minus(1)), sd + 3*root, 5)).dividedBy(root); - // On the first iteration only, check to see if rounding up gives the exact result as the - // nines may infinitely repeat. - if (!rep) { - finalise(t, e + 1, 0); + // TODO? Replace with for-loop and checkRoundingDigits. + if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) { + n = n.slice(sd - 3, sd + 1); - if (t.times(t).eq(x)) { - r = t; - break; - } + // The 4th rounding digit may be in error by -1 so if the 4 rounding digits are 9999 or + // 4999, i.e. approaching a rounding boundary, continue the iteration. + if (n == '9999' || !rep && n == '4999') { + + // On the first iteration only, check to see if rounding up gives the exact result as the + // nines may infinitely repeat. + if (!rep) { + finalise(t, e + 1, 0); + + if (t.pow(root).eq(x)) { + r = t; + break; } - - sd += 4; - rep = 1; - } else { - - // If the rounding digits are null, 0{0,4} or 50{0,3}, check for an exact result. - // If not, then there are further digits and m will be truthy. - if (!+n || !+n.slice(1) && n.charAt(0) == '5') { - - // Truncate to the first rounding digit. - finalise(r, e + 1, 1); - m = !r.times(r).eq(x); - } - - break; } + + sd += 4; + rep = 1; + } else { + + // If the rounding digits are null, 0{0,4} or 50{0,3}, check for an exact result. + // If not, then there are further digits and m will be truthy. + if (!+n || !+n.slice(1) && n.charAt(0) == '5') { + + // Truncate to the first rounding digit. + finalise(r, e + 1, 1); + m = !r.pow(root).eq(x); + } + + break; } } + } - external = true; + external = true; + + return finalise(r, e, Ctor.rounding, m); +}; - return finalise(r, e, Ctor.rounding, m); - }; /* diff --git a/decimal.min.js b/decimal.min.js index 226c8fc..cf628d9 100644 --- a/decimal.min.js +++ b/decimal.min.js @@ -1,3 +1 @@ -/* decimal.js v9.0.1 https://github.com/MikeMcl/decimal.js/LICENCE */ -!function(n){"use strict";function e(n){var e,i,t,r=n.length-1,s="",o=n[0];if(r>0){for(s+=o,e=1;r>e;e++)t=n[e]+"",i=Un-t.length,i&&(s+=d(i)),s+=t;o=n[e],t=o+"",i=Un-t.length,i&&(s+=d(i))}else if(0===o)return"0";for(;o%10===0;)o/=10;return s+o}function i(n,e,i){if(n!==~~n||e>n||n>i)throw Error(yn+n)}function t(n,e,i,t){var r,s,o,u;for(s=n[0];s>=10;s/=10)--e;return--e<0?(e+=Un,r=0):(r=Math.ceil((e+1)/Un),e%=Un),s=Fn(10,Un-e),u=n[r]%s|0,null==t?3>e?(0==e?u=u/100|0:1==e&&(u=u/10|0),o=4>i&&99999==u||i>3&&49999==u||5e4==u||0==u):o=(4>i&&u+1==s||i>3&&u+1==s/2)&&(n[r+1]/s/100|0)==Fn(10,e-2)-1||(u==s/2||0==u)&&0==(n[r+1]/s/100|0):4>e?(0==e?u=u/1e3|0:1==e?u=u/100|0:2==e&&(u=u/10|0),o=(t||4>i)&&9999==u||!t&&i>3&&4999==u):o=((t||4>i)&&u+1==s||!t&&i>3&&u+1==s/2)&&(n[r+1]/s/1e3|0)==Fn(10,e-3)-1,o}function r(n,e,i){for(var t,r,s=[0],o=0,u=n.length;u>o;){for(r=s.length;r--;)s[r]*=e;for(s[0]+=vn.indexOf(n.charAt(o++)),t=0;ti-1&&(void 0===s[t+1]&&(s[t+1]=0),s[t+1]+=s[t]/i|0,s[t]%=i)}return s.reverse()}function s(n,e){var i,t,r=e.d.length;32>r?(i=Math.ceil(r/3),t=Math.pow(4,-i).toString()):(i=16,t="2.3283064365386962890625e-10"),n.precision+=i,e=E(n,1,e.times(t),new n(1));for(var s=i;s--;){var o=e.times(e);e=o.times(o).minus(o).times(8).plus(1)}return n.precision-=i,e}function o(n,e,i,t){var r,s,o,u,c,f,a,h,d,l=n.constructor;n:if(null!=e){if(h=n.d,!h)return n;for(r=1,u=h[0];u>=10;u/=10)r++;if(s=e-r,0>s)s+=Un,o=e,a=h[d=0],c=a/Fn(10,r-o-1)%10|0;else if(d=Math.ceil((s+1)/Un),u=h.length,d>=u){if(!t)break n;for(;u++<=d;)h.push(0);a=c=0,r=1,s%=Un,o=s-Un+1}else{for(a=u=h[d],r=1;u>=10;u/=10)r++;s%=Un,o=s-Un+r,c=0>o?0:a/Fn(10,r-o-1)%10|0}if(t=t||0>e||void 0!==h[d+1]||(0>o?a:a%Fn(10,r-o-1)),f=4>i?(c||t)&&(0==i||i==(n.s<0?3:2)):c>5||5==c&&(4==i||t||6==i&&(s>0?o>0?a/Fn(10,r-o):0:h[d-1])%10&1||i==(n.s<0?8:7)),1>e||!h[0])return h.length=0,f?(e-=n.e+1,h[0]=Fn(10,(Un-e%Un)%Un),n.e=-e||0):h[0]=n.e=0,n;if(0==s?(h.length=d,u=1,d--):(h.length=d+1,u=Fn(10,Un-s),h[d]=o>0?(a/Fn(10,r-o)%Fn(10,o)|0)*u:0),f)for(;;){if(0==d){for(s=1,o=h[0];o>=10;o/=10)s++;for(o=h[0]+=u,u=1;o>=10;o/=10)u++;s!=u&&(n.e++,h[0]==Ln&&(h[0]=1));break}if(h[d]+=u,h[d]!=Ln)break;h[d--]=0,u=1}for(s=h.length;0===h[--s];)h.pop()}return En&&(n.e>l.maxE?(n.d=null,n.e=NaN):n.e0?o=o.charAt(0)+"."+o.slice(1)+d(r):u>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(n.e<0?"e":"e+")+n.e):0>s?(o="0."+d(-s-1)+o,t&&(r=t-u)>0&&(o+=d(r))):s>=u?(o+=d(s+1-u),t&&(r=t-s-1)>0&&(o=o+"."+d(r))):((r=s+1)0&&(s+1===u&&(o+="."),o+=d(r))),o}function c(n,e){var i=n[0];for(e*=Un;i>=10;i/=10)e++;return e}function f(n,e,i){if(e>kn)throw En=!0,i&&(n.precision=i),Error(qn);return o(new n(Nn),e,1,!0)}function a(n,e,i){if(e>Sn)throw Error(qn);return o(new n(bn),e,i,!0)}function h(n){var e=n.length-1,i=e*Un+1;if(e=n[e]){for(;e%10==0;e/=10)i--;for(e=n[0];e>=10;e/=10)i++}return i}function d(n){for(var e="";n--;)e+="0";return e}function l(n,e,i,t){var r,s=new n(1),o=Math.ceil(t/Un+4);for(En=!1;;){if(i%2&&(s=s.times(e),q(s.d,o)&&(r=!0)),i=Dn(i/2),0===i){i=s.d.length-1,r&&0===s.d[i]&&++s.d[i];break}e=e.times(e),q(e.d,o)}return En=!0,s}function p(n){return 1&n.d[n.d.length-1]}function g(n,e,i){for(var t,r=new n(e[0]),s=0;++s17)return new g(n.d?n.d[0]?n.s<0?0:1/0:1:n.s?n.s<0?0:n:NaN);for(null==i?(En=!1,h=m):h=i,a=new g(.03125);n.e>-2;)n=n.times(a),p+=5;for(s=Math.log(Fn(2,p))/Math.LN10*2+5|0,h+=s,r=c=f=new g(1),g.precision=h;;){if(c=o(c.times(n),h,1),r=r.times(++l),a=f.plus(Cn(c,r,h,1)),e(a.d).slice(0,h)===e(f.d).slice(0,h)){for(u=p;u--;)f=o(f.times(f),h,1);if(null!=i)return g.precision=m,f;if(!(3>d&&t(f.d,h-s,w,d)))return o(f,g.precision=m,w,En=!0);g.precision=h+=10,r=c=a=new g(1),l=0,d++}f=a}}function m(n,i){var r,s,u,c,a,h,d,l,p,g,w,v=1,N=10,b=n,x=b.d,E=b.constructor,M=E.rounding,y=E.precision;if(b.s<0||!x||!x[0]||!b.e&&1==x[0]&&1==x.length)return new E(x&&!x[0]?-1/0:1!=b.s?NaN:x?0:b);if(null==i?(En=!1,p=y):p=i,E.precision=p+=N,r=e(x),s=r.charAt(0),!(Math.abs(c=b.e)<15e14))return l=f(E,p+2,y).times(c+""),b=m(new E(s+"."+r.slice(1)),p-N).plus(l),E.precision=y,null==i?o(b,y,M,En=!0):b;for(;7>s&&1!=s||1==s&&r.charAt(1)>3;)b=b.times(n),r=e(b.d),s=r.charAt(0),v++;for(c=b.e,s>1?(b=new E("0."+r),c++):b=new E(s+"."+r.slice(1)),g=b,d=a=b=Cn(b.minus(1),b.plus(1),p,1),w=o(b.times(b),p,1),u=3;;){if(a=o(a.times(w),p,1),l=d.plus(Cn(a,new E(u),p,1)),e(l.d).slice(0,p)===e(d.d).slice(0,p)){if(d=d.times(2),0!==c&&(d=d.plus(f(E,p+2,y).times(c+""))),d=Cn(d,new E(v),p,1),null!=i)return E.precision=y,d;if(!t(d.d,p-N,M,h))return o(d,E.precision=y,M,En=!0);E.precision=p+=N,l=a=b=Cn(g.minus(1),g.plus(1),p,1),w=o(b.times(b),p,1),u=h=1}d=l,u+=2}}function v(n){return String(n.s*n.s/0)}function N(n,e){var i,t,r;for((i=e.indexOf("."))>-1&&(e=e.replace(".","")),(t=e.search(/e/i))>0?(0>i&&(i=t),i+=+e.slice(t+1),e=e.substring(0,t)):0>i&&(i=e.length),t=0;48===e.charCodeAt(t);t++);for(r=e.length;48===e.charCodeAt(r-1);--r);if(e=e.slice(t,r)){if(r-=t,n.e=i=i-t-1,n.d=[],t=(i+1)%Un,0>i&&(t+=Un),r>t){for(t&&n.d.push(+e.slice(0,t)),r-=Un;r>t;)n.d.push(+e.slice(t,t+=Un));e=e.slice(t),t=Un-e.length}else t-=r;for(;t--;)e+="0";n.d.push(+e),En&&(n.e>n.constructor.maxE?(n.d=null,n.e=NaN):n.e0?(a=+e.slice(o+1),e=e.substring(2,o)):e=e.slice(2),o=e.indexOf("."),u=o>=0,t=n.constructor,u&&(e=e.replace(".",""),f=e.length,o=f-o,s=l(t,new t(i),o,2*o)),h=r(e,i,Ln),d=h.length-1,o=d;0===h[o];--o)h.pop();return 0>o?new t(0*n.s):(n.e=c(h,d),n.d=h,En=!1,u&&(n=Cn(n,s,4*f)),a&&(n=n.times(Math.abs(a)<54?Math.pow(2,a):dn.pow(2,a))),En=!0,n)}function x(n,e){var i,t=e.d.length;if(3>t)return E(n,2,e,e);i=1.4*Math.sqrt(t),i=i>16?16:0|i,e=e.times(Math.pow(5,-i)),e=E(n,2,e,e);for(var r,s=new n(5),o=new n(16),u=new n(20);i--;)r=e.times(e),e=e.times(s.plus(r.times(o.times(r).minus(u))));return e}function E(n,e,i,t,r){var s,o,u,c,f=1,a=n.precision,h=Math.ceil(a/Un);for(En=!1,c=i.times(i),u=new n(t);;){if(o=Cn(u.times(c),new n(e++*e++),a,1),u=r?t.plus(o):t.minus(o),t=Cn(o.times(c),new n(e++*e++),a,1),o=u.plus(t),void 0!==o.d[h]){for(s=h;o.d[s]===u.d[s]&&s--;);if(-1==s)break}s=u,u=t,t=o,o=s,f++}return En=!0,o.d.length=h+1,o}function M(n,e){var i,t=e.s<0,r=a(n,n.precision,1),s=r.times(.5);if(e=e.abs(),e.lte(s))return gn=t?4:1,e;if(i=e.divToInt(r),i.isZero())gn=t?3:2;else{if(e=e.minus(i.times(r)),e.lte(s))return gn=p(i)?t?2:3:t?4:1,e;gn=p(i)?t?1:4:t?3:2}return e.minus(r).abs()}function y(n,e,t,s){var o,c,f,a,h,d,l,p,g,w=n.constructor,m=void 0!==t;if(m?(i(t,1,mn),void 0===s?s=w.rounding:i(s,0,8)):(t=w.precision,s=w.rounding),n.isFinite()){for(l=u(n),f=l.indexOf("."),m?(o=2,16==e?t=4*t-3:8==e&&(t=3*t-2)):o=e,f>=0&&(l=l.replace(".",""),g=new w(1),g.e=l.length-f,g.d=r(u(g),10,o),g.e=g.d.length),p=r(l,10,o),c=h=p.length;0==p[--h];)p.pop();if(p[0]){if(0>f?c--:(n=new w(n),n.d=p,n.e=c,n=Cn(n,g,t,s,0,o),p=n.d,c=n.e,d=ln),f=p[t],a=o/2,d=d||void 0!==p[t+1],d=4>s?(void 0!==f||d)&&(0===s||s===(n.s<0?3:2)):f>a||f===a&&(4===s||d||6===s&&1&p[t-1]||s===(n.s<0?8:7)),p.length=t,d)for(;++p[--t]>o-1;)p[t]=0,t||(++c,p.unshift(1));for(h=p.length;!p[h-1];--h);for(f=0,l="";h>f;f++)l+=vn.charAt(p[f]);if(m){if(h>1)if(16==e||8==e){for(f=16==e?4:3,--h;h%f;h++)l+="0";for(p=r(l,o,e),h=p.length;!p[h-1];--h);for(f=1,l="1.";h>f;f++)l+=vn.charAt(p[f])}else l=l.charAt(0)+"."+l.slice(1);l=l+(0>c?"p":"p+")+c}else if(0>c){for(;++c;)l="0"+l;l="0."+l}else if(++c>h)for(c-=h;c--;)l+="0";else h>c&&(l=l.slice(0,c)+"."+l.slice(c))}else l=m?"0p+0":"0";l=(16==e?"0x":2==e?"0b":8==e?"0o":"")+l}else l=v(n);return n.s<0?"-"+l:l}function q(n,e){return n.length>e?(n.length=e,!0):void 0}function O(n){return new this(n).abs()}function D(n){return new this(n).acos()}function F(n){return new this(n).acosh()}function A(n,e){return new this(n).plus(e)}function Z(n){return new this(n).asin()}function P(n){return new this(n).asinh()}function R(n){return new this(n).atan()}function L(n){return new this(n).atanh()}function U(n,e){n=new this(n),e=new this(e);var i,t=this.precision,r=this.rounding,s=t+4;return n.s&&e.s?n.d||e.d?!e.d||n.isZero()?(i=e.s<0?a(this,t,r):new this(0),i.s=n.s):!n.d||e.isZero()?(i=a(this,s,1).times(.5),i.s=n.s):e.s<0?(this.precision=s,this.rounding=1,i=this.atan(Cn(n,e,s,1)),e=a(this,s,1),this.precision=t,this.rounding=r,i=n.s<0?i.minus(e):i.plus(e)):i=this.atan(Cn(n,e,s,1)):(i=a(this,s,1).times(e.s>0?.25:.75),i.s=n.s):i=new this(NaN),i}function _(n){return new this(n).cbrt()}function k(n){return o(n=new this(n),n.e+1,2)}function S(n){if(!n||"object"!=typeof n)throw Error(Mn+"Object expected");var e,i,t,r=n.defaults===!0,s=["precision",1,mn,"rounding",0,8,"toExpNeg",-wn,0,"toExpPos",0,wn,"maxE",0,wn,"minE",-wn,0,"modulo",0,9];for(e=0;e=s[e+1]&&t<=s[e+2]))throw Error(yn+i+": "+t);this[i]=t}if(i="crypto",r&&(this[i]=xn[i]),void 0!==(t=n[i])){if(t!==!0&&t!==!1&&0!==t&&1!==t)throw Error(yn+i+": "+t);if(t){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw Error(On);this[i]=!0}else this[i]=!1}return this}function T(n){return new this(n).cos()}function C(n){return new this(n).cosh()}function I(n){function e(n){var i,t,r,s=this;if(!(s instanceof e))return new e(n);if(s.constructor=e,n instanceof e)return s.s=n.s,s.e=n.e,void(s.d=(n=n.d)?n.slice():n);if(r=typeof n,"number"===r){if(0===n)return s.s=0>1/n?-1:1,s.e=0,void(s.d=[0]);if(0>n?(n=-n,s.s=-1):s.s=1,n===~~n&&1e7>n){for(i=0,t=n;t>=10;t/=10)i++;return s.e=i,void(s.d=[n])}return 0*n!==0?(n||(s.s=NaN),s.e=NaN,void(s.d=null)):N(s,n.toString())}if("string"!==r)throw Error(yn+n);return 45===n.charCodeAt(0)?(n=n.slice(1),s.s=-1):s.s=1,Rn.test(n)?N(s,n):b(s,n)}var i,t,r;if(e.prototype=Tn,e.ROUND_UP=0,e.ROUND_DOWN=1,e.ROUND_CEIL=2,e.ROUND_FLOOR=3,e.ROUND_HALF_UP=4,e.ROUND_HALF_DOWN=5,e.ROUND_HALF_EVEN=6,e.ROUND_HALF_CEIL=7,e.ROUND_HALF_FLOOR=8,e.EUCLID=9,e.config=e.set=S,e.clone=I,e.isDecimal=$,e.abs=O,e.acos=D,e.acosh=F,e.add=A,e.asin=Z,e.asinh=P,e.atan=R,e.atanh=L,e.atan2=U,e.cbrt=_,e.ceil=k,e.cos=T,e.cosh=C,e.div=H,e.exp=B,e.floor=V,e.hypot=j,e.ln=W,e.log=J,e.log10=G,e.log2=z,e.max=K,e.min=Q,e.mod=X,e.mul=Y,e.pow=nn,e.random=en,e.round=tn,e.sign=rn,e.sin=sn,e.sinh=on,e.sqrt=un,e.sub=cn,e.tan=fn,e.tanh=an,e.trunc=hn,void 0===n&&(n={}),n&&n.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],i=0;io;)s=e[o],s>=429e7?e[o]=crypto.getRandomValues(new Uint32Array(1))[0]:c[o++]=s%1e7;else{if(!crypto.randomBytes)throw Error(On);for(e=crypto.randomBytes(r*=4);r>o;)s=e[o]+(e[o+1]<<8)+(e[o+2]<<16)+((127&e[o+3])<<24),s>=214e7?crypto.randomBytes(4).copy(e,o):(c.push(s%1e7),o+=4);o=r/4}else for(;r>o;)c[o++]=1e7*Math.random()|0;for(r=c[--o],n%=Un,r&&n&&(s=Fn(10,Un-n),c[o]=(r/s|0)*s);0===c[o];o--)c.pop();if(0>o)t=0,c=[0];else{for(t=-1;0===c[0];t-=Un)c.shift();for(r=1,s=c[0];s>=10;s/=10)r++;Un>r&&(t-=Un-r)}return u.e=t,u.d=c,u}function tn(n){return o(n=new this(n),n.e+1,this.rounding)}function rn(n){return n=new this(n),n.d?n.d[0]?n.s:0*n.s:n.s||NaN}function sn(n){return new this(n).sin()}function on(n){return new this(n).sinh()}function un(n){return new this(n).sqrt()}function cn(n,e){return new this(n).sub(e)}function fn(n){return new this(n).tan()}function an(n){return new this(n).tanh()}function hn(n){return o(n=new this(n),n.e+1,1)}var dn,ln,pn,gn,wn=9e15,mn=1e9,vn="0123456789abcdef",Nn="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",bn="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",xn={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-wn,maxE:wn,crypto:!1},En=!0,Mn="[DecimalError] ",yn=Mn+"Invalid argument: ",qn=Mn+"Precision limit exceeded",On=Mn+"crypto unavailable",Dn=Math.floor,Fn=Math.pow,An=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Zn=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Pn=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Rn=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Ln=1e7,Un=7,_n=9007199254740991,kn=Nn.length-1,Sn=bn.length-1,Tn={name:"[object Decimal]"};Tn.absoluteValue=Tn.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),o(n)},Tn.ceil=function(){return o(new this.constructor(this),this.e+1,2)},Tn.comparedTo=Tn.cmp=function(n){var e,i,t,r,s=this,o=s.d,u=(n=new s.constructor(n)).d,c=s.s,f=n.s;if(!o||!u)return c&&f?c!==f?c:o===u?0:!o^0>c?1:-1:NaN;if(!o[0]||!u[0])return o[0]?c:u[0]?-f:0;if(c!==f)return c;if(s.e!==n.e)return s.e>n.e^0>c?1:-1;for(t=o.length,r=u.length,e=0,i=r>t?t:r;i>e;++e)if(o[e]!==u[e])return o[e]>u[e]^0>c?1:-1;return t===r?0:t>r^0>c?1:-1},Tn.cosine=Tn.cos=function(){var n,e,i=this,t=i.constructor;return i.d?i.d[0]?(n=t.precision,e=t.rounding,t.precision=n+Math.max(i.e,i.sd())+Un,t.rounding=1,i=s(t,M(t,i)),t.precision=n,t.rounding=e,o(2==gn||3==gn?i.neg():i,n,e,!0)):new t(1):new t(NaN)},Tn.cubeRoot=Tn.cbrt=function(){var n,i,t,r,s,u,c,f,a,h,d=this,l=d.constructor;if(!d.isFinite()||d.isZero())return new l(d);for(En=!1,u=d.s*Math.pow(d.s*d,1/3),u&&Math.abs(u)!=1/0?r=new l(u.toString()):(t=e(d.d),n=d.e,(u=(n-t.length+1)%3)&&(t+=1==u||-2==u?"0":"00"),u=Math.pow(t,1/3),n=Dn((n+1)/3)-(n%3==(0>n?-1:2)),u==1/0?t="5e"+n:(t=u.toExponential(),t=t.slice(0,t.indexOf("e")+1)+n),r=new l(t),r.s=d.s),c=(n=l.precision)+3;;)if(f=r,a=f.times(f).times(f),h=a.plus(d),r=Cn(h.plus(d).times(f),h.plus(a),c+2,1),e(f.d).slice(0,c)===(t=e(r.d)).slice(0,c)){if(t=t.slice(c-3,c+1),"9999"!=t&&(s||"4999"!=t)){(!+t||!+t.slice(1)&&"5"==t.charAt(0))&&(o(r,n+1,1),i=!r.times(r).times(r).eq(d));break}if(!s&&(o(f,n+1,0),f.times(f).times(f).eq(d))){r=f;break}c+=4,s=1}return En=!0,o(r,n,l.rounding,i)},Tn.decimalPlaces=Tn.dp=function(){var n,e=this.d,i=NaN;if(e){if(n=e.length-1,i=(n-Dn(this.e/Un))*Un,n=e[n])for(;n%10==0;n/=10)i--;0>i&&(i=0)}return i},Tn.dividedBy=Tn.div=function(n){return Cn(this,new this.constructor(n))},Tn.dividedToIntegerBy=Tn.divToInt=function(n){var e=this,i=e.constructor;return o(Cn(e,new i(n),0,1,1),i.precision,i.rounding)},Tn.equals=Tn.eq=function(n){return 0===this.cmp(n)},Tn.floor=function(){return o(new this.constructor(this),this.e+1,3)},Tn.greaterThan=Tn.gt=function(n){return this.cmp(n)>0},Tn.greaterThanOrEqualTo=Tn.gte=function(n){var e=this.cmp(n);return 1==e||0===e},Tn.hyperbolicCosine=Tn.cosh=function(){var n,e,i,t,r,s=this,u=s.constructor,c=new u(1);if(!s.isFinite())return new u(s.s?1/0:NaN);if(s.isZero())return c;i=u.precision,t=u.rounding,u.precision=i+Math.max(s.e,s.sd())+4,u.rounding=1,r=s.d.length,32>r?(n=Math.ceil(r/3),e=Math.pow(4,-n).toString()):(n=16,e="2.3283064365386962890625e-10"),s=E(u,1,s.times(e),new u(1),!0);for(var f,a=n,h=new u(8);a--;)f=s.times(s),s=c.minus(f.times(h.minus(f.times(h))));return o(s,u.precision=i,u.rounding=t,!0)},Tn.hyperbolicSine=Tn.sinh=function(){var n,e,i,t,r=this,s=r.constructor;if(!r.isFinite()||r.isZero())return new s(r);if(e=s.precision,i=s.rounding,s.precision=e+Math.max(r.e,r.sd())+4,s.rounding=1,t=r.d.length,3>t)r=E(s,2,r,r,!0);else{n=1.4*Math.sqrt(t),n=n>16?16:0|n,r=r.times(Math.pow(5,-n)),r=E(s,2,r,r,!0);for(var u,c=new s(5),f=new s(16),a=new s(20);n--;)u=r.times(r),r=r.times(c.plus(u.times(f.times(u).plus(a))))}return s.precision=e,s.rounding=i,o(r,e,i,!0)},Tn.hyperbolicTangent=Tn.tanh=function(){var n,e,i=this,t=i.constructor;return i.isFinite()?i.isZero()?new t(i):(n=t.precision,e=t.rounding,t.precision=n+7,t.rounding=1,Cn(i.sinh(),i.cosh(),t.precision=n,t.rounding=e)):new t(i.s)},Tn.inverseCosine=Tn.acos=function(){var n,e=this,i=e.constructor,t=e.abs().cmp(1),r=i.precision,s=i.rounding;return-1!==t?0===t?e.isNeg()?a(i,r,s):new i(0):new i(NaN):e.isZero()?a(i,r+4,s).times(.5):(i.precision=r+6,i.rounding=1,e=e.asin(),n=a(i,r+4,s).times(.5),i.precision=r,i.rounding=s,n.minus(e))},Tn.inverseHyperbolicCosine=Tn.acosh=function(){var n,e,i=this,t=i.constructor;return i.lte(1)?new t(i.eq(1)?0:NaN):i.isFinite()?(n=t.precision,e=t.rounding,t.precision=n+Math.max(Math.abs(i.e),i.sd())+4,t.rounding=1,En=!1,i=i.times(i).minus(1).sqrt().plus(i),En=!0,t.precision=n,t.rounding=e,i.ln()):new t(i)},Tn.inverseHyperbolicSine=Tn.asinh=function(){var n,e,i=this,t=i.constructor;return!i.isFinite()||i.isZero()?new t(i):(n=t.precision,e=t.rounding,t.precision=n+2*Math.max(Math.abs(i.e),i.sd())+6,t.rounding=1,En=!1,i=i.times(i).plus(1).sqrt().plus(i),En=!0,t.precision=n,t.rounding=e,i.ln())},Tn.inverseHyperbolicTangent=Tn.atanh=function(){var n,e,i,t,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,e=s.rounding,t=r.sd(),Math.max(t,n)<2*-r.e-1?o(new s(r),n,e,!0):(s.precision=i=t-r.e,r=Cn(r.plus(1),new s(1).minus(r),i+n,1),s.precision=n+4,s.rounding=1,r=r.ln(),s.precision=n,s.rounding=e,r.times(.5))):new s(NaN)},Tn.inverseSine=Tn.asin=function(){var n,e,i,t,r=this,s=r.constructor;return r.isZero()?new s(r):(e=r.abs().cmp(1),i=s.precision,t=s.rounding,-1!==e?0===e?(n=a(s,i+4,t).times(.5),n.s=r.s,n):new s(NaN):(s.precision=i+6,s.rounding=1,r=r.div(new s(1).minus(r.times(r)).sqrt().plus(1)).atan(),s.precision=i,s.rounding=t,r.times(2)))},Tn.inverseTangent=Tn.atan=function(){var n,e,i,t,r,s,u,c,f,h=this,d=h.constructor,l=d.precision,p=d.rounding;if(h.isFinite()){if(h.isZero())return new d(h);if(h.abs().eq(1)&&Sn>=l+4)return u=a(d,l+4,p).times(.25),u.s=h.s,u}else{if(!h.s)return new d(NaN);if(Sn>=l+4)return u=a(d,l+4,p).times(.5),u.s=h.s,u}for(d.precision=c=l+10,d.rounding=1,i=Math.min(28,c/Un+2|0),n=i;n;--n)h=h.div(h.times(h).plus(1).sqrt().plus(1));for(En=!1,e=Math.ceil(c/Un),t=1,f=h.times(h),u=new d(h),r=h;-1!==n;)if(r=r.times(f),s=u.minus(r.div(t+=2)),r=r.times(f),u=s.plus(r.div(t+=2)),void 0!==u.d[e])for(n=e;u.d[n]===s.d[n]&&n--;);return i&&(u=u.times(2<this.d.length-2},Tn.isNaN=function(){return!this.s},Tn.isNegative=Tn.isNeg=function(){return this.s<0},Tn.isPositive=Tn.isPos=function(){return this.s>0},Tn.isZero=function(){return!!this.d&&0===this.d[0]},Tn.lessThan=Tn.lt=function(n){return this.cmp(n)<0},Tn.lessThanOrEqualTo=Tn.lte=function(n){return this.cmp(n)<1},Tn.logarithm=Tn.log=function(n){var i,r,s,u,c,a,h,d,l=this,p=l.constructor,g=p.precision,w=p.rounding,v=5;if(null==n)n=new p(10),i=!0;else{if(n=new p(n),r=n.d,n.s<0||!r||!r[0]||n.eq(1))return new p(NaN);i=n.eq(10)}if(r=l.d,l.s<0||!r||!r[0]||l.eq(1))return new p(r&&!r[0]?-1/0:1!=l.s?NaN:r?0:1/0);if(i)if(r.length>1)c=!0;else{for(u=r[0];u%10===0;)u/=10;c=1!==u}if(En=!1,h=g+v,a=m(l,h),s=i?f(p,h+10):m(n,h),d=Cn(a,s,h,1),t(d.d,u=g,w))do if(h+=10,a=m(l,h),s=i?f(p,h+10):m(n,h),d=Cn(a,s,h,1),!c){+e(d.d).slice(u+1,u+15)+1==1e14&&(d=o(d,g+1,0));break}while(t(d.d,u+=10,w));return En=!0,o(d,g,w)},Tn.minus=Tn.sub=function(n){var e,i,t,r,s,u,f,a,h,d,l,p,g=this,w=g.constructor;if(n=new w(n),!g.d||!n.d)return g.s&&n.s?g.d?n.s=-n.s:n=new w(n.d||g.s!==n.s?g:NaN):n=new w(NaN),n;if(g.s!=n.s)return n.s=-n.s,g.plus(n);if(h=g.d,p=n.d,f=w.precision,a=w.rounding,!h[0]||!p[0]){if(p[0])n.s=-n.s;else{if(!h[0])return new w(3===a?-0:0);n=new w(g)}return En?o(n,f,a):n}if(i=Dn(n.e/Un),d=Dn(g.e/Un),h=h.slice(),s=d-i){for(l=0>s,l?(e=h,s=-s,u=p.length):(e=p,i=d,u=h.length),t=Math.max(Math.ceil(f/Un),u)+2,s>t&&(s=t,e.length=1),e.reverse(),t=s;t--;)e.push(0);e.reverse()}else{for(t=h.length,u=p.length,l=u>t,l&&(u=t),t=0;u>t;t++)if(h[t]!=p[t]){l=h[t]0;--t)h[u++]=0;for(t=p.length;t>s;){if(h[--t]r?(i=h,r=-r,u=d.length):(i=d,t=s,u=h.length),s=Math.ceil(f/Un),u=s>u?s+1:u+1,r>u&&(r=u,i.length=1),i.reverse();r--;)i.push(0);i.reverse()}for(u=h.length,r=d.length,0>u-r&&(r=u,i=d,d=h,h=i),e=0;r;)e=(h[--r]=h[r]+d[r]+e)/Ln|0,h[r]%=Ln;for(e&&(h.unshift(e),++t),u=h.length;0==h[--u];)h.pop();return n.d=h,n.e=c(h,t),En?o(n,f,a):n},Tn.precision=Tn.sd=function(n){var e,i=this;if(void 0!==n&&n!==!!n&&1!==n&&0!==n)throw Error(yn+n);return i.d?(e=h(i.d),n&&i.e+1>e&&(e=i.e+1)):e=NaN,e},Tn.round=function(){var n=this,e=n.constructor;return o(new e(n),n.e+1,e.rounding)},Tn.sine=Tn.sin=function(){var n,e,i=this,t=i.constructor;return i.isFinite()?i.isZero()?new t(i):(n=t.precision,e=t.rounding,t.precision=n+Math.max(i.e,i.sd())+Un,t.rounding=1,i=x(t,M(t,i)),t.precision=n,t.rounding=e,o(gn>2?i.neg():i,n,e,!0)):new t(NaN)},Tn.squareRoot=Tn.sqrt=function(){var n,i,t,r,s,u,c=this,f=c.d,a=c.e,h=c.s,d=c.constructor;if(1!==h||!f||!f[0])return new d(!h||0>h&&(!f||f[0])?NaN:f?c:1/0);for(En=!1,h=Math.sqrt(+c),0==h||h==1/0?(i=e(f),(i.length+a)%2==0&&(i+="0"),h=Math.sqrt(i),a=Dn((a+1)/2)-(0>a||a%2),h==1/0?i="1e"+a:(i=h.toExponential(),i=i.slice(0,i.indexOf("e")+1)+a),r=new d(i)):r=new d(h.toString()),t=(a=d.precision)+3;;)if(u=r,r=u.plus(Cn(c,u,t+2,1)).times(.5),e(u.d).slice(0,t)===(i=e(r.d)).slice(0,t)){if(i=i.slice(t-3,t+1),"9999"!=i&&(s||"4999"!=i)){(!+i||!+i.slice(1)&&"5"==i.charAt(0))&&(o(r,a+1,1),n=!r.times(r).eq(c));break}if(!s&&(o(u,a+1,0),u.times(u).eq(c))){r=u;break}t+=4,s=1}return En=!0,o(r,a,d.rounding,n)},Tn.tangent=Tn.tan=function(){var n,e,i=this,t=i.constructor;return i.isFinite()?i.isZero()?new t(i):(n=t.precision,e=t.rounding,t.precision=n+10,t.rounding=1,i=i.sin(),i.s=1,i=Cn(i,new t(1).minus(i.times(i)).sqrt(),n+10,0),t.precision=n,t.rounding=e,o(2==gn||4==gn?i.neg():i,n,e,!0)):new t(NaN)},Tn.times=Tn.mul=function(n){var e,i,t,r,s,u,f,a,h,d=this,l=d.constructor,p=d.d,g=(n=new l(n)).d;if(n.s*=d.s,!(p&&p[0]&&g&&g[0]))return new l(!n.s||p&&!p[0]&&!g||g&&!g[0]&&!p?NaN:p&&g?0*n.s:n.s/0);for(i=Dn(d.e/Un)+Dn(n.e/Un),a=p.length,h=g.length,h>a&&(s=p,p=g,g=s,u=a,a=h,h=u),s=[],u=a+h,t=u;t--;)s.push(0);for(t=h;--t>=0;){for(e=0,r=a+t;r>t;)f=s[r]+g[t]*p[r-t-1]+e,s[r--]=f%Ln|0,e=f/Ln|0;s[r]=(s[r]+e)%Ln|0}for(;!s[--u];)s.pop();return e?++i:s.shift(),n.d=s,n.e=c(s,i),En?o(n,l.precision,l.rounding):n},Tn.toBinary=function(n,e){return y(this,2,n,e)},Tn.toDecimalPlaces=Tn.toDP=function(n,e){var t=this,r=t.constructor;return t=new r(t),void 0===n?t:(i(n,0,mn),void 0===e?e=r.rounding:i(e,0,8),o(t,n+t.e+1,e))},Tn.toExponential=function(n,e){var t,r=this,s=r.constructor;return void 0===n?t=u(r,!0):(i(n,0,mn),void 0===e?e=s.rounding:i(e,0,8),r=o(new s(r),n+1,e),t=u(r,!0,n+1)),r.isNeg()&&!r.isZero()?"-"+t:t},Tn.toFixed=function(n,e){var t,r,s=this,c=s.constructor;return void 0===n?t=u(s):(i(n,0,mn),void 0===e?e=c.rounding:i(e,0,8),r=o(new c(s),n+s.e+1,e),t=u(r,!1,n+r.e+1)),s.isNeg()&&!s.isZero()?"-"+t:t},Tn.toFraction=function(n){var i,t,r,s,o,u,c,f,a,d,l,p,g=this,w=g.d,m=g.constructor;if(!w)return new m(g);if(a=t=new m(1),r=f=new m(0),i=new m(r),o=i.e=h(w)-g.e-1,u=o%Un,i.d[0]=Fn(10,0>u?Un+u:u),null==n)n=o>0?i:a;else{if(c=new m(n),!c.isInt()||c.lt(a))throw Error(yn+c);n=c.gt(i)?o>0?i:a:c}for(En=!1,c=new m(e(w)),d=m.precision,m.precision=o=w.length*Un*2;l=Cn(c,i,0,1,1),s=t.plus(l.times(r)),1!=s.cmp(n);)t=r,r=s,s=a,a=f.plus(l.times(s)),f=s,s=i,i=c.minus(l.times(s)),c=s;return s=Cn(n.minus(t),r,0,1,1),f=f.plus(s.times(a)),t=t.plus(s.times(r)),f.s=a.s=g.s,p=Cn(a,r,o,1).minus(g).abs().cmp(Cn(f,t,o,1).minus(g).abs())<1?[a,r]:[f,t],m.precision=d,En=!0,p},Tn.toHexadecimal=Tn.toHex=function(n,e){return y(this,16,n,e)},Tn.toNearest=function(n,e){var t=this,r=t.constructor;if(t=new r(t),null==n){if(!t.d)return t;n=new r(1),e=r.rounding}else{if(n=new r(n),void 0!==e&&i(e,0,8),!t.d)return n.s?t:n;if(!n.d)return n.s&&(n.s=t.s),n}return n.d[0]?(En=!1,4>e&&(e=[4,5,7,8][e]),t=Cn(t,n,0,e,1).times(n),En=!0,o(t)):(n.s=t.s,t=n),t},Tn.toNumber=function(){return+this},Tn.toOctal=function(n,e){return y(this,8,n,e)},Tn.toPower=Tn.pow=function(n){var i,r,s,u,c,f,a=this,h=a.constructor,d=+(n=new h(n));if(!(a.d&&n.d&&a.d[0]&&n.d[0]))return new h(Fn(+a,d));if(a=new h(a),a.eq(1))return a;if(s=h.precision,c=h.rounding,n.eq(1))return o(a,s,c);if(i=Dn(n.e/Un),i>=n.d.length-1&&(r=0>d?-d:d)<=_n)return u=l(h,a,r,s),n.s<0?new h(1).div(u):o(u,s,c);if(f=a.s,0>f){if(ih.maxE+1||i0?f/0:0):(En=!1,h.rounding=a.s=1,r=Math.min(12,(i+"").length),u=w(n.times(m(a,s+r)),s),u.d&&(u=o(u,s+5,1),t(u.d,s,c)&&(i=s+10,u=o(w(n.times(m(a,i+r)),i),i+5,1),+e(u.d).slice(s+1,s+15)+1==1e14&&(u=o(u,s+1,0)))),u.s=f,En=!0,h.rounding=c,o(u,s,c))},Tn.toPrecision=function(n,e){var t,r=this,s=r.constructor;return void 0===n?t=u(r,r.e<=s.toExpNeg||r.e>=s.toExpPos):(i(n,1,mn),void 0===e?e=s.rounding:i(e,0,8),r=o(new s(r),n,e),t=u(r,n<=r.e||r.e<=s.toExpNeg,n)),r.isNeg()&&!r.isZero()?"-"+t:t},Tn.toSignificantDigits=Tn.toSD=function(n,e){var t=this,r=t.constructor;return void 0===n?(n=r.precision,e=r.rounding):(i(n,1,mn),void 0===e?e=r.rounding:i(e,0,8)),o(new r(t),n,e)},Tn.toString=function(){var n=this,e=n.constructor,i=u(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()&&!n.isZero()?"-"+i:i},Tn.truncated=Tn.trunc=function(){return o(new this.constructor(this),this.e+1,1)},Tn.valueOf=Tn.toJSON=function(){var n=this,e=n.constructor,i=u(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()?"-"+i:i};var Cn=function(){function n(n,e,i){var t,r=0,s=n.length;for(n=n.slice();s--;)t=n[s]*e+r,n[s]=t%i|0,r=t/i|0;return r&&n.unshift(r),n}function e(n,e,i,t){var r,s;if(i!=t)s=i>t?1:-1;else for(r=s=0;i>r;r++)if(n[r]!=e[r]){s=n[r]>e[r]?1:-1;break}return s}function i(n,e,i,t){for(var r=0;i--;)n[i]-=r,r=n[i]1;)n.shift()}return function(t,r,s,u,c,f){var a,h,d,l,p,g,w,m,v,N,b,x,E,M,y,q,O,D,F,A,Z=t.constructor,P=t.s==r.s?1:-1,R=t.d,L=r.d;if(!(R&&R[0]&&L&&L[0]))return new Z(t.s&&r.s&&(R?!L||R[0]!=L[0]:L)?R&&0==R[0]||!L?0*P:P/0:NaN);for(f?(p=1,h=t.e-r.e):(f=Ln,p=Un,h=Dn(t.e/p)-Dn(r.e/p)),F=L.length,O=R.length,v=new Z(P),N=v.d=[],d=0;L[d]==(R[d]||0);d++);if(L[d]>(R[d]||0)&&h--,null==s?(M=s=Z.precision,u=Z.rounding):M=c?s+(t.e-r.e)+1:s,0>M)N.push(1),g=!0;else{if(M=M/p+2|0,d=0,1==F){for(l=0,L=L[0],M++;(O>d||l)&&M--;d++)y=l*f+(R[d]||0),N[d]=y/L|0,l=y%L|0;g=l||O>d}else{for(l=f/(L[0]+1)|0,l>1&&(L=n(L,l,f),R=n(R,l,f),F=L.length,O=R.length),q=F,b=R.slice(0,F),x=b.length;F>x;)b[x++]=0;A=L.slice(),A.unshift(0),D=L[0],L[1]>=f/2&&++D;do l=0,a=e(L,b,F,x),0>a?(E=b[0],F!=x&&(E=E*f+(b[1]||0)),l=E/D|0,l>1?(l>=f&&(l=f-1),w=n(L,l,f),m=w.length,x=b.length,a=e(w,b,m,x),1==a&&(l--,i(w,m>F?A:L,m,f))):(0==l&&(a=l=1),w=L.slice()),m=w.length,x>m&&w.unshift(0),i(b,w,x,f),-1==a&&(x=b.length,a=e(L,b,F,x),1>a&&(l++,i(b,x>F?A:L,x,f))),x=b.length):0===a&&(l++,b=[0]),N[d++]=l,a&&b[0]?b[x++]=R[q]||0:(b=[R[q]],x=1);while((q++=10;l/=10)d++;v.e=d+h*p-1,o(v,c?s+v.e+1:s,u,g)}return v}}();dn=I(xn),dn["default"]=dn.Decimal=dn,Nn=new dn(Nn),bn=new dn(bn),"function"==typeof define&&define.amd?define(function(){return dn}):"undefined"!=typeof module&&module.exports?module.exports=dn:(n||(n="undefined"!=typeof self&&self&&self.self==self?self:Function("return this")()),pn=n.Decimal,dn.noConflict=function(){return n.Decimal=pn,dn},n.Decimal=dn)}(this); -//# sourceMappingURL=doc/decimal.js.map \ No newline at end of file +!function(n){"use strict";var e,i,t,r,s=9e15,o=1e9,u="0123456789abcdef",c="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",f="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",h={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-s,maxE:s,crypto:!1},a=!0,l="[DecimalError] ",d=l+"Invalid argument: ",p=l+"Precision limit exceeded",g=l+"crypto unavailable",w=Math.floor,m=Math.pow,v=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,N=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,b=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,x=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,E=1e7,M=7,y=c.length-1,q=f.length-1,O={name:"[object Decimal]"};function D(n){var e,i,t,r=n.length-1,s="",o=n[0];if(r>0){for(s+=o,e=1;ei)throw Error(d+n)}function A(n,e,i,t){var r,s,o,u;for(s=n[0];s>=10;s/=10)--e;return--e<0?(e+=M,r=0):(r=Math.ceil((e+1)/M),e%=M),s=m(10,M-e),u=n[r]%s|0,null==t?e<3?(0==e?u=u/100|0:1==e&&(u=u/10|0),o=i<4&&99999==u||i>3&&49999==u||5e4==u||0==u):o=(i<4&&u+1==s||i>3&&u+1==s/2)&&(n[r+1]/s/100|0)==m(10,e-2)-1||(u==s/2||0==u)&&0==(n[r+1]/s/100|0):e<4?(0==e?u=u/1e3|0:1==e?u=u/100|0:2==e&&(u=u/10|0),o=(t||i<4)&&9999==u||!t&&i>3&&4999==u):o=((t||i<4)&&u+1==s||!t&&i>3&&u+1==s/2)&&(n[r+1]/s/1e3|0)==m(10,e-3)-1,o}function Z(n,e,i){for(var t,r,s=[0],o=0,c=n.length;oi-1&&(void 0===s[t+1]&&(s[t+1]=0),s[t+1]+=s[t]/i|0,s[t]%=i)}return s.reverse()}O.absoluteValue=O.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),R(n)},O.ceil=function(){return R(new this.constructor(this),this.e+1,2)},O.comparedTo=O.cmp=function(n){var e,i,t,r,s=this,o=s.d,u=(n=new s.constructor(n)).d,c=s.s,f=n.s;if(!o||!u)return c&&f?c!==f?c:o===u?0:!o^c<0?1:-1:NaN;if(!o[0]||!u[0])return o[0]?c:u[0]?-f:0;if(c!==f)return c;if(s.e!==n.e)return s.e>n.e^c<0?1:-1;for(e=0,i=(t=o.length)<(r=u.length)?t:r;eu[e]^c<0?1:-1;return t===r?0:t>r^c<0?1:-1},O.cosine=O.cos=function(){var n,e,i=this,t=i.constructor;return i.d?i.d[0]?(n=t.precision,e=t.rounding,t.precision=n+Math.max(i.e,i.sd())+M,t.rounding=1,i=function(n,e){var i,t,r=e.d.length;r<32?(i=Math.ceil(r/3),t=Math.pow(4,-i).toString()):(i=16,t="2.3283064365386962890625e-10");n.precision+=i,e=W(n,1,e.times(t),new n(1));for(var s=i;s--;){var o=e.times(e);e=o.times(o).minus(o).times(8).plus(1)}return n.precision-=i,e}(t,J(t,i)),t.precision=n,t.rounding=e,R(2==r||3==r?i.neg():i,n,e,!0)):new t(1):new t(NaN)},O.cubeRoot=O.cbrt=function(){var n,e,i,t,r,s,o,u,c,f,h=this,l=h.constructor;if(!h.isFinite()||h.isZero())return new l(h);for(a=!1,(s=h.s*Math.pow(h.s*h,1/3))&&Math.abs(s)!=1/0?t=new l(s.toString()):(i=D(h.d),(s=((n=h.e)-i.length+1)%3)&&(i+=1==s||-2==s?"0":"00"),s=Math.pow(i,1/3),n=w((n+1)/3)-(n%3==(n<0?-1:2)),(t=new l(i=s==1/0?"5e"+n:(i=s.toExponential()).slice(0,i.indexOf("e")+1)+n)).s=h.s),o=(n=l.precision)+3;;)if(f=(c=(u=t).times(u).times(u)).plus(h),t=P(f.plus(h).times(u),f.plus(c),o+2,1),D(u.d).slice(0,o)===(i=D(t.d)).slice(0,o)){if("9999"!=(i=i.slice(o-3,o+1))&&(r||"4999"!=i)){+i&&(+i.slice(1)||"5"!=i.charAt(0))||(R(t,n+1,1),e=!t.times(t).times(t).eq(h));break}if(!r&&(R(u,n+1,0),u.times(u).times(u).eq(h))){t=u;break}o+=4,r=1}return a=!0,R(t,n,l.rounding,e)},O.decimalPlaces=O.dp=function(){var n,e=this.d,i=NaN;if(e){if(i=((n=e.length-1)-w(this.e/M))*M,n=e[n])for(;n%10==0;n/=10)i--;i<0&&(i=0)}return i},O.dividedBy=O.div=function(n){return P(this,new this.constructor(n))},O.dividedToIntegerBy=O.divToInt=function(n){var e=this.constructor;return R(P(this,new e(n),0,1,1),e.precision,e.rounding)},O.equals=O.eq=function(n){return 0===this.cmp(n)},O.floor=function(){return R(new this.constructor(this),this.e+1,3)},O.greaterThan=O.gt=function(n){return this.cmp(n)>0},O.greaterThanOrEqualTo=O.gte=function(n){var e=this.cmp(n);return 1==e||0===e},O.hyperbolicCosine=O.cosh=function(){var n,e,i,t,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;i=o.precision,t=o.rounding,o.precision=i+Math.max(s.e,s.sd())+4,o.rounding=1,(r=s.d.length)<32?(n=Math.ceil(r/3),e=Math.pow(4,-n).toString()):(n=16,e="2.3283064365386962890625e-10"),s=W(o,1,s.times(e),new o(1),!0);for(var c,f=n,h=new o(8);f--;)c=s.times(s),s=u.minus(c.times(h.minus(c.times(h))));return R(s,o.precision=i,o.rounding=t,!0)},O.hyperbolicSine=O.sinh=function(){var n,e,i,t,r=this,s=r.constructor;if(!r.isFinite()||r.isZero())return new s(r);if(e=s.precision,i=s.rounding,s.precision=e+Math.max(r.e,r.sd())+4,s.rounding=1,(t=r.d.length)<3)r=W(s,2,r,r,!0);else{n=(n=1.4*Math.sqrt(t))>16?16:0|n,r=W(s,2,r=r.times(Math.pow(5,-n)),r,!0);for(var o,u=new s(5),c=new s(16),f=new s(20);n--;)o=r.times(r),r=r.times(u.plus(o.times(c.times(o).plus(f))))}return s.precision=e,s.rounding=i,R(r,e,i,!0)},O.hyperbolicTangent=O.tanh=function(){var n,e,i=this,t=i.constructor;return i.isFinite()?i.isZero()?new t(i):(n=t.precision,e=t.rounding,t.precision=n+7,t.rounding=1,P(i.sinh(),i.cosh(),t.precision=n,t.rounding=e)):new t(i.s)},O.inverseCosine=O.acos=function(){var n,e=this,i=e.constructor,t=e.abs().cmp(1),r=i.precision,s=i.rounding;return-1!==t?0===t?e.isNeg()?k(i,r,s):new i(0):new i(NaN):e.isZero()?k(i,r+4,s).times(.5):(i.precision=r+6,i.rounding=1,e=e.asin(),n=k(i,r+4,s).times(.5),i.precision=r,i.rounding=s,n.minus(e))},O.inverseHyperbolicCosine=O.acosh=function(){var n,e,i=this,t=i.constructor;return i.lte(1)?new t(i.eq(1)?0:NaN):i.isFinite()?(n=t.precision,e=t.rounding,t.precision=n+Math.max(Math.abs(i.e),i.sd())+4,t.rounding=1,a=!1,i=i.times(i).minus(1).sqrt().plus(i),a=!0,t.precision=n,t.rounding=e,i.ln()):new t(i)},O.inverseHyperbolicSine=O.asinh=function(){var n,e,i=this,t=i.constructor;return!i.isFinite()||i.isZero()?new t(i):(n=t.precision,e=t.rounding,t.precision=n+2*Math.max(Math.abs(i.e),i.sd())+6,t.rounding=1,a=!1,i=i.times(i).plus(1).sqrt().plus(i),a=!0,t.precision=n,t.rounding=e,i.ln())},O.inverseHyperbolicTangent=O.atanh=function(){var n,e,i,t,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,e=s.rounding,t=r.sd(),Math.max(t,n)<2*-r.e-1?R(new s(r),n,e,!0):(s.precision=i=t-r.e,r=P(r.plus(1),new s(1).minus(r),i+n,1),s.precision=n+4,s.rounding=1,r=r.ln(),s.precision=n,s.rounding=e,r.times(.5))):new s(NaN)},O.inverseSine=O.asin=function(){var n,e,i,t,r=this,s=r.constructor;return r.isZero()?new s(r):(e=r.abs().cmp(1),i=s.precision,t=s.rounding,-1!==e?0===e?((n=k(s,i+4,t).times(.5)).s=r.s,n):new s(NaN):(s.precision=i+6,s.rounding=1,r=r.div(new s(1).minus(r.times(r)).sqrt().plus(1)).atan(),s.precision=i,s.rounding=t,r.times(2)))},O.inverseTangent=O.atan=function(){var n,e,i,t,r,s,o,u,c,f=this,h=f.constructor,l=h.precision,d=h.rounding;if(f.isFinite()){if(f.isZero())return new h(f);if(f.abs().eq(1)&&l+4<=q)return(o=k(h,l+4,d).times(.25)).s=f.s,o}else{if(!f.s)return new h(NaN);if(l+4<=q)return(o=k(h,l+4,d).times(.5)).s=f.s,o}for(h.precision=u=l+10,h.rounding=1,n=i=Math.min(28,u/M+2|0);n;--n)f=f.div(f.times(f).plus(1).sqrt().plus(1));for(a=!1,e=Math.ceil(u/M),t=1,c=f.times(f),o=new h(f),r=f;-1!==n;)if(r=r.times(c),s=o.minus(r.div(t+=2)),r=r.times(c),void 0!==(o=s.plus(r.div(t+=2))).d[e])for(n=e;o.d[n]===s.d[n]&&n--;);return i&&(o=o.times(2<this.d.length-2},O.isNaN=function(){return!this.s},O.isNegative=O.isNeg=function(){return this.s<0},O.isPositive=O.isPos=function(){return this.s>0},O.isZero=function(){return!!this.d&&0===this.d[0]},O.lessThan=O.lt=function(n){return this.cmp(n)<0},O.lessThanOrEqualTo=O.lte=function(n){return this.cmp(n)<1},O.logarithm=O.log=function(n){var e,i,t,r,s,o,u,c,f=this,h=f.constructor,l=h.precision,d=h.rounding;if(null==n)n=new h(10),e=!0;else{if(i=(n=new h(n)).d,n.s<0||!i||!i[0]||n.eq(1))return new h(NaN);e=n.eq(10)}if(i=f.d,f.s<0||!i||!i[0]||f.eq(1))return new h(i&&!i[0]?-1/0:1!=f.s?NaN:i?0:1/0);if(e)if(i.length>1)s=!0;else{for(r=i[0];r%10==0;)r/=10;s=1!==r}if(a=!1,o=V(f,u=l+5),t=e?_(h,u+10):V(n,u),A((c=P(o,t,u,1)).d,r=l,d))do{if(o=V(f,u+=10),t=e?_(h,u+10):V(n,u),c=P(o,t,u,1),!s){+D(c.d).slice(r+1,r+15)+1==1e14&&(c=R(c,l+1,0));break}}while(A(c.d,r+=10,d));return a=!0,R(c,l,d)},O.minus=O.sub=function(n){var e,i,t,r,s,o,u,c,f,h,l,d,p=this,g=p.constructor;if(n=new g(n),!p.d||!n.d)return p.s&&n.s?p.d?n.s=-n.s:n=new g(n.d||p.s!==n.s?p:NaN):n=new g(NaN),n;if(p.s!=n.s)return n.s=-n.s,p.plus(n);if(f=p.d,d=n.d,u=g.precision,c=g.rounding,!f[0]||!d[0]){if(d[0])n.s=-n.s;else{if(!f[0])return new g(3===c?-0:0);n=new g(p)}return a?R(n,u,c):n}if(i=w(n.e/M),h=w(p.e/M),f=f.slice(),s=h-i){for((l=s<0)?(e=f,s=-s,o=d.length):(e=d,i=h,o=f.length),s>(t=Math.max(Math.ceil(u/M),o)+2)&&(s=t,e.length=1),e.reverse(),t=s;t--;)e.push(0);e.reverse()}else{for((l=(t=f.length)<(o=d.length))&&(o=t),t=0;t0;--t)f[o++]=0;for(t=d.length;t>s;){if(f[--t](o=(s=Math.ceil(u/M))>o?s+1:o+1)&&(r=o,i.length=1),i.reverse();r--;)i.push(0);i.reverse()}for((o=f.length)-(r=h.length)<0&&(r=o,i=h,h=f,f=i),e=0;r;)e=(f[--r]=f[r]+h[r]+e)/E|0,f[r]%=E;for(e&&(f.unshift(e),++t),o=f.length;0==f[--o];)f.pop();return n.d=f,n.e=U(f,t),a?R(n,u,c):n},O.precision=O.sd=function(n){var e;if(void 0!==n&&n!==!!n&&1!==n&&0!==n)throw Error(d+n);return this.d?(e=S(this.d),n&&this.e+1>e&&(e=this.e+1)):e=NaN,e},O.round=function(){var n=this.constructor;return R(new n(this),this.e+1,n.rounding)},O.sine=O.sin=function(){var n,e,i=this,t=i.constructor;return i.isFinite()?i.isZero()?new t(i):(n=t.precision,e=t.rounding,t.precision=n+Math.max(i.e,i.sd())+M,t.rounding=1,i=function(n,e){var i,t=e.d.length;if(t<3)return W(n,2,e,e);i=(i=1.4*Math.sqrt(t))>16?16:0|i,e=e.times(Math.pow(5,-i)),e=W(n,2,e,e);for(var r,s=new n(5),o=new n(16),u=new n(20);i--;)r=e.times(e),e=e.times(s.plus(r.times(o.times(r).minus(u))));return e}(t,J(t,i)),t.precision=n,t.rounding=e,R(r>2?i.neg():i,n,e,!0)):new t(NaN)},O.squareRoot=O.sqrt=function(){var n,e,i,t,r,s,o=this,u=o.d,c=o.e,f=o.s,h=o.constructor;if(1!==f||!u||!u[0])return new h(!f||f<0&&(!u||u[0])?NaN:u?o:1/0);for(a=!1,0==(f=Math.sqrt(+o))||f==1/0?(((e=D(u)).length+c)%2==0&&(e+="0"),f=Math.sqrt(e),c=w((c+1)/2)-(c<0||c%2),t=new h(e=f==1/0?"1e"+c:(e=f.toExponential()).slice(0,e.indexOf("e")+1)+c)):t=new h(f.toString()),i=(c=h.precision)+3;;)if(t=(s=t).plus(P(o,s,i+2,1)).times(.5),D(s.d).slice(0,i)===(e=D(t.d)).slice(0,i)){if("9999"!=(e=e.slice(i-3,i+1))&&(r||"4999"!=e)){+e&&(+e.slice(1)||"5"!=e.charAt(0))||(R(t,c+1,1),n=!t.times(t).eq(o));break}if(!r&&(R(s,c+1,0),s.times(s).eq(o))){t=s;break}i+=4,r=1}return a=!0,R(t,c,h.rounding,n)},O.tangent=O.tan=function(){var n,e,i=this,t=i.constructor;return i.isFinite()?i.isZero()?new t(i):(n=t.precision,e=t.rounding,t.precision=n+10,t.rounding=1,(i=i.sin()).s=1,i=P(i,new t(1).minus(i.times(i)).sqrt(),n+10,0),t.precision=n,t.rounding=e,R(2==r||4==r?i.neg():i,n,e,!0)):new t(NaN)},O.times=O.mul=function(n){var e,i,t,r,s,o,u,c,f,h=this.constructor,l=this.d,d=(n=new h(n)).d;if(n.s*=this.s,!(l&&l[0]&&d&&d[0]))return new h(!n.s||l&&!l[0]&&!d||d&&!d[0]&&!l?NaN:l&&d?0*n.s:n.s/0);for(i=w(this.e/M)+w(n.e/M),(c=l.length)<(f=d.length)&&(s=l,l=d,d=s,o=c,c=f,f=o),s=[],t=o=c+f;t--;)s.push(0);for(t=f;--t>=0;){for(e=0,r=c+t;r>t;)u=s[r]+d[t]*l[r-t-1]+e,s[r--]=u%E|0,e=u/E|0;s[r]=(s[r]+e)%E|0}for(;!s[--o];)s.pop();return e?++i:s.shift(),n.d=s,n.e=U(s,i),a?R(n,h.precision,h.rounding):n},O.toBinary=function(n,e){return z(this,2,n,e)},O.toDecimalPlaces=O.toDP=function(n,e){var i=this,t=i.constructor;return i=new t(i),void 0===n?i:(F(n,0,o),void 0===e?e=t.rounding:F(e,0,8),R(i,n+i.e+1,e))},O.toExponential=function(n,e){var i,t=this,r=t.constructor;return void 0===n?i=L(t,!0):(F(n,0,o),void 0===e?e=r.rounding:F(e,0,8),i=L(t=R(new r(t),n+1,e),!0,n+1)),t.isNeg()&&!t.isZero()?"-"+i:i},O.toFixed=function(n,e){var i,t,r=this,s=r.constructor;return void 0===n?i=L(r):(F(n,0,o),void 0===e?e=s.rounding:F(e,0,8),i=L(t=R(new s(r),n+r.e+1,e),!1,n+t.e+1)),r.isNeg()&&!r.isZero()?"-"+i:i},O.toFraction=function(n){var e,i,t,r,s,o,u,c,f,h,l,p,g=this,w=g.d,v=g.constructor;if(!w)return new v(g);if(f=i=new v(1),o=(s=(e=new v(t=c=new v(0))).e=S(w)-g.e-1)%M,e.d[0]=m(10,o<0?M+o:o),null==n)n=s>0?e:f;else{if(!(u=new v(n)).isInt()||u.lt(f))throw Error(d+u);n=u.gt(e)?s>0?e:f:u}for(a=!1,u=new v(D(w)),h=v.precision,v.precision=s=w.length*M*2;l=P(u,e,0,1,1),1!=(r=i.plus(l.times(t))).cmp(n);)i=t,t=r,r=f,f=c.plus(l.times(r)),c=r,r=e,e=u.minus(l.times(r)),u=r;return r=P(n.minus(i),t,0,1,1),c=c.plus(r.times(f)),i=i.plus(r.times(t)),c.s=f.s=g.s,p=P(f,t,s,1).minus(g).abs().cmp(P(c,i,s,1).minus(g).abs())<1?[f,t]:[c,i],v.precision=h,a=!0,p},O.toHexadecimal=O.toHex=function(n,e){return z(this,16,n,e)},O.toNearest=function(n,e){var i=this,t=i.constructor;if(i=new t(i),null==n){if(!i.d)return i;n=new t(1),e=t.rounding}else{if(n=new t(n),void 0!==e&&F(e,0,8),!i.d)return n.s?i:n;if(!n.d)return n.s&&(n.s=i.s),n}return n.d[0]?(a=!1,e<4&&(e=[4,5,7,8][e]),i=P(i,n,0,e,1).times(n),a=!0,R(i)):(n.s=i.s,i=n),i},O.toNumber=function(){return+this},O.toOctal=function(n,e){return z(this,8,n,e)},O.toPower=O.pow=function(n){var e,i,t,r,s,o,u=this,c=u.constructor,f=+(n=new c(n));if(!(u.d&&n.d&&u.d[0]&&n.d[0]))return new c(m(+u,f));if((u=new c(u)).eq(1))return u;if(t=c.precision,s=c.rounding,n.eq(1))return R(u,t,s);if((e=w(n.e/M))>=n.d.length-1&&(i=f<0?-f:f)<=9007199254740991)return r=C(c,u,i,t),n.s<0?new c(1).div(r):R(r,t,s);if((o=u.s)<0){if(ec.maxE+1||e0?o/0:0):(a=!1,c.rounding=u.s=1,i=Math.min(12,(e+"").length),(r=B(n.times(V(u,t+i)),t)).d&&A((r=R(r,t+5,1)).d,t,s)&&(e=t+10,+D((r=R(B(n.times(V(u,e+i)),e),e+5,1)).d).slice(t+1,t+15)+1==1e14&&(r=R(r,t+1,0))),r.s=o,a=!0,c.rounding=s,R(r,t,s))},O.toPrecision=function(n,e){var i,t=this,r=t.constructor;return void 0===n?i=L(t,t.e<=r.toExpNeg||t.e>=r.toExpPos):(F(n,1,o),void 0===e?e=r.rounding:F(e,0,8),i=L(t=R(new r(t),n,e),n<=t.e||t.e<=r.toExpNeg,n)),t.isNeg()&&!t.isZero()?"-"+i:i},O.toSignificantDigits=O.toSD=function(n,e){var i=this.constructor;return void 0===n?(n=i.precision,e=i.rounding):(F(n,1,o),void 0===e?e=i.rounding:F(e,0,8)),R(new i(this),n,e)},O.toString=function(){var n=this,e=n.constructor,i=L(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()&&!n.isZero()?"-"+i:i},O.truncated=O.trunc=function(){return R(new this.constructor(this),this.e+1,1)},O.valueOf=O.toJSON=function(){var n=this,e=n.constructor,i=L(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()?"-"+i:i};var P=function(){function n(n,e,i){var t,r=0,s=n.length;for(n=n.slice();s--;)t=n[s]*e+r,n[s]=t%i|0,r=t/i|0;return r&&n.unshift(r),n}function e(n,e,i,t){var r,s;if(i!=t)s=i>t?1:-1;else for(r=s=0;re[r]?1:-1;break}return s}function t(n,e,i,t){for(var r=0;i--;)n[i]-=r,r=n[i]1;)n.shift()}return function(r,s,o,u,c,f){var h,a,l,d,p,g,m,v,N,b,x,y,q,O,D,F,A,Z,P,L,U=r.constructor,_=r.s==s.s?1:-1,k=r.d,S=s.d;if(!(k&&k[0]&&S&&S[0]))return new U(r.s&&s.s&&(k?!S||k[0]!=S[0]:S)?k&&0==k[0]||!S?0*_:_/0:NaN);for(f?(p=1,a=r.e-s.e):(f=E,p=M,a=w(r.e/p)-w(s.e/p)),P=S.length,A=k.length,b=(N=new U(_)).d=[],l=0;S[l]==(k[l]||0);l++);if(S[l]>(k[l]||0)&&a--,null==o?(O=o=U.precision,u=U.rounding):O=c?o+(r.e-s.e)+1:o,O<0)b.push(1),g=!0;else{if(O=O/p+2|0,l=0,1==P){for(d=0,S=S[0],O++;(l1&&(S=n(S,d,f),k=n(k,d,f),P=S.length,A=k.length),F=P,y=(x=k.slice(0,P)).length;y=f/2&&++Z;do{d=0,(h=e(S,x,P,y))<0?(q=x[0],P!=y&&(q=q*f+(x[1]||0)),(d=q/Z|0)>1?(d>=f&&(d=f-1),1==(h=e(m=n(S,d,f),x,v=m.length,y=x.length))&&(d--,t(m,P=10;d/=10)l++;N.e=l+a*p-1,R(N,c?o+N.e+1:o,u,g)}return N}}();function R(n,e,i,t){var r,s,o,u,c,f,h,l,d,p=n.constructor;n:if(null!=e){if(!(l=n.d))return n;for(r=1,u=l[0];u>=10;u/=10)r++;if((s=e-r)<0)s+=M,o=e,c=(h=l[d=0])/m(10,r-o-1)%10|0;else if((d=Math.ceil((s+1)/M))>=(u=l.length)){if(!t)break n;for(;u++<=d;)l.push(0);h=c=0,r=1,o=(s%=M)-M+1}else{for(h=u=l[d],r=1;u>=10;u/=10)r++;c=(o=(s%=M)-M+r)<0?0:h/m(10,r-o-1)%10|0}if(t=t||e<0||void 0!==l[d+1]||(o<0?h:h%m(10,r-o-1)),f=i<4?(c||t)&&(0==i||i==(n.s<0?3:2)):c>5||5==c&&(4==i||t||6==i&&(s>0?o>0?h/m(10,r-o):0:l[d-1])%10&1||i==(n.s<0?8:7)),e<1||!l[0])return l.length=0,f?(e-=n.e+1,l[0]=m(10,(M-e%M)%M),n.e=-e||0):l[0]=n.e=0,n;if(0==s?(l.length=d,u=1,d--):(l.length=d+1,u=m(10,M-s),l[d]=o>0?(h/m(10,r-o)%m(10,o)|0)*u:0),f)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++,l[0]==E&&(l[0]=1));break}if(l[d]+=u,l[d]!=E)break;l[d--]=0,u=1}for(s=l.length;0===l[--s];)l.pop()}return a&&(n.e>p.maxE?(n.d=null,n.e=NaN):n.e0?s=s.charAt(0)+"."+s.slice(1)+T(t):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(n.e<0?"e":"e+")+n.e):r<0?(s="0."+T(-r-1)+s,i&&(t=i-o)>0&&(s+=T(t))):r>=o?(s+=T(r+1-o),i&&(t=i-r-1)>0&&(s=s+"."+T(t))):((t=r+1)0&&(r+1===o&&(s+="."),s+=T(t))),s}function U(n,e){var i=n[0];for(e*=M;i>=10;i/=10)e++;return e}function _(n,e,i){if(e>y)throw a=!0,i&&(n.precision=i),Error(p);return R(new n(c),e,1,!0)}function k(n,e,i){if(e>q)throw Error(p);return R(new n(f),e,i,!0)}function S(n){var e=n.length-1,i=e*M+1;if(e=n[e]){for(;e%10==0;e/=10)i--;for(e=n[0];e>=10;e/=10)i++}return i}function T(n){for(var e="";n--;)e+="0";return e}function C(n,e,i,t){var r,s=new n(1),o=Math.ceil(t/M+4);for(a=!1;;){if(i%2&&G((s=s.times(e)).d,o)&&(r=!0),0===(i=w(i/2))){i=s.d.length-1,r&&0===s.d[i]&&++s.d[i];break}G((e=e.times(e)).d,o)}return a=!0,s}function I(n){return 1&n.d[n.d.length-1]}function H(n,e,i){for(var t,r=new n(e[0]),s=0;++s17)return new d(n.d?n.d[0]?n.s<0?0:1/0:1:n.s?n.s<0?0:n:NaN);for(null==e?(a=!1,c=g):c=e,u=new d(.03125);n.e>-2;)n=n.times(u),l+=5;for(c+=t=Math.log(m(2,l))/Math.LN10*2+5|0,i=s=o=new d(1),d.precision=c;;){if(s=R(s.times(n),c,1),i=i.times(++h),D((u=o.plus(P(s,i,c,1))).d).slice(0,c)===D(o.d).slice(0,c)){for(r=l;r--;)o=R(o.times(o),c,1);if(null!=e)return d.precision=g,o;if(!(f<3&&A(o.d,c-t,p,f)))return R(o,d.precision=g,p,a=!0);d.precision=c+=10,i=s=u=new d(1),h=0,f++}o=u}}function V(n,e){var i,t,r,s,o,u,c,f,h,l,d,p=1,g=n,w=g.d,m=g.constructor,v=m.rounding,N=m.precision;if(g.s<0||!w||!w[0]||!g.e&&1==w[0]&&1==w.length)return new m(w&&!w[0]?-1/0:1!=g.s?NaN:w?0:g);if(null==e?(a=!1,h=N):h=e,m.precision=h+=10,t=(i=D(w)).charAt(0),!(Math.abs(s=g.e)<15e14))return f=_(m,h+2,N).times(s+""),g=V(new m(t+"."+i.slice(1)),h-10).plus(f),m.precision=N,null==e?R(g,N,v,a=!0):g;for(;t<7&&1!=t||1==t&&i.charAt(1)>3;)t=(i=D((g=g.times(n)).d)).charAt(0),p++;for(s=g.e,t>1?(g=new m("0."+i),s++):g=new m(t+"."+i.slice(1)),l=g,c=o=g=P(g.minus(1),g.plus(1),h,1),d=R(g.times(g),h,1),r=3;;){if(o=R(o.times(d),h,1),D((f=c.plus(P(o,new m(r),h,1))).d).slice(0,h)===D(c.d).slice(0,h)){if(c=c.times(2),0!==s&&(c=c.plus(_(m,h+2,N).times(s+""))),c=P(c,new m(p),h,1),null!=e)return m.precision=N,c;if(!A(c.d,h-10,v,u))return R(c,m.precision=N,v,a=!0);m.precision=h+=10,f=o=g=P(l.minus(1),l.plus(1),h,1),d=R(g.times(g),h,1),r=u=1}c=f,r+=2}}function j(n){return String(n.s*n.s/0)}function $(n,e){var i,t,r;for((i=e.indexOf("."))>-1&&(e=e.replace(".","")),(t=e.search(/e/i))>0?(i<0&&(i=t),i+=+e.slice(t+1),e=e.substring(0,t)):i<0&&(i=e.length),t=0;48===e.charCodeAt(t);t++);for(r=e.length;48===e.charCodeAt(r-1);--r);if(e=e.slice(t,r)){if(r-=t,n.e=i=i-t-1,n.d=[],t=(i+1)%M,i<0&&(t+=M),tn.constructor.maxE?(n.d=null,n.e=NaN):n.e=0&&(d=d.replace(".",""),(g=new w(1)).e=d.length-f,g.d=Z(L(g),10,s),g.e=g.d.length),c=a=(p=Z(d,10,s)).length;0==p[--a];)p.pop();if(p[0]){if(f<0?c--:((n=new w(n)).d=p,n.e=c,p=(n=P(n,g,t,r,0,s)).d,c=n.e,l=i),f=p[t],h=s/2,l=l||void 0!==p[t+1],l=r<4?(void 0!==f||l)&&(0===r||r===(n.s<0?3:2)):f>h||f===h&&(4===r||l||6===r&&1&p[t-1]||r===(n.s<0?8:7)),p.length=t,l)for(;++p[--t]>s-1;)p[t]=0,t||(++c,p.unshift(1));for(a=p.length;!p[a-1];--a);for(f=0,d="";f1)if(16==e||8==e){for(f=16==e?4:3,--a;a%f;a++)d+="0";for(a=(p=Z(d,s,e)).length;!p[a-1];--a);for(f=1,d="1.";fa)for(c-=a;c--;)d+="0";else ce)return n.length=e,!0}function K(n){return new this(n).abs()}function Q(n){return new this(n).acos()}function X(n){return new this(n).acosh()}function Y(n,e){return new this(n).plus(e)}function nn(n){return new this(n).asin()}function en(n){return new this(n).asinh()}function tn(n){return new this(n).atan()}function rn(n){return new this(n).atanh()}function sn(n,e){n=new this(n),e=new this(e);var i,t=this.precision,r=this.rounding,s=t+4;return n.s&&e.s?n.d||e.d?!e.d||n.isZero()?(i=e.s<0?k(this,t,r):new this(0)).s=n.s:!n.d||e.isZero()?(i=k(this,s,1).times(.5)).s=n.s:e.s<0?(this.precision=s,this.rounding=1,i=this.atan(P(n,e,s,1)),e=k(this,s,1),this.precision=t,this.rounding=r,i=n.s<0?i.minus(e):i.plus(e)):i=this.atan(P(n,e,s,1)):(i=k(this,s,1).times(e.s>0?.25:.75)).s=n.s:i=new this(NaN),i}function on(n){return new this(n).cbrt()}function un(n){return R(n=new this(n),n.e+1,2)}function cn(n){if(!n||"object"!=typeof n)throw Error(l+"Object expected");var e,i,t,r=!0===n.defaults,u=["precision",1,o,"rounding",0,8,"toExpNeg",-s,0,"toExpPos",0,s,"maxE",0,s,"minE",-s,0,"modulo",0,9];for(e=0;e=u[e+1]&&t<=u[e+2]))throw Error(d+i+": "+t);this[i]=t}if(i="crypto",r&&(this[i]=h[i]),void 0!==(t=n[i])){if(!0!==t&&!1!==t&&0!==t&&1!==t)throw Error(d+i+": "+t);if(t){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw Error(g);this[i]=!0}else this[i]=!1}return this}function fn(n){return new this(n).cos()}function hn(n){return new this(n).cosh()}function an(n,e){return new this(n).div(e)}function ln(n){return new this(n).exp()}function dn(n){return R(n=new this(n),n.e+1,3)}function pn(){var n,e,i=new this(0);for(a=!1,n=0;n=429e7?e[s]=crypto.getRandomValues(new Uint32Array(1))[0]:c[s++]=r%1e7;else{if(!crypto.randomBytes)throw Error(g);for(e=crypto.randomBytes(t*=4);s=214e7?crypto.randomBytes(4).copy(e,s):(c.push(r%1e7),s+=4);s=t/4}else for(;s=10;r/=10)t++;t=10;t/=10)i++;return s.e=i,void(s.d=[n])}return 0*n!=0?(n||(s.s=NaN),s.e=NaN,void(s.d=null)):$(s,n.toString())}if("string"!==r)throw Error(d+n);return 45===n.charCodeAt(0)?(n=n.slice(1),s.s=-1):s.s=1,x.test(n)?$(s,n):function(n,i){var t,r,s,o,u,c,f,h,l;if("Infinity"===i||"NaN"===i)return+i||(n.s=NaN),n.e=NaN,n.d=null,n;if(N.test(i))t=16,i=i.toLowerCase();else if(v.test(i))t=2;else{if(!b.test(i))throw Error(d+i);t=8}for((o=i.search(/p/i))>0?(f=+i.slice(o+1),i=i.substring(2,o)):i=i.slice(2),u=(o=i.indexOf("."))>=0,r=n.constructor,u&&(o=(c=(i=i.replace(".","")).length)-o,s=C(r,new r(t),o,2*o)),o=l=(h=Z(i,t,E)).length-1;0===h[o];--o)h.pop();return o<0?new r(0*n.s):(n.e=U(h,l),n.d=h,a=!1,u&&(n=P(n,s,4*c)),f&&(n=n.times(Math.abs(f)<54?Math.pow(2,f):e.pow(2,f))),a=!0,n)}(s,n)}if(o.prototype=O,o.ROUND_UP=0,o.ROUND_DOWN=1,o.ROUND_CEIL=2,o.ROUND_FLOOR=3,o.ROUND_HALF_UP=4,o.ROUND_HALF_DOWN=5,o.ROUND_HALF_EVEN=6,o.ROUND_HALF_CEIL=7,o.ROUND_HALF_FLOOR=8,o.EUCLID=9,o.config=o.set=cn,o.clone=n,o.isDecimal=gn,o.abs=K,o.acos=Q,o.acosh=X,o.add=Y,o.asin=nn,o.asinh=en,o.atan=tn,o.atanh=rn,o.atan2=sn,o.cbrt=on,o.ceil=un,o.cos=fn,o.cosh=hn,o.div=an,o.exp=ln,o.floor=dn,o.hypot=pn,o.ln=wn,o.log=mn,o.log10=Nn,o.log2=vn,o.max=bn,o.min=xn,o.mod=En,o.mul=Mn,o.pow=yn,o.random=qn,o.round=On,o.sign=Dn,o.sin=Fn,o.sinh=An,o.sqrt=Zn,o.sub=Pn,o.tan=Rn,o.tanh=Ln,o.trunc=Un,void 0===i&&(i={}),i&&!0!==i.defaults)for(s=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t