-
Notifications
You must be signed in to change notification settings - Fork 46
/
break_infinity.min.js
1 lines (1 loc) · 16.2 KB
/
break_infinity.min.js
1
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t=t||self).Decimal=n()}(this,function(){"use strict";var t=function(t,n,e){if(null==t||null==n)return t;var r=String(t),i="number"==typeof n?n:parseInt(n,10);if(isNaN(i)||!isFinite(i))return r;var o=r.length;if(o>=i)return r;var u=null==e?"":String(e);""===u&&(u=" ");for(var s=i-o;u.length<s;)u+=u;return r+(u.length>s?u.substr(0,s):u)},n=function(){for(var t=[],n=-323;n<=308;n++)t.push(Number("1e"+n));return function(n){return t[n+323]}}(),e=function(t){return t instanceof s?t:new s(t)},r=function(t,n){return(new s).fromMantissaExponent(t,n)},i=function(t,n){return(new s).fromMantissaExponent_noNormalize(t,n)};function o(t,n,e,r){var i=n.mul(e.pow(r));return s.floor(t.div(i).mul(e.sub(1)).add(1).log10()/e.log10())}function u(t,n,e,r){return n.mul(e.pow(r)).mul(s.sub(1,e.pow(t))).div(s.sub(1,e))}var s=function(){function s(t){this.mantissa=NaN,this.exponent=NaN,void 0===t?(this.m=0,this.e=0):t instanceof s?this.fromDecimal(t):"number"==typeof t?this.fromNumber(t):this.fromString(t)}return Object.defineProperty(s.prototype,"m",{get:function(){return this.mantissa},set:function(t){this.mantissa=t},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"e",{get:function(){return this.exponent},set:function(t){this.exponent=t},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"s",{get:function(){return this.sign()},set:function(t){if(0===t)return this.e=0,void(this.m=0);this.sgn()!==t&&(this.m=-this.m)},enumerable:!0,configurable:!0}),s.fromMantissaExponent=function(t,n){return(new s).fromMantissaExponent(t,n)},s.fromMantissaExponent_noNormalize=function(t,n){return(new s).fromMantissaExponent_noNormalize(t,n)},s.fromDecimal=function(t){return(new s).fromDecimal(t)},s.fromNumber=function(t){return(new s).fromNumber(t)},s.fromString=function(t){return(new s).fromString(t)},s.fromValue=function(t){return(new s).fromValue(t)},s.fromValue_noAlloc=function(t){return t instanceof s?t:new s(t)},s.abs=function(t){return e(t).abs()},s.neg=function(t){return e(t).neg()},s.negate=function(t){return e(t).neg()},s.negated=function(t){return e(t).neg()},s.sign=function(t){return e(t).sign()},s.sgn=function(t){return e(t).sign()},s.round=function(t){return e(t).round()},s.floor=function(t){return e(t).floor()},s.ceil=function(t){return e(t).ceil()},s.trunc=function(t){return e(t).trunc()},s.add=function(t,n){return e(t).add(n)},s.plus=function(t,n){return e(t).add(n)},s.sub=function(t,n){return e(t).sub(n)},s.subtract=function(t,n){return e(t).sub(n)},s.minus=function(t,n){return e(t).sub(n)},s.mul=function(t,n){return e(t).mul(n)},s.multiply=function(t,n){return e(t).mul(n)},s.times=function(t,n){return e(t).mul(n)},s.div=function(t,n){return e(t).div(n)},s.divide=function(t,n){return e(t).div(n)},s.recip=function(t){return e(t).recip()},s.reciprocal=function(t){return e(t).recip()},s.reciprocate=function(t){return e(t).reciprocate()},s.cmp=function(t,n){return e(t).cmp(n)},s.compare=function(t,n){return e(t).cmp(n)},s.eq=function(t,n){return e(t).eq(n)},s.equals=function(t,n){return e(t).eq(n)},s.neq=function(t,n){return e(t).neq(n)},s.notEquals=function(t,n){return e(t).notEquals(n)},s.lt=function(t,n){return e(t).lt(n)},s.lte=function(t,n){return e(t).lte(n)},s.gt=function(t,n){return e(t).gt(n)},s.gte=function(t,n){return e(t).gte(n)},s.max=function(t,n){return e(t).max(n)},s.min=function(t,n){return e(t).min(n)},s.clamp=function(t,n,r){return e(t).clamp(n,r)},s.clampMin=function(t,n){return e(t).clampMin(n)},s.clampMax=function(t,n){return e(t).clampMax(n)},s.cmp_tolerance=function(t,n,r){return e(t).cmp_tolerance(n,r)},s.compare_tolerance=function(t,n,r){return e(t).cmp_tolerance(n,r)},s.eq_tolerance=function(t,n,r){return e(t).eq_tolerance(n,r)},s.equals_tolerance=function(t,n,r){return e(t).eq_tolerance(n,r)},s.neq_tolerance=function(t,n,r){return e(t).neq_tolerance(n,r)},s.notEquals_tolerance=function(t,n,r){return e(t).notEquals_tolerance(n,r)},s.lt_tolerance=function(t,n,r){return e(t).lt_tolerance(n,r)},s.lte_tolerance=function(t,n,r){return e(t).lte_tolerance(n,r)},s.gt_tolerance=function(t,n,r){return e(t).gt_tolerance(n,r)},s.gte_tolerance=function(t,n,r){return e(t).gte_tolerance(n,r)},s.log10=function(t){return e(t).log10()},s.absLog10=function(t){return e(t).absLog10()},s.pLog10=function(t){return e(t).pLog10()},s.log=function(t,n){return e(t).log(n)},s.log2=function(t){return e(t).log2()},s.ln=function(t){return e(t).ln()},s.logarithm=function(t,n){return e(t).logarithm(n)},s.pow10=function(t){return Number.isInteger(t)?i(1,t):r(Math.pow(10,t%1),Math.trunc(t))},s.pow=function(t,n){return"number"==typeof t&&10===t&&"number"==typeof n&&Number.isInteger(n)?i(1,n):e(t).pow(n)},s.exp=function(t){return e(t).exp()},s.sqr=function(t){return e(t).sqr()},s.sqrt=function(t){return e(t).sqrt()},s.cube=function(t){return e(t).cube()},s.cbrt=function(t){return e(t).cbrt()},s.dp=function(t){return e(t).dp()},s.decimalPlaces=function(t){return e(t).dp()},s.affordGeometricSeries=function(t,n,r,i){return o(e(t),e(n),e(r),i)},s.sumGeometricSeries=function(t,n,r,i){return u(t,e(n),e(r),i)},s.affordArithmeticSeries=function(t,n,r,i){return function(t,n,e,r){var i=n.add(r.mul(e)).sub(e.div(2)),o=i.pow(2);return i.neg().add(o.add(e.mul(t).mul(2)).sqrt()).div(e).floor()}(e(t),e(n),e(r),e(i))},s.sumArithmeticSeries=function(t,n,r,i){return function(t,n,e,r){var i=n.add(r.mul(e));return t.div(2).mul(i.mul(2).plus(t.sub(1).mul(e)))}(e(t),e(n),e(r),e(i))},s.efficiencyOfPurchase=function(t,n,r){return function(t,n,e){return t.div(n).add(t.div(e))}(e(t),e(n),e(r))},s.randomDecimalForTesting=function(t){if(20*Math.random()<1)return i(0,0);var n=10*Math.random();10*Math.random()<1&&(n=Math.round(n)),n*=Math.sign(2*Math.random()-1);var e=Math.floor(Math.random()*t*2)-t;return r(n,e)},s.prototype.normalize=function(){if(this.m>=1&&this.m<10)return this;if(0===this.m)return this.m=0,this.e=0,this;var t=Math.floor(Math.log10(Math.abs(this.m)));return this.m=-324===t?10*this.m/1e-323:this.m/n(t),this.e+=t,this},s.prototype.fromMantissaExponent=function(t,n){return isFinite(t)&&isFinite(n)?(this.m=t,this.e=n,this.normalize(),this):(t=Number.NaN,n=Number.NaN,this)},s.prototype.fromMantissaExponent_noNormalize=function(t,n){return this.m=t,this.e=n,this},s.prototype.fromDecimal=function(t){return this.m=t.m,this.e=t.e,this},s.prototype.fromNumber=function(t){return isNaN(t)?(this.m=Number.NaN,this.e=Number.NaN):t===Number.POSITIVE_INFINITY?(this.m=1,this.e=9e15):t===Number.NEGATIVE_INFINITY?(this.m=-1,this.e=9e15):0===t?(this.m=0,this.e=0):(this.e=Math.floor(Math.log10(Math.abs(t))),this.m=-324===this.e?10*t/1e-323:t/n(this.e),this.normalize()),this},s.prototype.fromString=function(t){if(-1!==t.indexOf("e")){var n=t.split("e");this.m=parseFloat(n[0]),this.e=parseFloat(n[1]),this.normalize()}else if("NaN"===t)this.m=Number.NaN,this.e=Number.NaN;else if(this.fromNumber(parseFloat(t)),isNaN(this.m))throw Error("[DecimalError] Invalid argument: "+t);return this},s.prototype.fromValue=function(t){return t instanceof s?this.fromDecimal(t):"number"==typeof t?this.fromNumber(t):"string"==typeof t?this.fromString(t):(this.m=0,this.e=0,this)},s.prototype.toNumber=function(){if(!isFinite(this.e))return Number.NaN;if(this.e>308)return this.m>0?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY;if(this.e<-324)return 0;if(-324===this.e)return this.m>0?5e-324:-5e-324;var t=this.m*n(this.e);if(!isFinite(t)||this.e<0)return t;var e=Math.round(t);return Math.abs(e-t)<1e-10?e:t},s.prototype.mantissaWithDecimalPlaces=function(t){if(isNaN(this.m)||isNaN(this.e))return Number.NaN;if(0===this.m)return 0;var n=t+1,e=Math.ceil(Math.log10(Math.abs(this.m))),r=Math.round(this.m*Math.pow(10,n-e))*Math.pow(10,e-n);return parseFloat(r.toFixed(Math.max(n-e,0)))},s.prototype.toString=function(){return isNaN(this.m)||isNaN(this.e)?"NaN":this.e>=9e15?this.m>0?"Infinity":"-Infinity":this.e<=-9e15||0===this.m?"0":this.e<21&&this.e>-7?this.toNumber().toString():this.m+"e"+(this.e>=0?"+":"")+this.e},s.prototype.toExponential=function(n){if(isNaN(this.m)||isNaN(this.e))return"NaN";if(this.e>=9e15)return this.m>0?"Infinity":"-Infinity";if(this.e<=-9e15||0===this.m)return"0"+(n>0?t(".",n+1,"0"):"")+"e+0";if(this.e>-324&&this.e<308)return this.toNumber().toExponential(n);isFinite(n)||(n=17);var e=n+1,r=Math.max(1,Math.ceil(Math.log10(Math.abs(this.m))));return(Math.round(this.m*Math.pow(10,e-r))*Math.pow(10,r-e)).toFixed(Math.max(e-r,0))+"e"+(this.e>=0?"+":"")+this.e},s.prototype.toFixed=function(n){return isNaN(this.m)||isNaN(this.e)?"NaN":this.e>=9e15?this.m>0?"Infinity":"-Infinity":this.e<=-9e15||0===this.m?"0"+(n>0?t(".",n+1,"0"):""):this.e>=17?this.m.toString().replace(".","").padEnd(this.e+1,"0")+(n>0?t(".",n+1,"0"):""):this.toNumber().toFixed(n)},s.prototype.toPrecision=function(t){return this.e<=-7?this.toExponential(t-1):t>this.e?this.toFixed(t-this.e-1):this.toExponential(t-1)},s.prototype.valueOf=function(){return this.toString()},s.prototype.toJSON=function(){return this.toString()},s.prototype.toStringWithDecimalPlaces=function(t){return this.toExponential(t)},s.prototype.abs=function(){return i(Math.abs(this.m),this.e)},s.prototype.neg=function(){return i(-this.m,this.e)},s.prototype.negate=function(){return this.neg()},s.prototype.negated=function(){return this.neg()},s.prototype.sign=function(){return Math.sign(this.m)},s.prototype.sgn=function(){return this.sign()},s.prototype.round=function(){return this.e<-1?new s(0):this.e<17?new s(Math.round(this.toNumber())):this},s.prototype.floor=function(){return this.e<-1?Math.sign(this.m)>=0?new s(0):new s(-1):this.e<17?new s(Math.floor(this.toNumber())):this},s.prototype.ceil=function(){return this.e<-1?Math.sign(this.m)>0?new s(1):new s(0):this.e<17?new s(Math.ceil(this.toNumber())):this},s.prototype.trunc=function(){return this.e<0?new s(0):this.e<17?new s(Math.trunc(this.toNumber())):this},s.prototype.add=function(t){var i,o,u=e(t);return 0===this.m?u:0===u.m?this:(this.e>=u.e?(i=this,o=u):(i=u,o=this),i.e-o.e>17?i:r(Math.round(1e14*i.m+1e14*o.m*n(o.e-i.e)),i.e-14))},s.prototype.plus=function(t){return this.add(t)},s.prototype.sub=function(t){return this.add(e(t).neg())},s.prototype.subtract=function(t){return this.sub(t)},s.prototype.minus=function(t){return this.sub(t)},s.prototype.mul=function(t){if("number"==typeof t)return t<1e307&&t>-1e307?r(this.m*t,this.e):r(1e-307*this.m*t,this.e+307);var n="string"==typeof t?new s(t):t;return r(this.m*n.m,this.e+n.e)},s.prototype.multiply=function(t){return this.mul(t)},s.prototype.times=function(t){return this.mul(t)},s.prototype.div=function(t){return this.mul(e(t).recip())},s.prototype.divide=function(t){return this.div(t)},s.prototype.divideBy=function(t){return this.div(t)},s.prototype.dividedBy=function(t){return this.div(t)},s.prototype.recip=function(){return r(1/this.m,-this.e)},s.prototype.reciprocal=function(){return this.recip()},s.prototype.reciprocate=function(){return this.recip()},s.prototype.cmp=function(t){var n=e(t);if(0===this.m){if(0===n.m)return 0;if(n.m<0)return 1;if(n.m>0)return-1}if(0===n.m){if(this.m<0)return-1;if(this.m>0)return 1}if(this.m>0)return n.m<0?1:this.e>n.e?1:this.e<n.e?-1:this.m>n.m?1:this.m<n.m?-1:0;if(this.m<0)return n.m>0?-1:this.e>n.e?-1:this.e<n.e?1:this.m>n.m?1:this.m<n.m?-1:0;throw Error("Unreachable code")},s.prototype.compare=function(t){return this.cmp(t)},s.prototype.eq=function(t){var n=e(t);return this.e===n.e&&this.m===n.m},s.prototype.equals=function(t){return this.eq(t)},s.prototype.neq=function(t){return!this.eq(t)},s.prototype.notEquals=function(t){return this.neq(t)},s.prototype.lt=function(t){var n=e(t);return 0===this.m?n.m>0:0===n.m?this.m<=0:this.e===n.e?this.m<n.m:this.m>0?n.m>0&&this.e<n.e:n.m>0||this.e>n.e},s.prototype.lte=function(t){return!this.gt(t)},s.prototype.gt=function(t){var n=e(t);return 0===this.m?n.m<0:0===n.m?this.m>0:this.e===n.e?this.m>n.m:this.m>0?n.m<0||this.e>n.e:n.m<0&&this.e<n.e},s.prototype.gte=function(t){return!this.lt(t)},s.prototype.max=function(t){var n=e(t);return this.lt(n)?n:this},s.prototype.min=function(t){var n=e(t);return this.gt(n)?n:this},s.prototype.clamp=function(t,n){return this.max(t).min(n)},s.prototype.clampMin=function(t){return this.max(t)},s.prototype.clampMax=function(t){return this.min(t)},s.prototype.cmp_tolerance=function(t,n){var r=e(t);return this.eq_tolerance(r,n)?0:this.cmp(r)},s.prototype.compare_tolerance=function(t,n){return this.cmp_tolerance(t,n)},s.prototype.eq_tolerance=function(t,n){var r=e(t);return s.lte(this.sub(r).abs(),s.max(this.abs(),r.abs()).mul(n))},s.prototype.equals_tolerance=function(t,n){return this.eq_tolerance(t,n)},s.prototype.neq_tolerance=function(t,n){return!this.eq_tolerance(t,n)},s.prototype.notEquals_tolerance=function(t,n){return this.neq_tolerance(t,n)},s.prototype.lt_tolerance=function(t,n){var r=e(t);return!this.eq_tolerance(r,n)&&this.lt(r)},s.prototype.lte_tolerance=function(t,n){var r=e(t);return this.eq_tolerance(r,n)||this.lt(r)},s.prototype.gt_tolerance=function(t,n){var r=e(t);return!this.eq_tolerance(r,n)&&this.gt(r)},s.prototype.gte_tolerance=function(t,n){var r=e(t);return this.eq_tolerance(r,n)||this.gt(r)},s.prototype.log10=function(){return this.e+Math.log10(this.m)},s.prototype.absLog10=function(){return this.e+Math.log10(Math.abs(this.m))},s.prototype.pLog10=function(){return this.m<=0||this.e<0?0:this.log10()},s.prototype.log=function(t){return Math.LN10/Math.log(t)*this.log10()},s.prototype.log2=function(){return 3.321928094887362*this.log10()},s.prototype.ln=function(){return 2.302585092994046*this.log10()},s.prototype.logarithm=function(t){return this.log(t)},s.prototype.pow=function(t){var n,e=t instanceof s?t.toNumber():t,i=this.e*e;if(Number.isSafeInteger(i)&&(n=Math.pow(this.m,e),isFinite(n)&&0!==n))return r(n,i);var o=Math.trunc(i),u=i-o;if(n=Math.pow(10,e*Math.log10(this.m)+u),isFinite(n)&&0!==n)return r(n,o);var h=s.pow10(e*this.absLog10());return-1===this.sign()&&e%2==1?h.neg():h},s.prototype.pow_base=function(t){return e(t).pow(this)},s.prototype.factorial=function(){var t=this.toNumber()+1;return s.pow(t/Math.E*Math.sqrt(t*Math.sinh(1/t)+1/(810*Math.pow(t,6))),t).mul(Math.sqrt(2*Math.PI/t))},s.prototype.exp=function(){var t=this.toNumber();return-706<t&&t<709?s.fromNumber(Math.exp(t)):s.pow(Math.E,t)},s.prototype.sqr=function(){return r(Math.pow(this.m,2),2*this.e)},s.prototype.sqrt=function(){return this.m<0?new s(Number.NaN):this.e%2!=0?r(3.16227766016838*Math.sqrt(this.m),Math.floor(this.e/2)):r(Math.sqrt(this.m),Math.floor(this.e/2))},s.prototype.cube=function(){return r(Math.pow(this.m,3),3*this.e)},s.prototype.cbrt=function(){var t=1,n=this.m;n<0&&(t=-1,n=-n);var e=t*Math.pow(n,1/3),i=this.e%3;return r(1===i||-1===i?2.154434690031884*e:0!==i?4.641588833612779*e:e,Math.floor(this.e/3))},s.prototype.sinh=function(){return this.exp().sub(this.negate().exp()).div(2)},s.prototype.cosh=function(){return this.exp().add(this.negate().exp()).div(2)},s.prototype.tanh=function(){return this.sinh().div(this.cosh())},s.prototype.asinh=function(){return s.ln(this.add(this.sqr().add(1).sqrt()))},s.prototype.acosh=function(){return s.ln(this.add(this.sqr().sub(1).sqrt()))},s.prototype.atanh=function(){return this.abs().gte(1)?Number.NaN:s.ln(this.add(1).div(new s(1).sub(this)))/2},s.prototype.ascensionPenalty=function(t){return 0===t?this:this.pow(Math.pow(10,-t))},s.prototype.egg=function(){return this.add(9)},s.prototype.lessThanOrEqualTo=function(t){return this.cmp(t)<1},s.prototype.lessThan=function(t){return this.cmp(t)<0},s.prototype.greaterThanOrEqualTo=function(t){return this.cmp(t)>-1},s.prototype.greaterThan=function(t){return this.cmp(t)>0},s.prototype.decimalPlaces=function(){return this.dp()},s.prototype.dp=function(){if(!isFinite(this.mantissa))return NaN;if(this.exponent>=17)return 0;for(var t=this.mantissa,n=-this.exponent,e=1;Math.abs(Math.round(t*e)/e-t)>1e-10;)e*=10,n++;return n>0?n:0},Object.defineProperty(s,"MAX_VALUE",{get:function(){return h},enumerable:!0,configurable:!0}),Object.defineProperty(s,"MIN_VALUE",{get:function(){return a},enumerable:!0,configurable:!0}),Object.defineProperty(s,"NUMBER_MAX_VALUE",{get:function(){return c},enumerable:!0,configurable:!0}),Object.defineProperty(s,"NUMBER_MIN_VALUE",{get:function(){return p},enumerable:!0,configurable:!0}),s}(),h=i(1,9e15),a=i(1,-9e15),c=e(Number.MAX_VALUE),p=e(Number.MIN_VALUE);return s});