forked from nsjcy/frontEnd/nsjcy

liuwh
2020-05-09 6ee2429b63ff94f80a5c3e5db963ef77745b0094
1
"use strict";function strip(t,e){return void 0===e&&(e=12),+parseFloat(t.toPrecision(e))}function digitLength(t){var e=t.toString().split(/[eE]/),i=(e[0].split(".")[1]||"").length-+(e[1]||0);return 0<i?i:0}function float2Fixed(t){if(-1===t.toString().indexOf("e"))return Number(t.toString().replace(".",""));var e=digitLength(t);return 0<e?strip(t*Math.pow(10,e)):t}function checkBoundary(t){_boundaryCheckingState&&(t>Number.MAX_SAFE_INTEGER||t<Number.MIN_SAFE_INTEGER)&&console.warn(t+" is beyond boundary when transfer to integer, the results may not be accurate")}function times(t,e){for(var i=[],n=2;n<arguments.length;n++)i[n-2]=arguments[n];if(0<i.length)return times.apply(void 0,[times(t,e),i[0]].concat(i.slice(1)));var r=float2Fixed(t),o=float2Fixed(e),a=digitLength(t)+digitLength(e),d=r*o;return checkBoundary(d),d/Math.pow(10,a)}function plus(t,e){for(var i=[],n=2;n<arguments.length;n++)i[n-2]=arguments[n];if(0<i.length)return plus.apply(void 0,[plus(t,e),i[0]].concat(i.slice(1)));var r=Math.pow(10,Math.max(digitLength(t),digitLength(e)));return(times(t,r)+times(e,r))/r}function minus(t,e){for(var i=[],n=2;n<arguments.length;n++)i[n-2]=arguments[n];if(0<i.length)return minus.apply(void 0,[minus(t,e),i[0]].concat(i.slice(1)));var r=Math.pow(10,Math.max(digitLength(t),digitLength(e)));return(times(t,r)-times(e,r))/r}function divide(t,e){for(var i=[],n=2;n<arguments.length;n++)i[n-2]=arguments[n];if(0<i.length)return divide.apply(void 0,[divide(t,e),i[0]].concat(i.slice(1)));var r=float2Fixed(t),o=float2Fixed(e);return checkBoundary(r),checkBoundary(o),times(r/o,Math.pow(10,digitLength(e)-digitLength(t)))}function round(t,e){var i=Math.pow(10,e);return divide(Math.round(times(t,i)),i)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0,Object.defineProperty(exports,"__esModule",{value:!0});var _boundaryCheckingState=!0;function enableBoundaryChecking(t){void 0===t&&(t=!0),_boundaryCheckingState=t}var index={strip:strip,plus:plus,minus:minus,times:times,divide:divide,round:round,digitLength:digitLength,float2Fixed:float2Fixed,enableBoundaryChecking:enableBoundaryChecking},_default=index;exports.default=_default;