1
0
mirror of https://github.com/MikeMcl/decimal.js.git synced 2024-10-27 20:34:12 +00:00
MikeMcl_decimal.js/decimal.min.js

3 lines
31 KiB
JavaScript
Raw Normal View History

2016-06-30 18:27:50 +00:00
/* decimal.js v6.0.0 https://github.com/MikeMcl/decimal.js/LICENCE */
2016-09-20 15:33:36 +00:00
!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;e<r;e++)t=n[e]+"",i=Rn-t.length,i&&(s+=l(i)),s+=t;o=n[e],t=o+"",i=Rn-t.length,i&&(s+=l(i))}else if(0===o)return"0";for(;o%10===0;)o/=10;return s+o}function i(n,e,i){if(n!==~~n||n<e||n>i)throw Error(Mn+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+=Rn,r=0):(r=Math.ceil((e+1)/Rn),e%=Rn),s=On(10,Rn-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)==On(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)==On(10,e-3)-1,o}function r(n,e,i){for(var t,r,s=[0],o=0,u=n.length;o<u;){for(r=s.length;r--;)s[r]*=e;for(s[0]+=wn.indexOf(n.charAt(o++)),t=0;t<s.length;t++)s[t]>i-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;r<32?(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,h,a,l,d=n.constructor;n:if(null!=e){if(a=n.d,!a)return n;for(r=1,u=a[0];u>=10;u/=10)r++;if(s=e-r,s<0)s+=Rn,o=e,h=a[l=0],c=h/On(10,r-o-1)%10|0;else if(l=Math.ceil((s+1)/Rn),u=a.length,l>=u){if(!t)break n;for(;u++<=l;)a.push(0);h=c=0,r=1,s%=Rn,o=s-Rn+1}else{for(h=u=a[l],r=1;u>=10;u/=10)r++;s%=Rn,o=s-Rn+r,c=o<0?0:h/On(10,r-o-1)%10|0}if(t=t||e<0||void 0!==a[l+1]||(o<0?h:h%On(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/On(10,r-o):0:a[l-1])%10&1||i==(n.s<0?8:7)),e<1||!a[0])return a.length=0,f?(e-=n.e+1,a[0]=On(10,(Rn-e%Rn)%Rn),n.e=-e||0):a[0]=n.e=0,n;if(0==s?(a.length=l,u=1,l--):(a.length=l+1,u=On(10,Rn-s),a[l]=o>0?(h/On(10,r-o)%On(10,o)|0)*u:0),f)for(;;){if(0==l){for(s=1,o=a[0];o>=10;o/=10)s++;for(o=a[0]+=u,u=1;o>=10;o/=10)u++;s!=u&&(n.e++,a[0]==Pn&&(a[0]=1));break}if(a[l]+=u,a[l]!=Pn)break;a[l--]=0,u=1}for(s=a.length;0===a[--s];)a.pop()}return xn&&(n.e>d.maxE?(n.d=null,n.e=NaN):n.e<d.minE&&(n.e=0,n.d=[0])),n}function u(n,i,t){if(!n.isFinite())return v(n);var r,s=n.e,o=e(n.d),u=o.length;return i?(t&&(r=t-u)>0?o=o.charAt(0)+"."+o.slice(1)+l(r):u>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(n.e<0?"e":"e+")+n.e):s<0?(o="0."+l(-s-1)+o,t&&(r=t-u)>0&&(o+=l(r))):s>=u?(o+=l(s+1-u),t&&(r=t-s-1)>0&&(o=o+"."+l(r))):((r=s+1)<u&&(o=o.slice(0,r)+"."+o.slice(r)),t&&(r=t-u)>0&&(s+1===u&&(o+="."),o+=l(r))),o}function c(n,e){for(var i=1,t=n[0];t>=10;t/=10)i++;return i+e*Rn-1}function f(n,e,i){if(e>Ln)throw xn=!0,i&&(n.precision=i),Error(yn);return o(new n(mn),e,1,!0)}function h(n,e,i){if(e>Sn)throw Error(yn);return o(new n(vn),e,i,!0)}function a(n){var e=n.length-1,i=e*Rn+1;if(e=n[e]){for(;e%10==0;e/=10)i--;for(e=n[0];e>=10;e/=10)i++}return i}function l(n){for(var e="";n--;)e+="0";return e}function d(n,e,i,t){var r,s=new n(1),o=Math.ceil(t/Rn+4);for(xn=!1;;){if(i%2&&(s=s.times(e),q(s.d,o)&&(r=!0)),i=qn(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 xn=!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;++s<e.length;){if(t=new n(e[s]),!t.s){r=t;break}r[i](t)&&(r=t)}return r}function w(n,i){var r,s,u,c,f,h,a,l=0,d=0,p=0,g=n.constructor,w=g.rounding,m=g.precision;if(!n.d||!n.d[0]||n.e>17)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?(xn=!1,a=m):a=i,h=new g(.03125);n.e>-2;)n=n.times(h),p+=5;for(s=Math.log(On(2,p))/Math.LN10*2+5|0,a+=s,r=c=f=new g(1),g.precision=a;;){if(c=o(c.times(n),a,1),r=r.times(++d),h=f.plus(_n(c,r,a,1)),e(h.d).slice(0,a)===e(f.d).slice(0,a)){for(u=p;u--;)f=o(f.times(f),a,1);if(null!=i)return g.precision=m,f;if(!(l<3&&t(f.d,a-s,w,l)))return o(f,g.precision=m,w,xn=!0);g.precision=a+=10,r=c=h=new g(1),d=0,l++}f=h}}function m(n,i){var r,s,u,c,h,a,l,d,p,g,w,v=1,N=10,b=n,x=b.d,E=b.constructor,M=E
2015-02-20 16:01:25 +00:00
//# sourceMappingURL=doc/decimal.js.map