diff --git a/dist/esm/abs.d.ts b/dist/esm/abs.d.ts new file mode 100644 index 0000000..b912da3 --- /dev/null +++ b/dist/esm/abs.d.ts @@ -0,0 +1 @@ +export declare function abs(n: number | string | bigint): string; diff --git a/dist/esm/add.d.ts b/dist/esm/add.d.ts new file mode 100644 index 0000000..4a227f3 --- /dev/null +++ b/dist/esm/add.d.ts @@ -0,0 +1,3 @@ +export declare function add(number1: string, number2?: string): string; +export declare function trim(number: string): string; +export declare function pad(number1: string, number2: string): string[]; diff --git a/dist/esm/big-decimal.d.ts b/dist/esm/big-decimal.d.ts new file mode 100644 index 0000000..556d018 --- /dev/null +++ b/dist/esm/big-decimal.d.ts @@ -0,0 +1,34 @@ +import { RoundingModes as Modes } from "./roundingModes"; +declare class bigDecimal { + private value; + static RoundingModes: typeof Modes; + private static validate; + constructor(number?: number | string | bigint); + getValue(): string; + setValue(num: number | string | bigint): void; + static getPrettyValue(number: any, digits?: number, separator?: string): string; + getPrettyValue(digits?: number, separator?: string): string; + static round(number: any, precision?: number, mode?: Modes): string; + round(precision?: number, mode?: Modes): bigDecimal; + static abs(number: any): string; + abs(): bigDecimal; + static floor(number: any): any; + floor(): bigDecimal; + static ceil(number: any): any; + ceil(): bigDecimal; + static add(number1: any, number2: any): string; + add(number: bigDecimal): bigDecimal; + static subtract(number1: any, number2: any): string; + subtract(number: bigDecimal): bigDecimal; + static multiply(number1: any, number2: any): string; + multiply(number: bigDecimal): bigDecimal; + static divide(number1: any, number2: any, precision?: number): string; + divide(number: bigDecimal, precision: any): bigDecimal; + static modulus(number1: any, number2: any): string; + modulus(number: bigDecimal): bigDecimal; + static compareTo(number1: any, number2: any): 0 | 1 | -1; + compareTo(number: bigDecimal): 0 | 1 | -1; + static negate(number: any): string; + negate(): bigDecimal; +} +export default bigDecimal; diff --git a/dist/esm/big-decimal.js b/dist/esm/big-decimal.js new file mode 100644 index 0000000..94a5776 --- /dev/null +++ b/dist/esm/big-decimal.js @@ -0,0 +1,735 @@ +//function add { +function add(number1, number2) { + var _a; + if (number2 === void 0) { number2 = "0"; } + var neg = 0, ind = -1; + //check for negatives + if (number1[0] == "-") { + number1 = number1.substring(1); + if (!testZero(number1)) { + neg++; + ind = 1; + number1.length; + } + } + if (number2[0] == "-") { + number2 = number2.substring(1); + if (!testZero(number2)) { + neg++; + ind = 2; + number2.length; + } + } + number1 = trim(number1); + number2 = trim(number2); + _a = pad(trim(number1), trim(number2)), number1 = _a[0], number2 = _a[1]; + if (neg == 1) { + if (ind === 1) + number1 = compliment(number1); + else if (ind === 2) + number2 = compliment(number2); + } + var res = addCore(number1, number2); + if (!neg) + return trim(res); + else if (neg == 2) + return "-" + trim(res); + else { + if (number1.length < res.length) + return trim(res.substring(1)); + else + return "-" + trim(compliment(res)); + } +} +function compliment(number) { + if (testZero(number)) { + return number; + } + var s = "", l = number.length, dec = number.split(".")[1], ld = dec ? dec.length : 0; + for (var i = 0; i < l; i++) { + if (number[i] >= "0" && number[i] <= "9") + s += 9 - parseInt(number[i]); + else + s += number[i]; + } + var one = ld > 0 ? "0." + new Array(ld).join("0") + "1" : "1"; + return addCore(s, one); +} +function trim(number) { + var parts = number.split("."); + if (!parts[0]) + parts[0] = "0"; + while (parts[0][0] == "0" && parts[0].length > 1) + parts[0] = parts[0].substring(1); + return parts[0] + (parts[1] ? "." + parts[1] : ""); +} +function pad(number1, number2) { + var parts1 = number1.split("."), parts2 = number2.split("."); + //pad integral part + var length1 = parts1[0].length, length2 = parts2[0].length; + if (length1 > length2) { + parts2[0] = + new Array(Math.abs(length1 - length2) + 1).join("0") + + (parts2[0] ? parts2[0] : ""); + } + else { + parts1[0] = + new Array(Math.abs(length1 - length2) + 1).join("0") + + (parts1[0] ? parts1[0] : ""); + } + //pad fractional part + (length1 = parts1[1] ? parts1[1].length : 0), + (length2 = parts2[1] ? parts2[1].length : 0); + if (length1 || length2) { + if (length1 > length2) { + parts2[1] = + (parts2[1] ? parts2[1] : "") + + new Array(Math.abs(length1 - length2) + 1).join("0"); + } + else { + parts1[1] = + (parts1[1] ? parts1[1] : "") + + new Array(Math.abs(length1 - length2) + 1).join("0"); + } + } + number1 = parts1[0] + (parts1[1] ? "." + parts1[1] : ""); + number2 = parts2[0] + (parts2[1] ? "." + parts2[1] : ""); + return [number1, number2]; +} +function addCore(number1, number2) { + var _a; + _a = pad(number1, number2), number1 = _a[0], number2 = _a[1]; + var sum = "", carry = 0; + for (var i = number1.length - 1; i >= 0; i--) { + if (number1[i] === ".") { + sum = "." + sum; + continue; + } + var temp = parseInt(number1[i]) + parseInt(number2[i]) + carry; + sum = (temp % 10) + sum; + carry = Math.floor(temp / 10); + } + return carry ? carry.toString() + sum : sum; +} +function testZero(number) { + return /^0[0]*[.]{0,1}[0]*$/.test(number); +} + +function abs(n) { + if (typeof n == "number" || typeof n == "bigint") + n = n.toString(); + if (n[0] == "-") + return n.substring(1); + return n; +} + +var RoundingModes; +(function (RoundingModes) { + /** + * Rounding mode to round towards positive infinity. + */ + RoundingModes[RoundingModes["CEILING"] = 0] = "CEILING"; + /** + * Rounding mode to round towards zero. + */ + RoundingModes[RoundingModes["DOWN"] = 1] = "DOWN"; + /** + * Rounding mode to round towards negative infinity. + */ + RoundingModes[RoundingModes["FLOOR"] = 2] = "FLOOR"; + /** + * Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, + * in which case round down. + */ + RoundingModes[RoundingModes["HALF_DOWN"] = 3] = "HALF_DOWN"; + /** + * Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, + * in which case, round towards the even neighbor. + */ + RoundingModes[RoundingModes["HALF_EVEN"] = 4] = "HALF_EVEN"; + /** + * Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, + * in which case round up. + */ + RoundingModes[RoundingModes["HALF_UP"] = 5] = "HALF_UP"; + /** + * Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary. + * UNIMPLEMENTED + */ + RoundingModes[RoundingModes["UNNECESSARY"] = 6] = "UNNECESSARY"; + /** + * Rounding mode to round away from zero. + */ + RoundingModes[RoundingModes["UP"] = 7] = "UP"; +})(RoundingModes || (RoundingModes = {})); + +/** + * + * @param input the number to round + * @param n precision + * @param mode Rounding Mode + */ +function roundOff(input, n, mode) { + if (n === void 0) { n = 0; } + if (mode === void 0) { mode = RoundingModes.HALF_EVEN; } + if (mode === RoundingModes.UNNECESSARY) { + throw new Error("UNNECESSARY Rounding Mode has not yet been implemented"); + } + if (typeof (input) == 'number' || typeof (input) == 'bigint') + input = input.toString(); + var neg = false; + if (input[0] === '-') { + neg = true; + input = input.substring(1); + } + var parts = input.split('.'), partInt = parts[0], partDec = parts[1]; + //handle case of -ve n: roundOff(12564,-2)=12600 + if (n < 0) { + n = -n; + if (partInt.length <= n) + return '0'; + else { + var prefix = partInt.substr(0, partInt.length - n); + input = prefix + '.' + partInt.substr(partInt.length - n) + partDec; + prefix = roundOff(input, 0, mode); + return (neg ? '-' : '') + prefix + (new Array(n + 1).join('0')); + } + } + // handle case when integer output is desired + if (n == 0) { + partInt.length; + if (greaterThanFive(parts[1], partInt, neg, mode)) { + partInt = increment(partInt); + } + return (neg && parseInt(partInt) ? '-' : '') + partInt; + } + // handle case when n>0 + if (!parts[1]) { + return (neg ? '-' : '') + partInt + '.' + (new Array(n + 1).join('0')); + } + else if (parts[1].length < n) { + return (neg ? '-' : '') + partInt + '.' + parts[1] + (new Array(n - parts[1].length + 1).join('0')); + } + partDec = parts[1].substring(0, n); + var rem = parts[1].substring(n); + if (rem && greaterThanFive(rem, partDec, neg, mode)) { + partDec = increment(partDec); + if (partDec.length > n) { + return (neg ? '-' : '') + increment(partInt, parseInt(partDec[0])) + '.' + partDec.substring(1); + } + } + return (neg && (parseInt(partInt) || parseInt(partDec)) ? '-' : '') + partInt + '.' + partDec; +} +function greaterThanFive(part, pre, neg, mode) { + if (!part || part === new Array(part.length + 1).join('0')) + return false; + // #region UP, DOWN, CEILING, FLOOR + if (mode === RoundingModes.DOWN || (!neg && mode === RoundingModes.FLOOR) || + (neg && mode === RoundingModes.CEILING)) + return false; + if (mode === RoundingModes.UP || (neg && mode === RoundingModes.FLOOR) || + (!neg && mode === RoundingModes.CEILING)) + return true; + // #endregion + // case when part !== five + var five = '5' + (new Array(part.length).join('0')); + if (part > five) + return true; + else if (part < five) + return false; + // case when part === five + switch (mode) { + case RoundingModes.HALF_DOWN: return false; + case RoundingModes.HALF_UP: return true; + case RoundingModes.HALF_EVEN: + default: return (parseInt(pre[pre.length - 1]) % 2 == 1); + } +} +function increment(part, c) { + if (c === void 0) { c = 0; } + if (!c) + c = 1; + if (typeof (part) == 'number') + part.toString(); + var l = part.length - 1, s = ''; + for (var i = l; i >= 0; i--) { + var x = parseInt(part[i]) + c; + if (x == 10) { + c = 1; + x = 0; + } + else { + c = 0; + } + s += x; + } + if (c) + s += c; + return s.split('').reverse().join(''); +} + +function multiply(number1, number2) { + number1 = number1.toString(); + number2 = number2.toString(); + /*Filter numbers*/ + var negative = 0; + if (number1[0] == '-') { + negative++; + number1 = number1.substr(1); + } + if (number2[0] == '-') { + negative++; + number2 = number2.substr(1); + } + number1 = trailZero(number1); + number2 = trailZero(number2); + var decimalLength1 = 0; + var decimalLength2 = 0; + if (number1.indexOf('.') != -1) { + decimalLength1 = number1.length - number1.indexOf('.') - 1; + } + if (number2.indexOf('.') != -1) { + decimalLength2 = number2.length - number2.indexOf('.') - 1; + } + var decimalLength = decimalLength1 + decimalLength2; + number1 = trailZero(number1.replace('.', '')); + number2 = trailZero(number2.replace('.', '')); + if (number1.length < number2.length) { + var temp = number1; + number1 = number2; + number2 = temp; + } + if (number2 == '0') { + return '0'; + } + /* + * Core multiplication + */ + var length = number2.length; + var carry = 0; + var positionVector = []; + var currentPosition = length - 1; + var result = ""; + for (var i = 0; i < length; i++) { + positionVector[i] = number1.length - 1; + } + for (var i = 0; i < 2 * number1.length; i++) { + var sum = 0; + for (var j = number2.length - 1; j >= currentPosition && j >= 0; j--) { + if (positionVector[j] > -1 && positionVector[j] < number1.length) { + sum += parseInt(number1[positionVector[j]--]) * parseInt(number2[j]); + } + } + sum += carry; + carry = Math.floor(sum / 10); + result = sum % 10 + result; + currentPosition--; + } + /* + * Formatting result + */ + result = trailZero(adjustDecimal(result, decimalLength)); + if (negative == 1) { + result = '-' + result; + } + return result; +} +/* +* Add decimal point +*/ +function adjustDecimal(number, decimal) { + if (decimal == 0) + return number; + else { + number = (decimal >= number.length) ? ((new Array(decimal - number.length + 1)).join('0') + number) : number; + return number.substr(0, number.length - decimal) + '.' + number.substr(number.length - decimal, decimal); + } +} +/* +* Removes zero from front and back*/ +function trailZero(number) { + while (number[0] == '0') { + number = number.substr(1); + } + if (number.indexOf('.') != -1) { + while (number[number.length - 1] == '0') { + number = number.substr(0, number.length - 1); + } + } + if (number == "" || number == ".") { + number = '0'; + } + else if (number[number.length - 1] == '.') { + number = number.substr(0, number.length - 1); + } + if (number[0] == '.') { + number = '0' + number; + } + return number; +} + +function divide(dividend, divisor, precission) { + if (precission === void 0) { precission = 8; } + if (divisor == 0) { + throw new Error('Cannot divide by 0'); + } + dividend = dividend.toString(); + divisor = divisor.toString(); + // remove trailing zeros in decimal ISSUE#18 + dividend = dividend.replace(/(\.\d*?[1-9])0+$/g, "$1").replace(/\.0+$/, ""); + divisor = divisor.replace(/(\.\d*?[1-9])0+$/g, "$1").replace(/\.0+$/, ""); + if (dividend == 0) + return '0'; + var neg = 0; + if (divisor[0] == '-') { + divisor = divisor.substring(1); + neg++; + } + if (dividend[0] == '-') { + dividend = dividend.substring(1); + neg++; + } + var pt_dvsr = divisor.indexOf('.') > 0 ? divisor.length - divisor.indexOf('.') - 1 : -1; + divisor = trim(divisor.replace('.', '')); + if (pt_dvsr >= 0) { + var pt_dvnd = dividend.indexOf('.') > 0 ? dividend.length - dividend.indexOf('.') - 1 : -1; + if (pt_dvnd == -1) { + dividend = trim(dividend + (new Array(pt_dvsr + 1)).join('0')); + } + else { + if (pt_dvsr > pt_dvnd) { + dividend = dividend.replace('.', ''); + dividend = trim(dividend + (new Array(pt_dvsr - pt_dvnd + 1)).join('0')); + } + else if (pt_dvsr < pt_dvnd) { + dividend = dividend.replace('.', ''); + var loc = dividend.length - pt_dvnd + pt_dvsr; + dividend = trim(dividend.substring(0, loc) + '.' + dividend.substring(loc)); + } + else if (pt_dvsr == pt_dvnd) { + dividend = trim(dividend.replace('.', '')); + } + } + } + var prec = 0, dl = divisor.length, quotent = ''; + var dvnd = (dividend.indexOf('.') > -1 && dividend.indexOf('.') < dl) ? dividend.substring(0, dl + 1) : dividend.substring(0, dl); + dividend = (dividend.indexOf('.') > -1 && dividend.indexOf('.') < dl) ? dividend.substring(dl + 1) : dividend.substring(dl); + if (dvnd.indexOf('.') > -1) { + var shift = dvnd.length - dvnd.indexOf('.') - 1; + dvnd = dvnd.replace('.', ''); + if (dl > dvnd.length) { + shift += dl - dvnd.length; + dvnd = dvnd + (new Array(dl - dvnd.length + 1)).join('0'); + } + prec = shift; + quotent = '0.' + (new Array(shift)).join('0'); + } + precission = precission + 2; + while (prec <= precission) { + var qt = 0; + while (parseInt(dvnd) >= parseInt(divisor)) { + dvnd = add(dvnd, '-' + divisor); + qt++; + } + quotent += qt; + if (!dividend) { + if (!prec) + quotent += '.'; + prec++; + dvnd = dvnd + '0'; + } + else { + if (dividend[0] == '.') { + quotent += '.'; + prec++; + dividend = dividend.substring(1); + } + dvnd = dvnd + dividend.substring(0, 1); + dividend = dividend.substring(1); + } + } + return ((neg == 1) ? '-' : '') + trim(roundOff(quotent, precission - 2)); +} + +function subtract(number1, number2) { + number1 = number1.toString(); + number2 = number2.toString(); + number2 = negate(number2); + return add(number1, number2); +} +function negate(number) { + if (number[0] == '-') { + number = number.substr(1); + } + else { + number = '-' + number; + } + return number; +} + +function modulus(dividend, divisor) { + if (divisor == 0) { + throw new Error('Cannot divide by 0'); + } + dividend = dividend.toString(); + divisor = divisor.toString(); + validate(dividend); + validate(divisor); + var sign = ''; + if (dividend[0] == '-') { + sign = '-'; + dividend = dividend.substr(1); + } + if (divisor[0] == '-') { + divisor = divisor.substr(1); + } + var result = subtract(dividend, multiply(divisor, roundOff(divide(dividend, divisor), 0, RoundingModes.FLOOR))); + return sign + result; +} +function validate(oparand) { + if (oparand.indexOf('.') != -1) { + throw new Error('Modulus of non-integers not supported'); + } +} + +function compareTo(number1, number2) { + var _a; + var negative = false; + if (number1[0] == '-' && number2[0] != "-") { + return -1; + } + else if (number1[0] != '-' && number2[0] == '-') { + return 1; + } + else if (number1[0] == '-' && number2[0] == '-') { + number1 = number1.substr(1); + number2 = number2.substr(1); + negative = true; + } + _a = pad(number1, number2), number1 = _a[0], number2 = _a[1]; + if (number1.localeCompare(number2) == 0) { + return 0; + } + for (var i = 0; i < number1.length; i++) { + if (number1[i] == number2[i]) { + continue; + } + else if (number1[i] > number2[i]) { + if (negative) { + return -1; + } + else { + return 1; + } + } + else { + if (negative) { + return 1; + } + else { + return -1; + } + } + } + return 0; +} + +var bigDecimal = /** @class */ (function () { + function bigDecimal(number) { + if (number === void 0) { number = "0"; } + this.value = bigDecimal.validate(number); + } + bigDecimal.validate = function (number) { + if (number) { + number = number.toString(); + if (isNaN(number)) + throw Error("Parameter is not a number: " + number); + if (number[0] == "+") + number = number.substring(1); + } + else + number = "0"; + //handle missing leading zero + if (number.startsWith(".")) + number = "0" + number; + else if (number.startsWith("-.")) + number = "-0" + number.substr(1); + //handle exponentiation + if (/e/i.test(number)) { + var _a = number.split(/[eE]/), mantisa = _a[0], exponent = _a[1]; + mantisa = trim(mantisa); + var sign = ""; + if (mantisa[0] == "-") { + sign = "-"; + mantisa = mantisa.substring(1); + } + if (mantisa.indexOf(".") >= 0) { + exponent = parseInt(exponent) + mantisa.indexOf("."); + mantisa = mantisa.replace(".", ""); + } + else { + exponent = parseInt(exponent) + mantisa.length; + } + if (mantisa.length < exponent) { + number = + sign + mantisa + new Array(exponent - mantisa.length + 1).join("0"); + } + else if (mantisa.length >= exponent && exponent > 0) { + number = + sign + + trim(mantisa.substring(0, exponent)) + + (mantisa.length > exponent ? "." + mantisa.substring(exponent) : ""); + } + else { + number = sign + "0." + new Array(-exponent + 1).join("0") + mantisa; + } + } + return number; + }; + bigDecimal.prototype.getValue = function () { + return this.value; + }; + bigDecimal.prototype.setValue = function (num) { + this.value = bigDecimal.validate(num); + }; + bigDecimal.getPrettyValue = function (number, digits, separator) { + if (digits === void 0) { digits = 3; } + if (separator === void 0) { separator = ","; } + // if (!(digits || separator)) { + // digits = 3; + // separator = ','; + // } else if (!(digits && separator)) { + // throw Error('Illegal Arguments. Should pass both digits and separator or pass none'); + // } + number = bigDecimal.validate(number); + var neg = number.charAt(0) == "-"; + if (neg) + number = number.substring(1); + var len = number.indexOf("."); + len = len > 0 ? len : number.length; + var temp = ""; + for (var i = len; i > 0;) { + if (i < digits) { + digits = i; + i = 0; + } + else + i -= digits; + temp = + number.substring(i, i + digits) + + (i < len - digits && i >= 0 ? separator : "") + + temp; + } + return (neg ? "-" : "") + temp + number.substring(len); + }; + bigDecimal.prototype.getPrettyValue = function (digits, separator) { + if (digits === void 0) { digits = 3; } + if (separator === void 0) { separator = ","; } + return bigDecimal.getPrettyValue(this.value, digits, separator); + }; + bigDecimal.round = function (number, precision, mode) { + if (precision === void 0) { precision = 0; } + if (mode === void 0) { mode = RoundingModes.HALF_EVEN; } + number = bigDecimal.validate(number); + // console.log(number) + if (isNaN(precision)) + throw Error("Precision is not a number: " + precision); + return roundOff(number, precision, mode); + }; + bigDecimal.prototype.round = function (precision, mode) { + if (precision === void 0) { precision = 0; } + if (mode === void 0) { mode = RoundingModes.HALF_EVEN; } + if (isNaN(precision)) + throw Error("Precision is not a number: " + precision); + return new bigDecimal(roundOff(this.value, precision, mode)); + }; + bigDecimal.abs = function (number) { + number = bigDecimal.validate(number); + return abs(number); + }; + bigDecimal.prototype.abs = function () { + return new bigDecimal(abs(this.value)); + }; + bigDecimal.floor = function (number) { + number = bigDecimal.validate(number); + if (number.indexOf(".") === -1) + return number; + return bigDecimal.round(number, 0, RoundingModes.FLOOR); + }; + bigDecimal.prototype.floor = function () { + if (this.value.indexOf(".") === -1) + return new bigDecimal(this.value); + return new bigDecimal(this.value).round(0, RoundingModes.FLOOR); + }; + bigDecimal.ceil = function (number) { + number = bigDecimal.validate(number); + if (number.indexOf(".") === -1) + return number; + return bigDecimal.round(number, 0, RoundingModes.CEILING); + }; + bigDecimal.prototype.ceil = function () { + if (this.value.indexOf(".") === -1) + return new bigDecimal(this.value); + return new bigDecimal(this.value).round(0, RoundingModes.CEILING); + }; + bigDecimal.add = function (number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return add(number1, number2); + }; + bigDecimal.prototype.add = function (number) { + return new bigDecimal(add(this.value, number.getValue())); + }; + bigDecimal.subtract = function (number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return subtract(number1, number2); + }; + bigDecimal.prototype.subtract = function (number) { + return new bigDecimal(subtract(this.value, number.getValue())); + }; + bigDecimal.multiply = function (number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return multiply(number1, number2); + }; + bigDecimal.prototype.multiply = function (number) { + return new bigDecimal(multiply(this.value, number.getValue())); + }; + bigDecimal.divide = function (number1, number2, precision) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return divide(number1, number2, precision); + }; + bigDecimal.prototype.divide = function (number, precision) { + return new bigDecimal(divide(this.value, number.getValue(), precision)); + }; + bigDecimal.modulus = function (number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return modulus(number1, number2); + }; + bigDecimal.prototype.modulus = function (number) { + return new bigDecimal(modulus(this.value, number.getValue())); + }; + bigDecimal.compareTo = function (number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return compareTo(number1, number2); + }; + bigDecimal.prototype.compareTo = function (number) { + return compareTo(this.value, number.getValue()); + }; + bigDecimal.negate = function (number) { + number = bigDecimal.validate(number); + return negate(number); + }; + bigDecimal.prototype.negate = function () { + return new bigDecimal(negate(this.value)); + }; + bigDecimal.RoundingModes = RoundingModes; + return bigDecimal; +}()); + +export { bigDecimal as default }; +//# sourceMappingURL=big-decimal.js.map diff --git a/dist/esm/big-decimal.js.map b/dist/esm/big-decimal.js.map new file mode 100644 index 0000000..6d42104 --- /dev/null +++ b/dist/esm/big-decimal.js.map @@ -0,0 +1 @@ +{"version":3,"file":"big-decimal.js","sources":["../../../src/add.ts","../../../src/abs.ts","../../../src/roundingModes.ts","../../../src/round.ts","../../../src/multiply.ts","../../../src/divide.ts","../../../src/subtract.ts","../../../src/modulus.ts","../../../src/compareTo.ts","../../../src/big-decimal.ts"],"sourcesContent":["//function add {\nexport function add(number1: string, number2 = \"0\") {\n let neg = 0,\n ind = -1,\n neg_len;\n\n //check for negatives\n if (number1[0] == \"-\") {\n number1 = number1.substring(1);\n if (!testZero(number1)) {\n neg++;\n ind = 1;\n neg_len = number1.length;\n }\n }\n if (number2[0] == \"-\") {\n number2 = number2.substring(1);\n if (!testZero(number2)) {\n neg++;\n ind = 2;\n neg_len = number2.length;\n }\n }\n\n number1 = trim(number1);\n number2 = trim(number2);\n\n [number1, number2] = pad(trim(number1), trim(number2));\n\n if (neg == 1) {\n if (ind === 1) number1 = compliment(number1);\n else if (ind === 2) number2 = compliment(number2);\n }\n\n let res = addCore(number1, number2);\n if (!neg) return trim(res);\n else if (neg == 2) return \"-\" + trim(res);\n else {\n if (number1.length < res.length) return trim(res.substring(1));\n else return \"-\" + trim(compliment(res));\n }\n}\n\nfunction compliment(number: string) {\n if (testZero(number)) {\n return number;\n }\n\n let s = \"\",\n l = number.length,\n dec = number.split(\".\")[1],\n ld = dec ? dec.length : 0;\n\n for (let i = 0; i < l; i++) {\n if (number[i] >= \"0\" && number[i] <= \"9\") s += 9 - parseInt(number[i]);\n else s += number[i];\n }\n\n let one = ld > 0 ? \"0.\" + new Array(ld).join(\"0\") + \"1\" : \"1\";\n\n return addCore(s, one);\n}\n\nexport function trim(number: string) {\n let parts = number.split(\".\");\n\n if (!parts[0]) parts[0] = \"0\";\n\n while (parts[0][0] == \"0\" && parts[0].length > 1)\n parts[0] = parts[0].substring(1);\n\n return parts[0] + (parts[1] ? \".\" + parts[1] : \"\");\n}\n\nexport function pad(number1: string, number2: string) {\n let parts1 = number1.split(\".\"),\n parts2 = number2.split(\".\");\n\n //pad integral part\n let length1 = parts1[0].length,\n length2 = parts2[0].length;\n if (length1 > length2) {\n parts2[0] =\n new Array(Math.abs(length1 - length2) + 1).join(\"0\") +\n (parts2[0] ? parts2[0] : \"\");\n } else {\n parts1[0] =\n new Array(Math.abs(length1 - length2) + 1).join(\"0\") +\n (parts1[0] ? parts1[0] : \"\");\n }\n\n //pad fractional part\n (length1 = parts1[1] ? parts1[1].length : 0),\n (length2 = parts2[1] ? parts2[1].length : 0);\n if (length1 || length2) {\n if (length1 > length2) {\n parts2[1] =\n (parts2[1] ? parts2[1] : \"\") +\n new Array(Math.abs(length1 - length2) + 1).join(\"0\");\n } else {\n parts1[1] =\n (parts1[1] ? parts1[1] : \"\") +\n new Array(Math.abs(length1 - length2) + 1).join(\"0\");\n }\n }\n\n number1 = parts1[0] + (parts1[1] ? \".\" + parts1[1] : \"\");\n number2 = parts2[0] + (parts2[1] ? \".\" + parts2[1] : \"\");\n\n return [number1, number2];\n}\n\nfunction addCore(number1: string, number2: string) {\n [number1, number2] = pad(number1, number2);\n\n let sum = \"\",\n carry = 0;\n\n for (let i = number1.length - 1; i >= 0; i--) {\n if (number1[i] === \".\") {\n sum = \".\" + sum;\n continue;\n }\n let temp = parseInt(number1[i]) + parseInt(number2[i]) + carry;\n sum = (temp % 10) + sum;\n carry = Math.floor(temp / 10);\n }\n\n return carry ? carry.toString() + sum : sum;\n}\n\nfunction testZero(number: string) {\n return /^0[0]*[.]{0,1}[0]*$/.test(number);\n}\n","export function abs(n: number | string | bigint) {\n if (typeof n == \"number\" || typeof n == \"bigint\") n = n.toString();\n if (n[0] == \"-\") return n.substring(1);\n return n;\n}\n","export enum RoundingModes {\n /**\n * Rounding mode to round towards positive infinity.\n */\n CEILING,\n\n /**\n * Rounding mode to round towards zero.\n */\n DOWN,\n\n /**\n * Rounding mode to round towards negative infinity.\n */\n FLOOR,\n\n /**\n * Rounding mode to round towards \"nearest neighbor\" unless both neighbors are equidistant, \n * in which case round down.\n */\n HALF_DOWN,\n\n /**\n * Rounding mode to round towards the \"nearest neighbor\" unless both neighbors are equidistant, \n * in which case, round towards the even neighbor.\n */\n HALF_EVEN,\n\n /**\n * Rounding mode to round towards \"nearest neighbor\" unless both neighbors are equidistant, \n * in which case round up.\n */\n HALF_UP,\n\n /**\n * Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary.\n * UNIMPLEMENTED\n */\n UNNECESSARY,\n\n /**\n * Rounding mode to round away from zero.\n */\n UP\n}\n\n","import { RoundingModes } from './roundingModes';\n/**\n * \n * @param input the number to round\n * @param n precision\n * @param mode Rounding Mode\n */\nexport function roundOff(input: number | string | bigint, n: number = 0, mode=RoundingModes.HALF_EVEN) {\n if (mode === RoundingModes.UNNECESSARY) {\n throw new Error(\"UNNECESSARY Rounding Mode has not yet been implemented\");\n }\n\n if (typeof (input) == 'number' || typeof (input) == 'bigint')\n input = input.toString();\n\n let neg = false;\n if (input[0] === '-') {\n neg = true;\n input = input.substring(1);\n }\n\n let parts = input.split('.'),\n partInt = parts[0],\n partDec = parts[1];\n\n //handle case of -ve n: roundOff(12564,-2)=12600\n if (n < 0) {\n n = -n;\n if (partInt.length <= n)\n return '0';\n else {\n let prefix = partInt.substr(0, partInt.length - n);\n input = prefix + '.' + partInt.substr(partInt.length - n) + partDec;\n prefix = roundOff(input, 0, mode);\n return (neg ? '-' : '') + prefix + (new Array(n + 1).join('0'));\n }\n }\n\n\n // handle case when integer output is desired\n if (n == 0) {\n let l = partInt.length;\n if (greaterThanFive(parts[1], partInt, neg, mode)) {\n partInt = increment(partInt);\n }\n return (neg&&parseInt(partInt) ? '-' : '') + partInt;\n }\n\n\n // handle case when n>0\n if (!parts[1]) {\n return (neg ? '-' : '') + partInt + '.' + (new Array(n + 1).join('0'));\n } else if (parts[1].length < n) {\n return (neg ? '-' : '') + partInt + '.' + parts[1] + (new Array(n - parts[1].length + 1).join('0'));\n }\n\n partDec = parts[1].substring(0, n);\n let rem = parts[1].substring(n);\n\n if (rem && greaterThanFive(rem, partDec, neg, mode)) {\n partDec = increment(partDec);\n if (partDec.length > n) {\n return (neg ? '-' : '') + increment(partInt, parseInt(partDec[0])) + '.' + partDec.substring(1);\n }\n }\n return (neg&&(parseInt(partInt) || parseInt(partDec)) ? '-' : '') + partInt + '.' + partDec;\n}\n\nfunction greaterThanFive(part: string, pre: string, neg: boolean, mode: RoundingModes) {\n if (!part || part === new Array(part.length + 1).join('0'))\n return false;\n\n // #region UP, DOWN, CEILING, FLOOR \n if (mode === RoundingModes.DOWN || (!neg && mode === RoundingModes.FLOOR) ||\n (neg && mode === RoundingModes.CEILING))\n return false;\n\n if (mode === RoundingModes.UP || (neg && mode === RoundingModes.FLOOR) ||\n (!neg && mode === RoundingModes.CEILING))\n return true;\n // #endregion\n\n // case when part !== five\n let five = '5' + (new Array(part.length).join('0'));\n if (part > five)\n return true;\n else if (part < five)\n return false;\n\n // case when part === five\n switch (mode) {\n case RoundingModes.HALF_DOWN: return false;\n case RoundingModes.HALF_UP: return true;\n case RoundingModes.HALF_EVEN:\n default: return (parseInt(pre[pre.length - 1]) % 2 == 1)\n }\n}\n\nfunction increment(part, c: number = 0) {\n if (!c)\n c = 1;\n if (typeof (part) == 'number')\n part.toString();\n\n let l = part.length - 1,\n s = '';\n\n for (let i = l; i >= 0; i--) {\n let x = parseInt(part[i]) + c;\n if (x == 10) {\n c = 1; x = 0;\n } else {\n c = 0;\n }\n s += x;\n }\n if (c)\n s += c;\n\n return s.split('').reverse().join('');\n}","export function multiply(number1, number2) {\n\tnumber1 = number1.toString();\n\tnumber2 = number2.toString();\n\n\t/*Filter numbers*/\n\tlet negative = 0;\n\tif (number1[0] == '-') {\n\t\tnegative++;\n\t\tnumber1 = number1.substr(1);\n\t}\n\tif (number2[0] == '-') {\n\t\tnegative++;\n\t\tnumber2 = number2.substr(1);\n\t}\n\tnumber1 = trailZero(number1);\n\tnumber2 = trailZero(number2);\n\tlet decimalLength1 = 0;\n\tlet decimalLength2 = 0;\n\n\tif (number1.indexOf('.') != -1) {\n\t\tdecimalLength1 = number1.length - number1.indexOf('.') - 1;\n\t}\n\n\tif (number2.indexOf('.') != -1) {\n\t\tdecimalLength2 = number2.length - number2.indexOf('.') - 1;\n\t}\n\tlet decimalLength = decimalLength1 + decimalLength2;\n\tnumber1 = trailZero(number1.replace('.', ''));\n\tnumber2 = trailZero(number2.replace('.', ''));\n\n\tif (number1.length < number2.length) {\n\t\tlet temp = number1;\n\t\tnumber1 = number2;\n\t\tnumber2 = temp;\n\t}\n\n\tif (number2 == '0') {\n\t\treturn '0';\n\t}\n\n\t/*\n\t* Core multiplication\n\t*/\n\tlet length = number2.length;\n\tlet carry = 0;\n\tlet positionVector = [];\n\tlet currentPosition = length - 1;\n\n\tlet result = \"\";\n\tfor (let i = 0; i < length; i++) {\n\t\tpositionVector[i] = number1.length - 1;\n\t}\n\tfor (let i = 0; i < 2 * number1.length; i++) {\n\t\tlet sum = 0;\n\t\tfor (let j = number2.length - 1; j >= currentPosition && j >= 0; j--) {\n\t\t\tif (positionVector[j] > -1 && positionVector[j] < number1.length) {\n\t\t\t\tsum += parseInt(number1[positionVector[j]--]) * parseInt(number2[j]);\n\t\t\t}\n\t\t}\n\t\tsum += carry;\n\t\tcarry = Math.floor(sum / 10);\n\t\tresult = sum % 10 + result;\n\t\tcurrentPosition--;\n\t}\n\t/*\n\t* Formatting result\n\t*/\n\tresult = trailZero(adjustDecimal(result, decimalLength));\n\tif (negative == 1) {\n\t\tresult = '-' + result;\n\t}\n\treturn result;\n}\n\n/*\n* Add decimal point\n*/\nfunction adjustDecimal(number, decimal) {\n\tif (decimal == 0)\n\t\treturn number;\n\telse {\n\t\tnumber = (decimal >= number.length) ? ((new Array(decimal - number.length + 1)).join('0') + number) : number;\n\t\treturn number.substr(0, number.length - decimal) + '.' + number.substr(number.length - decimal, decimal)\n\t}\n}\n\n/*\n* Removes zero from front and back*/\nfunction trailZero(number) {\n\twhile (number[0] == '0') {\n\t\tnumber = number.substr(1);\n\t}\n\tif (number.indexOf('.') != -1) {\n\t\twhile (number[number.length - 1] == '0') {\n\t\t\tnumber = number.substr(0, number.length - 1);\n\t\t}\n\t}\n\tif (number == \"\" || number == \".\") {\n\t\tnumber = '0';\n\t} else if (number[number.length - 1] == '.') {\n\t\tnumber = number.substr(0, number.length - 1);\n\t}\n\tif (number[0] == '.') {\n\t\tnumber = '0' + number;\n\t}\n\treturn number;\n}","import { add, trim } from './add';\nimport { roundOff } from './round';\n\nexport function divide(dividend, divisor, precission = 8) {\n if (divisor == 0) {\n throw new Error('Cannot divide by 0');\n }\n\n dividend = dividend.toString();\n divisor = divisor.toString();\n\n // remove trailing zeros in decimal ISSUE#18\n dividend = dividend.replace(/(\\.\\d*?[1-9])0+$/g, \"$1\").replace(/\\.0+$/, \"\");\n divisor = divisor.replace(/(\\.\\d*?[1-9])0+$/g, \"$1\").replace(/\\.0+$/, \"\");\n\n if (dividend == 0)\n return '0';\n\n let neg = 0;\n if (divisor[0] == '-') {\n divisor = divisor.substring(1);\n neg++;\n }\n if (dividend[0] == '-') {\n dividend = dividend.substring(1);\n neg++;\n }\n\n var pt_dvsr = divisor.indexOf('.') > 0 ? divisor.length - divisor.indexOf('.') - 1 : -1;\n\n divisor = trim(divisor.replace('.', ''));\n if (pt_dvsr >= 0) {\n let pt_dvnd = dividend.indexOf('.') > 0 ? dividend.length - dividend.indexOf('.') - 1 : -1;\n\n if (pt_dvnd == -1) {\n dividend = trim(dividend + (new Array(pt_dvsr + 1)).join('0'));\n } else {\n if (pt_dvsr > pt_dvnd) {\n dividend = dividend.replace('.', '');\n dividend = trim(dividend + (new Array(pt_dvsr - pt_dvnd + 1)).join('0'));\n } else if (pt_dvsr < pt_dvnd) {\n dividend = dividend.replace('.', '');\n let loc = dividend.length - pt_dvnd + pt_dvsr;\n dividend = trim(dividend.substring(0, loc) + '.' + dividend.substring(loc));\n } else if (pt_dvsr == pt_dvnd) {\n dividend = trim(dividend.replace('.', ''));\n }\n }\n }\n\n let prec = 0, dl = divisor.length, rem = '0', quotent = '';\n let dvnd = (dividend.indexOf('.') > -1 && dividend.indexOf('.') < dl) ? dividend.substring(0, dl + 1) : dividend.substring(0, dl);\n dividend = (dividend.indexOf('.') > -1 && dividend.indexOf('.') < dl) ? dividend.substring(dl + 1) : dividend.substring(dl);\n \n if (dvnd.indexOf('.') > -1) {\n let shift = dvnd.length - dvnd.indexOf('.') - 1;\n dvnd = dvnd.replace('.', '');\n if (dl > dvnd.length) {\n shift += dl - dvnd.length;\n dvnd = dvnd + (new Array(dl - dvnd.length + 1)).join('0');\n }\n prec = shift;\n quotent = '0.' + (new Array(shift)).join('0');\n\n }\n\n precission = precission + 2;\n\n while (prec <= precission) {\n let qt = 0;\n while (parseInt(dvnd) >= parseInt(divisor)) {\n dvnd = add(dvnd, '-' + divisor);\n qt++;\n }\n quotent += qt;\n\n if (!dividend) {\n if (!prec)\n quotent += '.';\n prec++;\n dvnd = dvnd + '0';\n } else {\n if (dividend[0] == '.') {\n quotent += '.';\n prec++;\n dividend = dividend.substring(1);\n }\n dvnd = dvnd + dividend.substring(0, 1);\n dividend = dividend.substring(1);\n }\n }\n\n return ((neg == 1) ? '-' : '') + trim(roundOff(quotent, precission - 2));\n}","import { add } from './add';\r\n\r\nexport function subtract(number1, number2) {\r\n\tnumber1 = number1.toString();\r\n\tnumber2 = number2.toString();\r\n\tnumber2 = negate(number2);\r\n\treturn add(number1, number2);\r\n}\r\n\r\nexport function negate(number : string){\r\n\tif(number[0] == '-'){\r\n\t\tnumber = number.substr(1);\r\n\t}else{\r\n\t\tnumber = '-' + number;\r\n\t}\r\n\treturn number;\r\n}","import { divide } from './divide';\nimport { roundOff } from './round';\nimport { multiply } from './multiply';\nimport { subtract } from './subtract';\nimport { RoundingModes } from './roundingModes';\n\nexport function modulus(dividend: number|string, divisor:number|string) {\n if (divisor == 0) {\n throw new Error('Cannot divide by 0');\n }\n\n dividend = dividend.toString();\n divisor = divisor.toString();\n\n validate(dividend);\n validate(divisor);\n\n let sign = '';\n if(dividend[0] == '-'){\n sign = '-';\n dividend = dividend.substr(1);\n }\n if(divisor[0] == '-'){\n divisor = divisor.substr(1);\n }\n\n let result = subtract(dividend, multiply(divisor, roundOff(divide(dividend, divisor), 0, RoundingModes.FLOOR)));\n return sign+result;\n}\n\nfunction validate(oparand: string) {\n if (oparand.indexOf('.') != -1) {\n throw new Error('Modulus of non-integers not supported');\n }\n}\n","import { pad } from './add';\r\n\r\nexport function compareTo(number1 : string, number2 : string) {\r\n\tlet negative = false;\r\n\tif(number1[0] == '-' && number2[0] != \"-\"){\r\n\t\treturn -1;\r\n\t}else if(number1[0] != '-' && number2[0] == '-'){\r\n\t\treturn 1;\r\n\t}else if(number1[0] == '-' && number2[0] == '-'){\r\n\t\tnumber1 = number1.substr(1);\r\n\t\tnumber2 = number2.substr(1);\r\n\t\tnegative = true;\r\n\t}\r\n\t[number1, number2] = pad(number1, number2);\r\n\tif(number1.localeCompare(number2) == 0){\r\n\t\treturn 0;\r\n\t}\r\n\tfor(let i = 0 ; i < number1.length ; i++){\r\n\t\tif(number1[i] == number2[i]){\r\n\t\t\tcontinue;\r\n\t\t}else if(number1[i] > number2[i]){\r\n\t\t\tif(negative){\r\n\t\t\t\treturn -1;\r\n\t\t\t}else{\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}else{\r\n\t\t\tif(negative){\r\n\t\t\t\treturn 1;\r\n\t\t\t}else{\r\n\t\t\t\treturn -1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn 0;\r\n}","import { add, trim } from \"./add\";\r\nimport { abs } from \"./abs\";\r\nimport { roundOff } from \"./round\";\r\nimport { multiply } from \"./multiply\";\r\nimport { divide } from \"./divide\";\r\nimport { modulus } from \"./modulus\";\r\nimport { compareTo } from \"./compareTo\";\r\nimport { subtract, negate } from \"./subtract\";\r\nimport { RoundingModes as Modes, RoundingModes } from \"./roundingModes\";\r\n\r\nclass bigDecimal {\r\n private value: string;\r\n static RoundingModes = Modes;\r\n\r\n private static validate(number): string {\r\n if (number) {\r\n number = number.toString();\r\n if (isNaN(number)) throw Error(\"Parameter is not a number: \" + number);\r\n\r\n if (number[0] == \"+\") number = number.substring(1);\r\n } else number = \"0\";\r\n\r\n //handle missing leading zero\r\n if (number.startsWith(\".\")) number = \"0\" + number;\r\n else if (number.startsWith(\"-.\")) number = \"-0\" + number.substr(1);\r\n\r\n //handle exponentiation\r\n if (/e/i.test(number)) {\r\n let [mantisa, exponent] = number.split(/[eE]/);\r\n mantisa = trim(mantisa);\r\n\r\n let sign = \"\";\r\n if (mantisa[0] == \"-\") {\r\n sign = \"-\";\r\n mantisa = mantisa.substring(1);\r\n }\r\n\r\n if (mantisa.indexOf(\".\") >= 0) {\r\n exponent = parseInt(exponent) + mantisa.indexOf(\".\");\r\n mantisa = mantisa.replace(\".\", \"\");\r\n } else {\r\n exponent = parseInt(exponent) + mantisa.length;\r\n }\r\n\r\n if (mantisa.length < exponent) {\r\n number =\r\n sign + mantisa + new Array(exponent - mantisa.length + 1).join(\"0\");\r\n } else if (mantisa.length >= exponent && exponent > 0) {\r\n number =\r\n sign +\r\n trim(mantisa.substring(0, exponent)) +\r\n (mantisa.length > exponent ? \".\" + mantisa.substring(exponent) : \"\");\r\n } else {\r\n number = sign + \"0.\" + new Array(-exponent + 1).join(\"0\") + mantisa;\r\n }\r\n }\r\n\r\n return number;\r\n }\r\n\r\n constructor(number: number | string | bigint = \"0\") {\r\n this.value = bigDecimal.validate(number);\r\n }\r\n\r\n getValue() {\r\n return this.value;\r\n }\r\n\r\n setValue(num: number | string | bigint) {\r\n this.value = bigDecimal.validate(num);\r\n }\r\n\r\n static getPrettyValue(number, digits = 3, separator = \",\"): string {\r\n // if (!(digits || separator)) {\r\n // digits = 3;\r\n // separator = ',';\r\n // } else if (!(digits && separator)) {\r\n // throw Error('Illegal Arguments. Should pass both digits and separator or pass none');\r\n // }\r\n number = bigDecimal.validate(number);\r\n let neg = number.charAt(0) == \"-\";\r\n if (neg) number = number.substring(1);\r\n var len = number.indexOf(\".\");\r\n len = len > 0 ? len : number.length;\r\n var temp = \"\";\r\n for (var i = len; i > 0; ) {\r\n if (i < digits) {\r\n digits = i;\r\n i = 0;\r\n } else i -= digits;\r\n\r\n temp =\r\n number.substring(i, i + digits) +\r\n (i < len - digits && i >= 0 ? separator : \"\") +\r\n temp;\r\n }\r\n return (neg ? \"-\" : \"\") + temp + number.substring(len);\r\n }\r\n getPrettyValue(digits = 3, separator = \",\") {\r\n return bigDecimal.getPrettyValue(this.value, digits, separator);\r\n }\r\n\r\n static round(number, precision = 0, mode = Modes.HALF_EVEN) {\r\n number = bigDecimal.validate(number);\r\n // console.log(number)\r\n if (isNaN(precision))\r\n throw Error(\"Precision is not a number: \" + precision);\r\n return roundOff(number, precision, mode);\r\n }\r\n\r\n round(precision = 0, mode = Modes.HALF_EVEN) {\r\n if (isNaN(precision))\r\n throw Error(\"Precision is not a number: \" + precision);\r\n\r\n return new bigDecimal(roundOff(this.value, precision, mode));\r\n }\r\n\r\n static abs(number) {\r\n number = bigDecimal.validate(number);\r\n return abs(number);\r\n }\r\n\r\n abs() {\r\n return new bigDecimal(abs(this.value));\r\n }\r\n\r\n static floor(number) {\r\n number = bigDecimal.validate(number);\r\n if (number.indexOf(\".\") === -1) return number;\r\n return bigDecimal.round(number, 0, RoundingModes.FLOOR);\r\n }\r\n\r\n floor() {\r\n if (this.value.indexOf(\".\") === -1) return new bigDecimal(this.value);\r\n return new bigDecimal(this.value).round(0, RoundingModes.FLOOR);\r\n }\r\n\r\n static ceil(number) {\r\n number = bigDecimal.validate(number);\r\n if (number.indexOf(\".\") === -1) return number;\r\n return bigDecimal.round(number, 0, RoundingModes.CEILING);\r\n }\r\n\r\n ceil() {\r\n if (this.value.indexOf(\".\") === -1) return new bigDecimal(this.value);\r\n return new bigDecimal(this.value).round(0, RoundingModes.CEILING);\r\n }\r\n\r\n static add(number1, number2) {\r\n number1 = bigDecimal.validate(number1);\r\n number2 = bigDecimal.validate(number2);\r\n return add(number1, number2);\r\n }\r\n\r\n add(number: bigDecimal) {\r\n return new bigDecimal(add(this.value, number.getValue()));\r\n }\r\n\r\n static subtract(number1, number2) {\r\n number1 = bigDecimal.validate(number1);\r\n number2 = bigDecimal.validate(number2);\r\n return subtract(number1, number2);\r\n }\r\n\r\n subtract(number: bigDecimal) {\r\n return new bigDecimal(subtract(this.value, number.getValue()));\r\n }\r\n\r\n static multiply(number1, number2) {\r\n number1 = bigDecimal.validate(number1);\r\n number2 = bigDecimal.validate(number2);\r\n return multiply(number1, number2);\r\n }\r\n\r\n multiply(number: bigDecimal) {\r\n return new bigDecimal(multiply(this.value, number.getValue()));\r\n }\r\n\r\n static divide(number1, number2, precision?: number) {\r\n number1 = bigDecimal.validate(number1);\r\n number2 = bigDecimal.validate(number2);\r\n return divide(number1, number2, precision);\r\n }\r\n\r\n divide(number: bigDecimal, precision) {\r\n return new bigDecimal(divide(this.value, number.getValue(), precision));\r\n }\r\n\r\n static modulus(number1, number2) {\r\n number1 = bigDecimal.validate(number1);\r\n number2 = bigDecimal.validate(number2);\r\n return modulus(number1, number2);\r\n }\r\n\r\n modulus(number: bigDecimal) {\r\n return new bigDecimal(modulus(this.value, number.getValue()));\r\n }\r\n\r\n static compareTo(number1, number2) {\r\n number1 = bigDecimal.validate(number1);\r\n number2 = bigDecimal.validate(number2);\r\n return compareTo(number1, number2);\r\n }\r\n\r\n compareTo(number: bigDecimal) {\r\n return compareTo(this.value, number.getValue());\r\n }\r\n\r\n static negate(number) {\r\n number = bigDecimal.validate(number);\r\n return negate(number);\r\n }\r\n\r\n negate() {\r\n return new bigDecimal(negate(this.value));\r\n }\r\n}\r\nexport default bigDecimal;\r\n"],"names":["Modes"],"mappings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AA,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;KAC/D,CAAA;AAEM,IAAA,UAAA,CAAA,SAAS,GAAhB,UAAiB,OAAO,EAAE,OAAO,EAAA;AAC/B,QAAA,OAAO,GAAG,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACvC,QAAA,OAAO,GAAG,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACvC,QAAA,OAAO,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;KACpC,CAAA;IAED,UAAS,CAAA,SAAA,CAAA,SAAA,GAAT,UAAU,MAAkB,EAAA;QAC1B,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;KACjD,CAAA;IAEM,UAAM,CAAA,MAAA,GAAb,UAAc,MAAM,EAAA;AAClB,QAAA,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACrC,QAAA,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;KACvB,CAAA;AAED,IAAA,UAAA,CAAA,SAAA,CAAA,MAAM,GAAN,YAAA;QACE,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;KAC3C,CAAA;IA3MM,UAAa,CAAA,aAAA,GAAGA,aAAK,CAAC;IA4M/B,OAAC,UAAA,CAAA;AAAA,CA9MD,EA8MC;;;;"} \ No newline at end of file diff --git a/dist/esm/compareTo.d.ts b/dist/esm/compareTo.d.ts new file mode 100644 index 0000000..d70d0c8 --- /dev/null +++ b/dist/esm/compareTo.d.ts @@ -0,0 +1 @@ +export declare function compareTo(number1: string, number2: string): 0 | 1 | -1; diff --git a/dist/esm/divide.d.ts b/dist/esm/divide.d.ts new file mode 100644 index 0000000..281ed48 --- /dev/null +++ b/dist/esm/divide.d.ts @@ -0,0 +1 @@ +export declare function divide(dividend: any, divisor: any, precission?: number): string; diff --git a/dist/esm/modulus.d.ts b/dist/esm/modulus.d.ts new file mode 100644 index 0000000..0136667 --- /dev/null +++ b/dist/esm/modulus.d.ts @@ -0,0 +1 @@ +export declare function modulus(dividend: number | string, divisor: number | string): string; diff --git a/dist/esm/multiply.d.ts b/dist/esm/multiply.d.ts new file mode 100644 index 0000000..dba5abb --- /dev/null +++ b/dist/esm/multiply.d.ts @@ -0,0 +1 @@ +export declare function multiply(number1: any, number2: any): string; diff --git a/dist/esm/round.d.ts b/dist/esm/round.d.ts new file mode 100644 index 0000000..372fb6c --- /dev/null +++ b/dist/esm/round.d.ts @@ -0,0 +1,8 @@ +import { RoundingModes } from './roundingModes'; +/** + * + * @param input the number to round + * @param n precision + * @param mode Rounding Mode + */ +export declare function roundOff(input: number | string | bigint, n?: number, mode?: RoundingModes): string; diff --git a/dist/esm/roundingModes.d.ts b/dist/esm/roundingModes.d.ts new file mode 100644 index 0000000..55419d5 --- /dev/null +++ b/dist/esm/roundingModes.d.ts @@ -0,0 +1,38 @@ +export declare enum RoundingModes { + /** + * Rounding mode to round towards positive infinity. + */ + CEILING = 0, + /** + * Rounding mode to round towards zero. + */ + DOWN = 1, + /** + * Rounding mode to round towards negative infinity. + */ + FLOOR = 2, + /** + * Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, + * in which case round down. + */ + HALF_DOWN = 3, + /** + * Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, + * in which case, round towards the even neighbor. + */ + HALF_EVEN = 4, + /** + * Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, + * in which case round up. + */ + HALF_UP = 5, + /** + * Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary. + * UNIMPLEMENTED + */ + UNNECESSARY = 6, + /** + * Rounding mode to round away from zero. + */ + UP = 7 +} diff --git a/dist/esm/subtract.d.ts b/dist/esm/subtract.d.ts new file mode 100644 index 0000000..fdc6d52 --- /dev/null +++ b/dist/esm/subtract.d.ts @@ -0,0 +1,2 @@ +export declare function subtract(number1: any, number2: any): string; +export declare function negate(number: string): string; diff --git a/dist/node/big-decimal.d.ts b/dist/node/big-decimal.d.ts index 38691e6..556d018 100644 --- a/dist/node/big-decimal.d.ts +++ b/dist/node/big-decimal.d.ts @@ -1,13 +1,13 @@ -import { RoundingModes as Modes } from './roundingModes'; +import { RoundingModes as Modes } from "./roundingModes"; declare class bigDecimal { private value; static RoundingModes: typeof Modes; private static validate; - constructor(number?: (number | string | bigint)); + constructor(number?: number | string | bigint); getValue(): string; - setValue(num: (number | string | bigint)): void; - static getPrettyValue(number: any, digits: any, separator: any): string; - getPrettyValue(digits: any, separator: any): string; + setValue(num: number | string | bigint): void; + static getPrettyValue(number: any, digits?: number, separator?: string): string; + getPrettyValue(digits?: number, separator?: string): string; static round(number: any, precision?: number, mode?: Modes): string; round(precision?: number, mode?: Modes): bigDecimal; static abs(number: any): string; @@ -22,7 +22,7 @@ declare class bigDecimal { subtract(number: bigDecimal): bigDecimal; static multiply(number1: any, number2: any): string; multiply(number: bigDecimal): bigDecimal; - static divide(number1: any, number2: any, precision: any): string; + static divide(number1: any, number2: any, precision?: number): string; divide(number: bigDecimal, precision: any): bigDecimal; static modulus(number1: any, number2: any): string; modulus(number: bigDecimal): bigDecimal; @@ -31,4 +31,4 @@ declare class bigDecimal { static negate(number: any): string; negate(): bigDecimal; } -export = bigDecimal; +export default bigDecimal; diff --git a/dist/node/js-big-decimal.js b/dist/node/js-big-decimal.js index 3dcf8c9..9eaea8d 100644 --- a/dist/node/js-big-decimal.js +++ b/dist/node/js-big-decimal.js @@ -19,9 +19,9 @@ return /******/ (function() { // webpackBootstrap Object.defineProperty(exports, "__esModule", ({ value: true })); exports.abs = void 0; function abs(n) { - if (typeof n == 'number' || typeof n == 'bigint') + if (typeof n == "number" || typeof n == "bigint") n = n.toString(); - if (n[0] == '-') + if (n[0] == "-") return n.substring(1); return n; } @@ -42,7 +42,7 @@ function add(number1, number2) { if (number2 === void 0) { number2 = "0"; } var neg = 0, ind = -1, neg_len; //check for negatives - if (number1[0] == '-') { + if (number1[0] == "-") { number1 = number1.substring(1); if (!testZero(number1)) { neg++; @@ -50,7 +50,7 @@ function add(number1, number2) { neg_len = number1.length; } } - if (number2[0] == '-') { + if (number2[0] == "-") { number2 = number2.substring(1); if (!testZero(number2)) { neg++; @@ -71,12 +71,12 @@ function add(number1, number2) { if (!neg) return trim(res); else if (neg == 2) - return ('-' + trim(res)); + return "-" + trim(res); else { - if (number1.length < (res.length)) + if (number1.length < res.length) return trim(res.substring(1)); else - return ('-' + trim(compliment(res))); + return "-" + trim(compliment(res)); } } exports.add = add; @@ -84,276 +84,79 @@ function compliment(number) { if (testZero(number)) { return number; } - var s = '', l = number.length, dec = number.split('.')[1], ld = dec ? dec.length : 0; + var s = "", l = number.length, dec = number.split(".")[1], ld = dec ? dec.length : 0; for (var i = 0; i < l; i++) { - if (number[i] >= '0' && number[i] <= '9') - s += (9 - parseInt(number[i])); + if (number[i] >= "0" && number[i] <= "9") + s += 9 - parseInt(number[i]); else s += number[i]; } - var one = (ld > 0) ? ('0.' + (new Array(ld)).join('0') + '1') : '1'; + var one = ld > 0 ? "0." + new Array(ld).join("0") + "1" : "1"; return addCore(s, one); } function trim(number) { - var parts = number.split('.'); + var parts = number.split("."); if (!parts[0]) - parts[0] = '0'; - while (parts[0][0] == '0' && parts[0].length > 1) + parts[0] = "0"; + while (parts[0][0] == "0" && parts[0].length > 1) parts[0] = parts[0].substring(1); - return parts[0] + (parts[1] ? ('.' + parts[1]) : ''); + return parts[0] + (parts[1] ? "." + parts[1] : ""); } exports.trim = trim; function pad(number1, number2) { - var parts1 = number1.split('.'), parts2 = number2.split('.'); + var parts1 = number1.split("."), parts2 = number2.split("."); //pad integral part var length1 = parts1[0].length, length2 = parts2[0].length; if (length1 > length2) { - parts2[0] = (new Array(Math.abs(length1 - length2) + 1)).join('0') + (parts2[0] ? parts2[0] : ''); + parts2[0] = + new Array(Math.abs(length1 - length2) + 1).join("0") + + (parts2[0] ? parts2[0] : ""); } else { - parts1[0] = (new Array(Math.abs(length1 - length2) + 1)).join('0') + (parts1[0] ? parts1[0] : ''); + parts1[0] = + new Array(Math.abs(length1 - length2) + 1).join("0") + + (parts1[0] ? parts1[0] : ""); } //pad fractional part - length1 = parts1[1] ? parts1[1].length : 0, - length2 = parts2[1] ? parts2[1].length : 0; + (length1 = parts1[1] ? parts1[1].length : 0), + (length2 = parts2[1] ? parts2[1].length : 0); if (length1 || length2) { if (length1 > length2) { - parts2[1] = (parts2[1] ? parts2[1] : '') + (new Array(Math.abs(length1 - length2) + 1)).join('0'); + parts2[1] = + (parts2[1] ? parts2[1] : "") + + new Array(Math.abs(length1 - length2) + 1).join("0"); } else { - parts1[1] = (parts1[1] ? parts1[1] : '') + (new Array(Math.abs(length1 - length2) + 1)).join('0'); + parts1[1] = + (parts1[1] ? parts1[1] : "") + + new Array(Math.abs(length1 - length2) + 1).join("0"); } } - number1 = parts1[0] + ((parts1[1]) ? ('.' + parts1[1]) : ''); - number2 = parts2[0] + ((parts2[1]) ? ('.' + parts2[1]) : ''); + number1 = parts1[0] + (parts1[1] ? "." + parts1[1] : ""); + number2 = parts2[0] + (parts2[1] ? "." + parts2[1] : ""); return [number1, number2]; } exports.pad = pad; function addCore(number1, number2) { var _a; _a = pad(number1, number2), number1 = _a[0], number2 = _a[1]; - var sum = '', carry = 0; + var sum = "", carry = 0; for (var i = number1.length - 1; i >= 0; i--) { - if (number1[i] === '.') { - sum = '.' + sum; + if (number1[i] === ".") { + sum = "." + sum; continue; } var temp = parseInt(number1[i]) + parseInt(number2[i]) + carry; sum = (temp % 10) + sum; carry = Math.floor(temp / 10); } - return carry ? (carry.toString() + sum) : sum; + return carry ? carry.toString() + sum : sum; } function testZero(number) { - return (/^0[0]*[.]{0,1}[0]*$/.test(number)); + return /^0[0]*[.]{0,1}[0]*$/.test(number); } -/***/ }), - -/***/ 423: -/***/ (function(module, __unused_webpack_exports, __webpack_require__) { - - -var add_1 = __webpack_require__(217); -var abs_1 = __webpack_require__(165); -var round_1 = __webpack_require__(350); -var multiply_1 = __webpack_require__(182); -var divide_1 = __webpack_require__(415); -var modulus_1 = __webpack_require__(213); -var compareTo_1 = __webpack_require__(664); -var subtract_1 = __webpack_require__(26); -var roundingModes_1 = __webpack_require__(916); -var bigDecimal = /** @class */ (function () { - function bigDecimal(number) { - if (number === void 0) { number = '0'; } - this.value = bigDecimal.validate(number); - } - bigDecimal.validate = function (number) { - if (number) { - number = number.toString(); - if (isNaN(number)) - throw Error("Parameter is not a number: " + number); - if (number[0] == '+') - number = number.substring(1); - } - else - number = '0'; - //handle missing leading zero - if (number.startsWith('.')) - number = '0' + number; - else if (number.startsWith('-.')) - number = '-0' + number.substr(1); - //handle exponentiation - if (/e/i.test(number)) { - var _a = number.split(/[eE]/), mantisa = _a[0], exponent = _a[1]; - mantisa = (0, add_1.trim)(mantisa); - var sign = ''; - if (mantisa[0] == '-') { - sign = '-'; - mantisa = mantisa.substring(1); - } - if (mantisa.indexOf('.') >= 0) { - exponent = parseInt(exponent) + mantisa.indexOf('.'); - mantisa = mantisa.replace('.', ''); - } - else { - exponent = parseInt(exponent) + mantisa.length; - } - if (mantisa.length < exponent) { - number = sign + mantisa + (new Array(exponent - mantisa.length + 1)).join('0'); - } - else if (mantisa.length >= exponent && exponent > 0) { - number = sign + (0, add_1.trim)(mantisa.substring(0, exponent)) + - ((mantisa.length > exponent) ? ('.' + mantisa.substring(exponent)) : ''); - } - else { - number = sign + '0.' + (new Array(-exponent + 1)).join('0') + mantisa; - } - } - return number; - }; - bigDecimal.prototype.getValue = function () { - return this.value; - }; - bigDecimal.prototype.setValue = function (num) { - this.value = bigDecimal.validate(num); - }; - bigDecimal.getPrettyValue = function (number, digits, separator) { - if (!(digits || separator)) { - digits = 3; - separator = ','; - } - else if (!(digits && separator)) { - throw Error('Illegal Arguments. Should pass both digits and separator or pass none'); - } - number = bigDecimal.validate(number); - var neg = number.charAt(0) == '-'; - if (neg) - number = number.substring(1); - var len = number.indexOf('.'); - len = len > 0 ? len : (number.length); - var temp = ''; - for (var i = len; i > 0;) { - if (i < digits) { - digits = i; - i = 0; - } - else - i -= digits; - temp = number.substring(i, i + digits) + ((i < (len - digits) && i >= 0) ? separator : '') + temp; - } - return (neg ? '-' : '') + temp + number.substring(len); - }; - bigDecimal.prototype.getPrettyValue = function (digits, separator) { - return bigDecimal.getPrettyValue(this.value, digits, separator); - }; - bigDecimal.round = function (number, precision, mode) { - if (precision === void 0) { precision = 0; } - if (mode === void 0) { mode = roundingModes_1.RoundingModes.HALF_EVEN; } - number = bigDecimal.validate(number); - // console.log(number) - if (isNaN(precision)) - throw Error("Precision is not a number: " + precision); - return (0, round_1.roundOff)(number, precision, mode); - }; - bigDecimal.prototype.round = function (precision, mode) { - if (precision === void 0) { precision = 0; } - if (mode === void 0) { mode = roundingModes_1.RoundingModes.HALF_EVEN; } - if (isNaN(precision)) - throw Error("Precision is not a number: " + precision); - return new bigDecimal((0, round_1.roundOff)(this.value, precision, mode)); - }; - bigDecimal.abs = function (number) { - number = bigDecimal.validate(number); - return (0, abs_1.abs)(number); - }; - bigDecimal.prototype.abs = function () { - return new bigDecimal((0, abs_1.abs)(this.value)); - }; - bigDecimal.floor = function (number) { - number = bigDecimal.validate(number); - if (number.indexOf('.') === -1) - return number; - return bigDecimal.round(number, 0, roundingModes_1.RoundingModes.FLOOR); - }; - bigDecimal.prototype.floor = function () { - if (this.value.indexOf('.') === -1) - return new bigDecimal(this.value); - return new bigDecimal(this.value).round(0, roundingModes_1.RoundingModes.FLOOR); - }; - bigDecimal.ceil = function (number) { - number = bigDecimal.validate(number); - if (number.indexOf('.') === -1) - return number; - return bigDecimal.round(number, 0, roundingModes_1.RoundingModes.CEILING); - }; - bigDecimal.prototype.ceil = function () { - if (this.value.indexOf('.') === -1) - return new bigDecimal(this.value); - return new bigDecimal(this.value).round(0, roundingModes_1.RoundingModes.CEILING); - }; - bigDecimal.add = function (number1, number2) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return (0, add_1.add)(number1, number2); - }; - bigDecimal.prototype.add = function (number) { - return new bigDecimal((0, add_1.add)(this.value, number.getValue())); - }; - bigDecimal.subtract = function (number1, number2) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return (0, subtract_1.subtract)(number1, number2); - }; - bigDecimal.prototype.subtract = function (number) { - return new bigDecimal((0, subtract_1.subtract)(this.value, number.getValue())); - }; - bigDecimal.multiply = function (number1, number2) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return (0, multiply_1.multiply)(number1, number2); - }; - bigDecimal.prototype.multiply = function (number) { - return new bigDecimal((0, multiply_1.multiply)(this.value, number.getValue())); - }; - bigDecimal.divide = function (number1, number2, precision) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return (0, divide_1.divide)(number1, number2, precision); - }; - bigDecimal.prototype.divide = function (number, precision) { - return new bigDecimal((0, divide_1.divide)(this.value, number.getValue(), precision)); - }; - bigDecimal.modulus = function (number1, number2) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return (0, modulus_1.modulus)(number1, number2); - }; - bigDecimal.prototype.modulus = function (number) { - return new bigDecimal((0, modulus_1.modulus)(this.value, number.getValue())); - }; - bigDecimal.compareTo = function (number1, number2) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return (0, compareTo_1.compareTo)(number1, number2); - }; - bigDecimal.prototype.compareTo = function (number) { - return (0, compareTo_1.compareTo)(this.value, number.getValue()); - }; - bigDecimal.negate = function (number) { - number = bigDecimal.validate(number); - return (0, subtract_1.negate)(number); - }; - bigDecimal.prototype.negate = function () { - return new bigDecimal((0, subtract_1.negate)(this.value)); - }; - bigDecimal.RoundingModes = roundingModes_1.RoundingModes; - return bigDecimal; -}()); -module.exports = bigDecimal; - - /***/ }), /***/ 664: @@ -874,12 +677,220 @@ exports.negate = negate; /******/ } /******/ /************************************************************************/ -/******/ -/******/ // startup -/******/ // Load entry module and return exports -/******/ // This entry module is referenced by other modules so it can't be inlined -/******/ var __webpack_exports__ = __webpack_require__(423); -/******/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +!function() { +var exports = __webpack_exports__; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +var add_1 = __webpack_require__(217); +var abs_1 = __webpack_require__(165); +var round_1 = __webpack_require__(350); +var multiply_1 = __webpack_require__(182); +var divide_1 = __webpack_require__(415); +var modulus_1 = __webpack_require__(213); +var compareTo_1 = __webpack_require__(664); +var subtract_1 = __webpack_require__(26); +var roundingModes_1 = __webpack_require__(916); +var bigDecimal = /** @class */ (function () { + function bigDecimal(number) { + if (number === void 0) { number = "0"; } + this.value = bigDecimal.validate(number); + } + bigDecimal.validate = function (number) { + if (number) { + number = number.toString(); + if (isNaN(number)) + throw Error("Parameter is not a number: " + number); + if (number[0] == "+") + number = number.substring(1); + } + else + number = "0"; + //handle missing leading zero + if (number.startsWith(".")) + number = "0" + number; + else if (number.startsWith("-.")) + number = "-0" + number.substr(1); + //handle exponentiation + if (/e/i.test(number)) { + var _a = number.split(/[eE]/), mantisa = _a[0], exponent = _a[1]; + mantisa = (0, add_1.trim)(mantisa); + var sign = ""; + if (mantisa[0] == "-") { + sign = "-"; + mantisa = mantisa.substring(1); + } + if (mantisa.indexOf(".") >= 0) { + exponent = parseInt(exponent) + mantisa.indexOf("."); + mantisa = mantisa.replace(".", ""); + } + else { + exponent = parseInt(exponent) + mantisa.length; + } + if (mantisa.length < exponent) { + number = + sign + mantisa + new Array(exponent - mantisa.length + 1).join("0"); + } + else if (mantisa.length >= exponent && exponent > 0) { + number = + sign + + (0, add_1.trim)(mantisa.substring(0, exponent)) + + (mantisa.length > exponent ? "." + mantisa.substring(exponent) : ""); + } + else { + number = sign + "0." + new Array(-exponent + 1).join("0") + mantisa; + } + } + return number; + }; + bigDecimal.prototype.getValue = function () { + return this.value; + }; + bigDecimal.prototype.setValue = function (num) { + this.value = bigDecimal.validate(num); + }; + bigDecimal.getPrettyValue = function (number, digits, separator) { + if (digits === void 0) { digits = 3; } + if (separator === void 0) { separator = ","; } + // if (!(digits || separator)) { + // digits = 3; + // separator = ','; + // } else if (!(digits && separator)) { + // throw Error('Illegal Arguments. Should pass both digits and separator or pass none'); + // } + number = bigDecimal.validate(number); + var neg = number.charAt(0) == "-"; + if (neg) + number = number.substring(1); + var len = number.indexOf("."); + len = len > 0 ? len : number.length; + var temp = ""; + for (var i = len; i > 0;) { + if (i < digits) { + digits = i; + i = 0; + } + else + i -= digits; + temp = + number.substring(i, i + digits) + + (i < len - digits && i >= 0 ? separator : "") + + temp; + } + return (neg ? "-" : "") + temp + number.substring(len); + }; + bigDecimal.prototype.getPrettyValue = function (digits, separator) { + if (digits === void 0) { digits = 3; } + if (separator === void 0) { separator = ","; } + return bigDecimal.getPrettyValue(this.value, digits, separator); + }; + bigDecimal.round = function (number, precision, mode) { + if (precision === void 0) { precision = 0; } + if (mode === void 0) { mode = roundingModes_1.RoundingModes.HALF_EVEN; } + number = bigDecimal.validate(number); + // console.log(number) + if (isNaN(precision)) + throw Error("Precision is not a number: " + precision); + return (0, round_1.roundOff)(number, precision, mode); + }; + bigDecimal.prototype.round = function (precision, mode) { + if (precision === void 0) { precision = 0; } + if (mode === void 0) { mode = roundingModes_1.RoundingModes.HALF_EVEN; } + if (isNaN(precision)) + throw Error("Precision is not a number: " + precision); + return new bigDecimal((0, round_1.roundOff)(this.value, precision, mode)); + }; + bigDecimal.abs = function (number) { + number = bigDecimal.validate(number); + return (0, abs_1.abs)(number); + }; + bigDecimal.prototype.abs = function () { + return new bigDecimal((0, abs_1.abs)(this.value)); + }; + bigDecimal.floor = function (number) { + number = bigDecimal.validate(number); + if (number.indexOf(".") === -1) + return number; + return bigDecimal.round(number, 0, roundingModes_1.RoundingModes.FLOOR); + }; + bigDecimal.prototype.floor = function () { + if (this.value.indexOf(".") === -1) + return new bigDecimal(this.value); + return new bigDecimal(this.value).round(0, roundingModes_1.RoundingModes.FLOOR); + }; + bigDecimal.ceil = function (number) { + number = bigDecimal.validate(number); + if (number.indexOf(".") === -1) + return number; + return bigDecimal.round(number, 0, roundingModes_1.RoundingModes.CEILING); + }; + bigDecimal.prototype.ceil = function () { + if (this.value.indexOf(".") === -1) + return new bigDecimal(this.value); + return new bigDecimal(this.value).round(0, roundingModes_1.RoundingModes.CEILING); + }; + bigDecimal.add = function (number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return (0, add_1.add)(number1, number2); + }; + bigDecimal.prototype.add = function (number) { + return new bigDecimal((0, add_1.add)(this.value, number.getValue())); + }; + bigDecimal.subtract = function (number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return (0, subtract_1.subtract)(number1, number2); + }; + bigDecimal.prototype.subtract = function (number) { + return new bigDecimal((0, subtract_1.subtract)(this.value, number.getValue())); + }; + bigDecimal.multiply = function (number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return (0, multiply_1.multiply)(number1, number2); + }; + bigDecimal.prototype.multiply = function (number) { + return new bigDecimal((0, multiply_1.multiply)(this.value, number.getValue())); + }; + bigDecimal.divide = function (number1, number2, precision) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return (0, divide_1.divide)(number1, number2, precision); + }; + bigDecimal.prototype.divide = function (number, precision) { + return new bigDecimal((0, divide_1.divide)(this.value, number.getValue(), precision)); + }; + bigDecimal.modulus = function (number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return (0, modulus_1.modulus)(number1, number2); + }; + bigDecimal.prototype.modulus = function (number) { + return new bigDecimal((0, modulus_1.modulus)(this.value, number.getValue())); + }; + bigDecimal.compareTo = function (number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return (0, compareTo_1.compareTo)(number1, number2); + }; + bigDecimal.prototype.compareTo = function (number) { + return (0, compareTo_1.compareTo)(this.value, number.getValue()); + }; + bigDecimal.negate = function (number) { + number = bigDecimal.validate(number); + return (0, subtract_1.negate)(number); + }; + bigDecimal.prototype.negate = function () { + return new bigDecimal((0, subtract_1.negate)(this.value)); + }; + bigDecimal.RoundingModes = roundingModes_1.RoundingModes; + return bigDecimal; +}()); +exports["default"] = bigDecimal; + +}(); /******/ return __webpack_exports__; /******/ })() ; diff --git a/dist/node/js-big-decimal.min.js b/dist/node/js-big-decimal.min.js index 5f72ba2..7a806bf 100644 --- a/dist/node/js-big-decimal.min.js +++ b/dist/node/js-big-decimal.min.js @@ -1 +1 @@ -!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.bigDecimal=n():e.bigDecimal=n()}(global,(function(){return function(){"use strict";var e={165:function(e,n){Object.defineProperty(n,"__esModule",{value:!0}),n.abs=void 0,n.abs=function(e){return"number"!=typeof e&&"bigint"!=typeof e||(e=e.toString()),"-"==e[0]?e.substring(1):e}},217:function(e,n){function t(e){if(u(e))return e;for(var n="",t=e.length,r=e.split(".")[1],i=r?r.length:0,a=0;a="0"&&e[a]<="9"?n+=9-parseInt(e[a]):n+=e[a];return o(n,i>0?"0."+new Array(i).join("0")+"1":"1")}function r(e){var n=e.split(".");for(n[0]||(n[0]="0");"0"==n[0][0]&&n[0].length>1;)n[0]=n[0].substring(1);return n[0]+(n[1]?"."+n[1]:"")}function i(e,n){var t=e.split("."),r=n.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")),[e=t[0]+(t[1]?"."+t[1]:""),n=r[0]+(r[1]?"."+r[1]:"")]}function o(e,n){var t;e=(t=i(e,n))[0],n=t[1];for(var r="",o=0,u=e.length-1;u>=0;u--)if("."!==e[u]){var a=parseInt(e[u])+parseInt(n[u])+o;r=a%10+r,o=Math.floor(a/10)}else r="."+r;return o?o.toString()+r:r}function u(e){return/^0[0]*[.]{0,1}[0]*$/.test(e)}Object.defineProperty(n,"__esModule",{value:!0}),n.pad=n.trim=n.add=void 0,n.add=function(e,n){var a;void 0===n&&(n="0");var s=0,d=-1;"-"==e[0]&&(u(e=e.substring(1))||(s++,d=1,e.length)),"-"==n[0]&&(u(n=n.substring(1))||(s++,d=2,n.length)),e=r(e),n=r(n),e=(a=i(r(e),r(n)))[0],n=a[1],1==s&&(1===d?e=t(e):2===d&&(n=t(n)));var l=o(e,n);return s?2==s?"-"+r(l):e.length=0?(i=parseInt(i)+t.indexOf("."),t=t.replace(".","")):i=parseInt(i)+t.length,e=t.length=i&&i>0?o+(0,r.trim)(t.substring(0,i))+(t.length>i?"."+t.substring(i):""):o+"0."+new Array(1-i).join("0")+t}return e},e.prototype.getValue=function(){return this.value},e.prototype.setValue=function(n){this.value=e.validate(n)},e.getPrettyValue=function(n,t,r){if(t||r){if(!t||!r)throw Error("Illegal Arguments. Should pass both digits and separator or pass none")}else t=3,r=",";var i="-"==(n=e.validate(n)).charAt(0);i&&(n=n.substring(1));for(var o=n.indexOf("."),u="",a=o=o>0?o:n.length;a>0;)a=0?r:"")+u;return(i?"-":"")+u+n.substring(o)},e.prototype.getPrettyValue=function(n,t){return e.getPrettyValue(this.value,n,t)},e.round=function(n,t,r){if(void 0===t&&(t=0),void 0===r&&(r=f.RoundingModes.HALF_EVEN),n=e.validate(n),isNaN(t))throw Error("Precision is not a number: "+t);return(0,o.roundOff)(n,t,r)},e.prototype.round=function(n,t){if(void 0===n&&(n=0),void 0===t&&(t=f.RoundingModes.HALF_EVEN),isNaN(n))throw Error("Precision is not a number: "+n);return new e((0,o.roundOff)(this.value,n,t))},e.abs=function(n){return n=e.validate(n),(0,i.abs)(n)},e.prototype.abs=function(){return new e((0,i.abs)(this.value))},e.floor=function(n){return-1===(n=e.validate(n)).indexOf(".")?n:e.round(n,0,f.RoundingModes.FLOOR)},e.prototype.floor=function(){return-1===this.value.indexOf(".")?new e(this.value):new e(this.value).round(0,f.RoundingModes.FLOOR)},e.ceil=function(n){return-1===(n=e.validate(n)).indexOf(".")?n:e.round(n,0,f.RoundingModes.CEILING)},e.prototype.ceil=function(){return-1===this.value.indexOf(".")?new e(this.value):new e(this.value).round(0,f.RoundingModes.CEILING)},e.add=function(n,t){return n=e.validate(n),t=e.validate(t),(0,r.add)(n,t)},e.prototype.add=function(n){return new e((0,r.add)(this.value,n.getValue()))},e.subtract=function(n,t){return n=e.validate(n),t=e.validate(t),(0,l.subtract)(n,t)},e.prototype.subtract=function(n){return new e((0,l.subtract)(this.value,n.getValue()))},e.multiply=function(n,t){return n=e.validate(n),t=e.validate(t),(0,u.multiply)(n,t)},e.prototype.multiply=function(n){return new e((0,u.multiply)(this.value,n.getValue()))},e.divide=function(n,t,r){return n=e.validate(n),t=e.validate(t),(0,a.divide)(n,t,r)},e.prototype.divide=function(n,t){return new e((0,a.divide)(this.value,n.getValue(),t))},e.modulus=function(n,t){return n=e.validate(n),t=e.validate(t),(0,s.modulus)(n,t)},e.prototype.modulus=function(n){return new e((0,s.modulus)(this.value,n.getValue()))},e.compareTo=function(n,t){return n=e.validate(n),t=e.validate(t),(0,d.compareTo)(n,t)},e.prototype.compareTo=function(e){return(0,d.compareTo)(this.value,e.getValue())},e.negate=function(n){return n=e.validate(n),(0,l.negate)(n)},e.prototype.negate=function(){return new e((0,l.negate)(this.value))},e.RoundingModes=f.RoundingModes,e}();e.exports=g},664:function(e,n,t){Object.defineProperty(n,"__esModule",{value:!0}),n.compareTo=void 0;var r=t(217);n.compareTo=function(e,n){var t,i=!1;if("-"==e[0]&&"-"!=n[0])return-1;if("-"!=e[0]&&"-"==n[0])return 1;if("-"==e[0]&&"-"==n[0]&&(e=e.substr(1),n=n.substr(1),i=!0),e=(t=(0,r.pad)(e,n))[0],n=t[1],0==e.localeCompare(n))return 0;for(var o=0;on[o]?i?-1:1:i?1:-1;return 0}},415:function(e,n,t){Object.defineProperty(n,"__esModule",{value:!0}),n.divide=void 0;var r=t(217),i=t(350);n.divide=function(e,n,t){if(void 0===t&&(t=8),0==n)throw new Error("Cannot divide by 0");if(e=e.toString(),n=n.toString(),e=e.replace(/(\.\d*?[1-9])0+$/g,"$1").replace(/\.0+$/,""),n=n.replace(/(\.\d*?[1-9])0+$/g,"$1").replace(/\.0+$/,""),0==e)return"0";var o=0;"-"==n[0]&&(n=n.substring(1),o++),"-"==e[0]&&(e=e.substring(1),o++);var u=n.indexOf(".")>0?n.length-n.indexOf(".")-1:-1;if(n=(0,r.trim)(n.replace(".","")),u>=0){var a=e.indexOf(".")>0?e.length-e.indexOf(".")-1:-1;if(-1==a)e=(0,r.trim)(e+new Array(u+1).join("0"));else if(u>a)e=e.replace(".",""),e=(0,r.trim)(e+new Array(u-a+1).join("0"));else if(u-1&&e.indexOf(".")-1&&e.indexOf(".")-1){var v=g.length-g.indexOf(".")-1;l>(g=g.replace(".","")).length&&(v+=l-g.length,g+=new Array(l-g.length+1).join("0")),d=v,f="0."+new Array(v).join("0")}for(t+=2;d<=t;){for(var c=0;parseInt(g)>=parseInt(n);)g=(0,r.add)(g,"-"+n),c++;f+=c,e?("."==e[0]&&(f+=".",d++,e=e.substring(1)),g+=e.substring(0,1),e=e.substring(1)):(d||(f+="."),d++,g+="0")}return(1==o?"-":"")+(0,r.trim)((0,i.roundOff)(f,t-2))}},213:function(e,n,t){Object.defineProperty(n,"__esModule",{value:!0}),n.modulus=void 0;var r=t(415),i=t(350),o=t(182),u=t(26),a=t(916);function s(e){if(-1!=e.indexOf("."))throw new Error("Modulus of non-integers not supported")}n.modulus=function(e,n){if(0==n)throw new Error("Cannot divide by 0");e=e.toString(),n=n.toString(),s(e),s(n);var t="";return"-"==e[0]&&(t="-",e=e.substr(1)),"-"==n[0]&&(n=n.substr(1)),t+(0,u.subtract)(e,(0,o.multiply)(n,(0,i.roundOff)((0,r.divide)(e,n),0,a.RoundingModes.FLOOR)))}},182:function(e,n){function t(e){for(;"0"==e[0];)e=e.substr(1);if(-1!=e.indexOf("."))for(;"0"==e[e.length-1];)e=e.substr(0,e.length-1);return""==e||"."==e?e="0":"."==e[e.length-1]&&(e=e.substr(0,e.length-1)),"."==e[0]&&(e="0"+e),e}Object.defineProperty(n,"__esModule",{value:!0}),n.multiply=void 0,n.multiply=function(e,n){e=e.toString(),n=n.toString();var r=0;"-"==e[0]&&(r++,e=e.substr(1)),"-"==n[0]&&(r++,n=n.substr(1)),e=t(e),n=t(n);var i=0,o=0;-1!=e.indexOf(".")&&(i=e.length-e.indexOf(".")-1),-1!=n.indexOf(".")&&(o=n.length-n.indexOf(".")-1);var u=i+o;if(e=t(e.replace(".","")),n=t(n.replace(".","")),e.length=v&&b>=0;b--)g[b]>-1&&g[b]=s.length?new Array(d-s.length+1).join("0")+s:s).substr(0,s.length-d)+"."+s.substr(s.length-d,d))),1==r&&(c="-"+c),c}},350:function(e,n,t){Object.defineProperty(n,"__esModule",{value:!0}),n.roundOff=void 0;var r=t(916);function i(e,n,t,i){if(!e||e===new Array(e.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(e.length).join("0");if(e>o)return!0;if(e=0;r--){var i=parseInt(e[r])+n;10==i?(n=1,i=0):n=0,t+=i}return n&&(t+=n),t.split("").reverse().join("")}n.roundOff=function e(n,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 n&&"bigint"!=typeof n||(n=n.toString());var a=!1;"-"===n[0]&&(a=!0,n=n.substring(1));var s=n.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=e(n=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].lengtht?(a?"-":"")+o(d,parseInt(l[0]))+"."+l.substring(1):(a&&(parseInt(d)||parseInt(l))?"-":"")+d+"."+l}},916:function(e,n){Object.defineProperty(n,"__esModule",{value:!0}),n.RoundingModes=void 0,function(e){e[e.CEILING=0]="CEILING",e[e.DOWN=1]="DOWN",e[e.FLOOR=2]="FLOOR",e[e.HALF_DOWN=3]="HALF_DOWN",e[e.HALF_EVEN=4]="HALF_EVEN",e[e.HALF_UP=5]="HALF_UP",e[e.UNNECESSARY=6]="UNNECESSARY",e[e.UP=7]="UP"}(n.RoundingModes||(n.RoundingModes={}))},26:function(e,n,t){Object.defineProperty(n,"__esModule",{value:!0}),n.negate=n.subtract=void 0;var r=t(217);function i(e){return e="-"==e[0]?e.substr(1):"-"+e}n.subtract=function(e,n){return e=e.toString(),n=i(n=n.toString()),(0,r.add)(e,n)},n.negate=i}},n={};var t=function t(r){var i=n[r];if(void 0!==i)return i.exports;var o=n[r]={exports:{}};return e[r](o,o.exports,t),o.exports}(423);return t}()})); \ No newline at end of file +!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.bigDecimal=n():e.bigDecimal=n()}(global,(function(){return function(){"use strict";var e={165:function(e,n){Object.defineProperty(n,"__esModule",{value:!0}),n.abs=void 0,n.abs=function(e){return"number"!=typeof e&&"bigint"!=typeof e||(e=e.toString()),"-"==e[0]?e.substring(1):e}},217:function(e,n){function t(e){if(u(e))return e;for(var n="",t=e.length,r=e.split(".")[1],i=r?r.length:0,a=0;a="0"&&e[a]<="9"?n+=9-parseInt(e[a]):n+=e[a];return o(n,i>0?"0."+new Array(i).join("0")+"1":"1")}function r(e){var n=e.split(".");for(n[0]||(n[0]="0");"0"==n[0][0]&&n[0].length>1;)n[0]=n[0].substring(1);return n[0]+(n[1]?"."+n[1]:"")}function i(e,n){var t=e.split("."),r=n.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")),[e=t[0]+(t[1]?"."+t[1]:""),n=r[0]+(r[1]?"."+r[1]:"")]}function o(e,n){var t;e=(t=i(e,n))[0],n=t[1];for(var r="",o=0,u=e.length-1;u>=0;u--)if("."!==e[u]){var a=parseInt(e[u])+parseInt(n[u])+o;r=a%10+r,o=Math.floor(a/10)}else r="."+r;return o?o.toString()+r:r}function u(e){return/^0[0]*[.]{0,1}[0]*$/.test(e)}Object.defineProperty(n,"__esModule",{value:!0}),n.pad=n.trim=n.add=void 0,n.add=function(e,n){var a;void 0===n&&(n="0");var s=0,d=-1;"-"==e[0]&&(u(e=e.substring(1))||(s++,d=1,e.length)),"-"==n[0]&&(u(n=n.substring(1))||(s++,d=2,n.length)),e=r(e),n=r(n),e=(a=i(r(e),r(n)))[0],n=a[1],1==s&&(1===d?e=t(e):2===d&&(n=t(n)));var l=o(e,n);return s?2==s?"-"+r(l):e.lengthn[o]?i?-1:1:i?1:-1;return 0}},415:function(e,n,t){Object.defineProperty(n,"__esModule",{value:!0}),n.divide=void 0;var r=t(217),i=t(350);n.divide=function(e,n,t){if(void 0===t&&(t=8),0==n)throw new Error("Cannot divide by 0");if(e=e.toString(),n=n.toString(),e=e.replace(/(\.\d*?[1-9])0+$/g,"$1").replace(/\.0+$/,""),n=n.replace(/(\.\d*?[1-9])0+$/g,"$1").replace(/\.0+$/,""),0==e)return"0";var o=0;"-"==n[0]&&(n=n.substring(1),o++),"-"==e[0]&&(e=e.substring(1),o++);var u=n.indexOf(".")>0?n.length-n.indexOf(".")-1:-1;if(n=(0,r.trim)(n.replace(".","")),u>=0){var a=e.indexOf(".")>0?e.length-e.indexOf(".")-1:-1;if(-1==a)e=(0,r.trim)(e+new Array(u+1).join("0"));else if(u>a)e=e.replace(".",""),e=(0,r.trim)(e+new Array(u-a+1).join("0"));else if(u-1&&e.indexOf(".")-1&&e.indexOf(".")-1){var v=g.length-g.indexOf(".")-1;l>(g=g.replace(".","")).length&&(v+=l-g.length,g+=new Array(l-g.length+1).join("0")),d=v,f="0."+new Array(v).join("0")}for(t+=2;d<=t;){for(var c=0;parseInt(g)>=parseInt(n);)g=(0,r.add)(g,"-"+n),c++;f+=c,e?("."==e[0]&&(f+=".",d++,e=e.substring(1)),g+=e.substring(0,1),e=e.substring(1)):(d||(f+="."),d++,g+="0")}return(1==o?"-":"")+(0,r.trim)((0,i.roundOff)(f,t-2))}},213:function(e,n,t){Object.defineProperty(n,"__esModule",{value:!0}),n.modulus=void 0;var r=t(415),i=t(350),o=t(182),u=t(26),a=t(916);function s(e){if(-1!=e.indexOf("."))throw new Error("Modulus of non-integers not supported")}n.modulus=function(e,n){if(0==n)throw new Error("Cannot divide by 0");e=e.toString(),n=n.toString(),s(e),s(n);var t="";return"-"==e[0]&&(t="-",e=e.substr(1)),"-"==n[0]&&(n=n.substr(1)),t+(0,u.subtract)(e,(0,o.multiply)(n,(0,i.roundOff)((0,r.divide)(e,n),0,a.RoundingModes.FLOOR)))}},182:function(e,n){function t(e){for(;"0"==e[0];)e=e.substr(1);if(-1!=e.indexOf("."))for(;"0"==e[e.length-1];)e=e.substr(0,e.length-1);return""==e||"."==e?e="0":"."==e[e.length-1]&&(e=e.substr(0,e.length-1)),"."==e[0]&&(e="0"+e),e}Object.defineProperty(n,"__esModule",{value:!0}),n.multiply=void 0,n.multiply=function(e,n){e=e.toString(),n=n.toString();var r=0;"-"==e[0]&&(r++,e=e.substr(1)),"-"==n[0]&&(r++,n=n.substr(1)),e=t(e),n=t(n);var i=0,o=0;-1!=e.indexOf(".")&&(i=e.length-e.indexOf(".")-1),-1!=n.indexOf(".")&&(o=n.length-n.indexOf(".")-1);var u=i+o;if(e=t(e.replace(".","")),n=t(n.replace(".","")),e.length=v&&b>=0;b--)g[b]>-1&&g[b]=s.length?new Array(d-s.length+1).join("0")+s:s).substr(0,s.length-d)+"."+s.substr(s.length-d,d))),1==r&&(c="-"+c),c}},350:function(e,n,t){Object.defineProperty(n,"__esModule",{value:!0}),n.roundOff=void 0;var r=t(916);function i(e,n,t,i){if(!e||e===new Array(e.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(e.length).join("0");if(e>o)return!0;if(e=0;r--){var i=parseInt(e[r])+n;10==i?(n=1,i=0):n=0,t+=i}return n&&(t+=n),t.split("").reverse().join("")}n.roundOff=function e(n,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 n&&"bigint"!=typeof n||(n=n.toString());var a=!1;"-"===n[0]&&(a=!0,n=n.substring(1));var s=n.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=e(n=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].lengtht?(a?"-":"")+o(d,parseInt(l[0]))+"."+l.substring(1):(a&&(parseInt(d)||parseInt(l))?"-":"")+d+"."+l}},916:function(e,n){Object.defineProperty(n,"__esModule",{value:!0}),n.RoundingModes=void 0,function(e){e[e.CEILING=0]="CEILING",e[e.DOWN=1]="DOWN",e[e.FLOOR=2]="FLOOR",e[e.HALF_DOWN=3]="HALF_DOWN",e[e.HALF_EVEN=4]="HALF_EVEN",e[e.HALF_UP=5]="HALF_UP",e[e.UNNECESSARY=6]="UNNECESSARY",e[e.UP=7]="UP"}(n.RoundingModes||(n.RoundingModes={}))},26:function(e,n,t){Object.defineProperty(n,"__esModule",{value:!0}),n.negate=n.subtract=void 0;var r=t(217);function i(e){return e="-"==e[0]?e.substr(1):"-"+e}n.subtract=function(e,n){return e=e.toString(),n=i(n=n.toString()),(0,r.add)(e,n)},n.negate=i}},n={};function t(r){var i=n[r];if(void 0!==i)return i.exports;var o=n[r]={exports:{}};return e[r](o,o.exports,t),o.exports}var r={};return function(){var e=r;Object.defineProperty(e,"__esModule",{value:!0});var n=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=function(){function e(n){void 0===n&&(n="0"),this.value=e.validate(n)}return e.validate=function(e){if(e){if(e=e.toString(),isNaN(e))throw Error("Parameter is not a number: "+e);"+"==e[0]&&(e=e.substring(1))}else e="0";if(e.startsWith(".")?e="0"+e:e.startsWith("-.")&&(e="-0"+e.substr(1)),/e/i.test(e)){var t=e.split(/[eE]/),r=t[0],i=t[1],o="";"-"==(r=(0,n.trim)(r))[0]&&(o="-",r=r.substring(1)),r.indexOf(".")>=0?(i=parseInt(i)+r.indexOf("."),r=r.replace(".","")):i=parseInt(i)+r.length,e=r.length=i&&i>0?o+(0,n.trim)(r.substring(0,i))+(r.length>i?"."+r.substring(i):""):o+"0."+new Array(1-i).join("0")+r}return e},e.prototype.getValue=function(){return this.value},e.prototype.setValue=function(n){this.value=e.validate(n)},e.getPrettyValue=function(n,t,r){void 0===t&&(t=3),void 0===r&&(r=",");var i="-"==(n=e.validate(n)).charAt(0);i&&(n=n.substring(1));for(var o=n.indexOf("."),u="",a=o=o>0?o:n.length;a>0;)a=0?r:"")+u;return(i?"-":"")+u+n.substring(o)},e.prototype.getPrettyValue=function(n,t){return void 0===n&&(n=3),void 0===t&&(t=","),e.getPrettyValue(this.value,n,t)},e.round=function(n,t,r){if(void 0===t&&(t=0),void 0===r&&(r=f.RoundingModes.HALF_EVEN),n=e.validate(n),isNaN(t))throw Error("Precision is not a number: "+t);return(0,o.roundOff)(n,t,r)},e.prototype.round=function(n,t){if(void 0===n&&(n=0),void 0===t&&(t=f.RoundingModes.HALF_EVEN),isNaN(n))throw Error("Precision is not a number: "+n);return new e((0,o.roundOff)(this.value,n,t))},e.abs=function(n){return n=e.validate(n),(0,i.abs)(n)},e.prototype.abs=function(){return new e((0,i.abs)(this.value))},e.floor=function(n){return-1===(n=e.validate(n)).indexOf(".")?n:e.round(n,0,f.RoundingModes.FLOOR)},e.prototype.floor=function(){return-1===this.value.indexOf(".")?new e(this.value):new e(this.value).round(0,f.RoundingModes.FLOOR)},e.ceil=function(n){return-1===(n=e.validate(n)).indexOf(".")?n:e.round(n,0,f.RoundingModes.CEILING)},e.prototype.ceil=function(){return-1===this.value.indexOf(".")?new e(this.value):new e(this.value).round(0,f.RoundingModes.CEILING)},e.add=function(t,r){return t=e.validate(t),r=e.validate(r),(0,n.add)(t,r)},e.prototype.add=function(t){return new e((0,n.add)(this.value,t.getValue()))},e.subtract=function(n,t){return n=e.validate(n),t=e.validate(t),(0,l.subtract)(n,t)},e.prototype.subtract=function(n){return new e((0,l.subtract)(this.value,n.getValue()))},e.multiply=function(n,t){return n=e.validate(n),t=e.validate(t),(0,u.multiply)(n,t)},e.prototype.multiply=function(n){return new e((0,u.multiply)(this.value,n.getValue()))},e.divide=function(n,t,r){return n=e.validate(n),t=e.validate(t),(0,a.divide)(n,t,r)},e.prototype.divide=function(n,t){return new e((0,a.divide)(this.value,n.getValue(),t))},e.modulus=function(n,t){return n=e.validate(n),t=e.validate(t),(0,s.modulus)(n,t)},e.prototype.modulus=function(n){return new e((0,s.modulus)(this.value,n.getValue()))},e.compareTo=function(n,t){return n=e.validate(n),t=e.validate(t),(0,d.compareTo)(n,t)},e.prototype.compareTo=function(e){return(0,d.compareTo)(this.value,e.getValue())},e.negate=function(n){return n=e.validate(n),(0,l.negate)(n)},e.prototype.negate=function(){return new e((0,l.negate)(this.value))},e.RoundingModes=f.RoundingModes,e}();e.default=g}(),r}()})); \ No newline at end of file diff --git a/dist/web/js-big-decimal.js b/dist/web/js-big-decimal.js index 842c253..d3ae675 100644 --- a/dist/web/js-big-decimal.js +++ b/dist/web/js-big-decimal.js @@ -10,9 +10,9 @@ var bigDecimal; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.abs = void 0; function abs(n) { - if (typeof n == 'number' || typeof n == 'bigint') + if (typeof n == "number" || typeof n == "bigint") n = n.toString(); - if (n[0] == '-') + if (n[0] == "-") return n.substring(1); return n; } @@ -33,7 +33,7 @@ function add(number1, number2) { if (number2 === void 0) { number2 = "0"; } var neg = 0, ind = -1, neg_len; //check for negatives - if (number1[0] == '-') { + if (number1[0] == "-") { number1 = number1.substring(1); if (!testZero(number1)) { neg++; @@ -41,7 +41,7 @@ function add(number1, number2) { neg_len = number1.length; } } - if (number2[0] == '-') { + if (number2[0] == "-") { number2 = number2.substring(1); if (!testZero(number2)) { neg++; @@ -62,12 +62,12 @@ function add(number1, number2) { if (!neg) return trim(res); else if (neg == 2) - return ('-' + trim(res)); + return "-" + trim(res); else { - if (number1.length < (res.length)) + if (number1.length < res.length) return trim(res.substring(1)); else - return ('-' + trim(compliment(res))); + return "-" + trim(compliment(res)); } } exports.add = add; @@ -75,276 +75,79 @@ function compliment(number) { if (testZero(number)) { return number; } - var s = '', l = number.length, dec = number.split('.')[1], ld = dec ? dec.length : 0; + var s = "", l = number.length, dec = number.split(".")[1], ld = dec ? dec.length : 0; for (var i = 0; i < l; i++) { - if (number[i] >= '0' && number[i] <= '9') - s += (9 - parseInt(number[i])); + if (number[i] >= "0" && number[i] <= "9") + s += 9 - parseInt(number[i]); else s += number[i]; } - var one = (ld > 0) ? ('0.' + (new Array(ld)).join('0') + '1') : '1'; + var one = ld > 0 ? "0." + new Array(ld).join("0") + "1" : "1"; return addCore(s, one); } function trim(number) { - var parts = number.split('.'); + var parts = number.split("."); if (!parts[0]) - parts[0] = '0'; - while (parts[0][0] == '0' && parts[0].length > 1) + parts[0] = "0"; + while (parts[0][0] == "0" && parts[0].length > 1) parts[0] = parts[0].substring(1); - return parts[0] + (parts[1] ? ('.' + parts[1]) : ''); + return parts[0] + (parts[1] ? "." + parts[1] : ""); } exports.trim = trim; function pad(number1, number2) { - var parts1 = number1.split('.'), parts2 = number2.split('.'); + var parts1 = number1.split("."), parts2 = number2.split("."); //pad integral part var length1 = parts1[0].length, length2 = parts2[0].length; if (length1 > length2) { - parts2[0] = (new Array(Math.abs(length1 - length2) + 1)).join('0') + (parts2[0] ? parts2[0] : ''); + parts2[0] = + new Array(Math.abs(length1 - length2) + 1).join("0") + + (parts2[0] ? parts2[0] : ""); } else { - parts1[0] = (new Array(Math.abs(length1 - length2) + 1)).join('0') + (parts1[0] ? parts1[0] : ''); + parts1[0] = + new Array(Math.abs(length1 - length2) + 1).join("0") + + (parts1[0] ? parts1[0] : ""); } //pad fractional part - length1 = parts1[1] ? parts1[1].length : 0, - length2 = parts2[1] ? parts2[1].length : 0; + (length1 = parts1[1] ? parts1[1].length : 0), + (length2 = parts2[1] ? parts2[1].length : 0); if (length1 || length2) { if (length1 > length2) { - parts2[1] = (parts2[1] ? parts2[1] : '') + (new Array(Math.abs(length1 - length2) + 1)).join('0'); + parts2[1] = + (parts2[1] ? parts2[1] : "") + + new Array(Math.abs(length1 - length2) + 1).join("0"); } else { - parts1[1] = (parts1[1] ? parts1[1] : '') + (new Array(Math.abs(length1 - length2) + 1)).join('0'); + parts1[1] = + (parts1[1] ? parts1[1] : "") + + new Array(Math.abs(length1 - length2) + 1).join("0"); } } - number1 = parts1[0] + ((parts1[1]) ? ('.' + parts1[1]) : ''); - number2 = parts2[0] + ((parts2[1]) ? ('.' + parts2[1]) : ''); + number1 = parts1[0] + (parts1[1] ? "." + parts1[1] : ""); + number2 = parts2[0] + (parts2[1] ? "." + parts2[1] : ""); return [number1, number2]; } exports.pad = pad; function addCore(number1, number2) { var _a; _a = pad(number1, number2), number1 = _a[0], number2 = _a[1]; - var sum = '', carry = 0; + var sum = "", carry = 0; for (var i = number1.length - 1; i >= 0; i--) { - if (number1[i] === '.') { - sum = '.' + sum; + if (number1[i] === ".") { + sum = "." + sum; continue; } var temp = parseInt(number1[i]) + parseInt(number2[i]) + carry; sum = (temp % 10) + sum; carry = Math.floor(temp / 10); } - return carry ? (carry.toString() + sum) : sum; + return carry ? carry.toString() + sum : sum; } function testZero(number) { - return (/^0[0]*[.]{0,1}[0]*$/.test(number)); + return /^0[0]*[.]{0,1}[0]*$/.test(number); } -/***/ }), - -/***/ 423: -/***/ (function(module, __unused_webpack_exports, __webpack_require__) { - - -var add_1 = __webpack_require__(217); -var abs_1 = __webpack_require__(165); -var round_1 = __webpack_require__(350); -var multiply_1 = __webpack_require__(182); -var divide_1 = __webpack_require__(415); -var modulus_1 = __webpack_require__(213); -var compareTo_1 = __webpack_require__(664); -var subtract_1 = __webpack_require__(26); -var roundingModes_1 = __webpack_require__(916); -var bigDecimal = /** @class */ (function () { - function bigDecimal(number) { - if (number === void 0) { number = '0'; } - this.value = bigDecimal.validate(number); - } - bigDecimal.validate = function (number) { - if (number) { - number = number.toString(); - if (isNaN(number)) - throw Error("Parameter is not a number: " + number); - if (number[0] == '+') - number = number.substring(1); - } - else - number = '0'; - //handle missing leading zero - if (number.startsWith('.')) - number = '0' + number; - else if (number.startsWith('-.')) - number = '-0' + number.substr(1); - //handle exponentiation - if (/e/i.test(number)) { - var _a = number.split(/[eE]/), mantisa = _a[0], exponent = _a[1]; - mantisa = (0, add_1.trim)(mantisa); - var sign = ''; - if (mantisa[0] == '-') { - sign = '-'; - mantisa = mantisa.substring(1); - } - if (mantisa.indexOf('.') >= 0) { - exponent = parseInt(exponent) + mantisa.indexOf('.'); - mantisa = mantisa.replace('.', ''); - } - else { - exponent = parseInt(exponent) + mantisa.length; - } - if (mantisa.length < exponent) { - number = sign + mantisa + (new Array(exponent - mantisa.length + 1)).join('0'); - } - else if (mantisa.length >= exponent && exponent > 0) { - number = sign + (0, add_1.trim)(mantisa.substring(0, exponent)) + - ((mantisa.length > exponent) ? ('.' + mantisa.substring(exponent)) : ''); - } - else { - number = sign + '0.' + (new Array(-exponent + 1)).join('0') + mantisa; - } - } - return number; - }; - bigDecimal.prototype.getValue = function () { - return this.value; - }; - bigDecimal.prototype.setValue = function (num) { - this.value = bigDecimal.validate(num); - }; - bigDecimal.getPrettyValue = function (number, digits, separator) { - if (!(digits || separator)) { - digits = 3; - separator = ','; - } - else if (!(digits && separator)) { - throw Error('Illegal Arguments. Should pass both digits and separator or pass none'); - } - number = bigDecimal.validate(number); - var neg = number.charAt(0) == '-'; - if (neg) - number = number.substring(1); - var len = number.indexOf('.'); - len = len > 0 ? len : (number.length); - var temp = ''; - for (var i = len; i > 0;) { - if (i < digits) { - digits = i; - i = 0; - } - else - i -= digits; - temp = number.substring(i, i + digits) + ((i < (len - digits) && i >= 0) ? separator : '') + temp; - } - return (neg ? '-' : '') + temp + number.substring(len); - }; - bigDecimal.prototype.getPrettyValue = function (digits, separator) { - return bigDecimal.getPrettyValue(this.value, digits, separator); - }; - bigDecimal.round = function (number, precision, mode) { - if (precision === void 0) { precision = 0; } - if (mode === void 0) { mode = roundingModes_1.RoundingModes.HALF_EVEN; } - number = bigDecimal.validate(number); - // console.log(number) - if (isNaN(precision)) - throw Error("Precision is not a number: " + precision); - return (0, round_1.roundOff)(number, precision, mode); - }; - bigDecimal.prototype.round = function (precision, mode) { - if (precision === void 0) { precision = 0; } - if (mode === void 0) { mode = roundingModes_1.RoundingModes.HALF_EVEN; } - if (isNaN(precision)) - throw Error("Precision is not a number: " + precision); - return new bigDecimal((0, round_1.roundOff)(this.value, precision, mode)); - }; - bigDecimal.abs = function (number) { - number = bigDecimal.validate(number); - return (0, abs_1.abs)(number); - }; - bigDecimal.prototype.abs = function () { - return new bigDecimal((0, abs_1.abs)(this.value)); - }; - bigDecimal.floor = function (number) { - number = bigDecimal.validate(number); - if (number.indexOf('.') === -1) - return number; - return bigDecimal.round(number, 0, roundingModes_1.RoundingModes.FLOOR); - }; - bigDecimal.prototype.floor = function () { - if (this.value.indexOf('.') === -1) - return new bigDecimal(this.value); - return new bigDecimal(this.value).round(0, roundingModes_1.RoundingModes.FLOOR); - }; - bigDecimal.ceil = function (number) { - number = bigDecimal.validate(number); - if (number.indexOf('.') === -1) - return number; - return bigDecimal.round(number, 0, roundingModes_1.RoundingModes.CEILING); - }; - bigDecimal.prototype.ceil = function () { - if (this.value.indexOf('.') === -1) - return new bigDecimal(this.value); - return new bigDecimal(this.value).round(0, roundingModes_1.RoundingModes.CEILING); - }; - bigDecimal.add = function (number1, number2) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return (0, add_1.add)(number1, number2); - }; - bigDecimal.prototype.add = function (number) { - return new bigDecimal((0, add_1.add)(this.value, number.getValue())); - }; - bigDecimal.subtract = function (number1, number2) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return (0, subtract_1.subtract)(number1, number2); - }; - bigDecimal.prototype.subtract = function (number) { - return new bigDecimal((0, subtract_1.subtract)(this.value, number.getValue())); - }; - bigDecimal.multiply = function (number1, number2) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return (0, multiply_1.multiply)(number1, number2); - }; - bigDecimal.prototype.multiply = function (number) { - return new bigDecimal((0, multiply_1.multiply)(this.value, number.getValue())); - }; - bigDecimal.divide = function (number1, number2, precision) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return (0, divide_1.divide)(number1, number2, precision); - }; - bigDecimal.prototype.divide = function (number, precision) { - return new bigDecimal((0, divide_1.divide)(this.value, number.getValue(), precision)); - }; - bigDecimal.modulus = function (number1, number2) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return (0, modulus_1.modulus)(number1, number2); - }; - bigDecimal.prototype.modulus = function (number) { - return new bigDecimal((0, modulus_1.modulus)(this.value, number.getValue())); - }; - bigDecimal.compareTo = function (number1, number2) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return (0, compareTo_1.compareTo)(number1, number2); - }; - bigDecimal.prototype.compareTo = function (number) { - return (0, compareTo_1.compareTo)(this.value, number.getValue()); - }; - bigDecimal.negate = function (number) { - number = bigDecimal.validate(number); - return (0, subtract_1.negate)(number); - }; - bigDecimal.prototype.negate = function () { - return new bigDecimal((0, subtract_1.negate)(this.value)); - }; - bigDecimal.RoundingModes = roundingModes_1.RoundingModes; - return bigDecimal; -}()); -module.exports = bigDecimal; - - /***/ }), /***/ 664: @@ -865,12 +668,220 @@ exports.negate = negate; /******/ } /******/ /************************************************************************/ -/******/ -/******/ // startup -/******/ // Load entry module and return exports -/******/ // This entry module is referenced by other modules so it can't be inlined -/******/ var __webpack_exports__ = __webpack_require__(423); -/******/ bigDecimal = __webpack_exports__; -/******/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +!function() { +var exports = __webpack_exports__; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +var add_1 = __webpack_require__(217); +var abs_1 = __webpack_require__(165); +var round_1 = __webpack_require__(350); +var multiply_1 = __webpack_require__(182); +var divide_1 = __webpack_require__(415); +var modulus_1 = __webpack_require__(213); +var compareTo_1 = __webpack_require__(664); +var subtract_1 = __webpack_require__(26); +var roundingModes_1 = __webpack_require__(916); +var bigDecimal = /** @class */ (function () { + function bigDecimal(number) { + if (number === void 0) { number = "0"; } + this.value = bigDecimal.validate(number); + } + bigDecimal.validate = function (number) { + if (number) { + number = number.toString(); + if (isNaN(number)) + throw Error("Parameter is not a number: " + number); + if (number[0] == "+") + number = number.substring(1); + } + else + number = "0"; + //handle missing leading zero + if (number.startsWith(".")) + number = "0" + number; + else if (number.startsWith("-.")) + number = "-0" + number.substr(1); + //handle exponentiation + if (/e/i.test(number)) { + var _a = number.split(/[eE]/), mantisa = _a[0], exponent = _a[1]; + mantisa = (0, add_1.trim)(mantisa); + var sign = ""; + if (mantisa[0] == "-") { + sign = "-"; + mantisa = mantisa.substring(1); + } + if (mantisa.indexOf(".") >= 0) { + exponent = parseInt(exponent) + mantisa.indexOf("."); + mantisa = mantisa.replace(".", ""); + } + else { + exponent = parseInt(exponent) + mantisa.length; + } + if (mantisa.length < exponent) { + number = + sign + mantisa + new Array(exponent - mantisa.length + 1).join("0"); + } + else if (mantisa.length >= exponent && exponent > 0) { + number = + sign + + (0, add_1.trim)(mantisa.substring(0, exponent)) + + (mantisa.length > exponent ? "." + mantisa.substring(exponent) : ""); + } + else { + number = sign + "0." + new Array(-exponent + 1).join("0") + mantisa; + } + } + return number; + }; + bigDecimal.prototype.getValue = function () { + return this.value; + }; + bigDecimal.prototype.setValue = function (num) { + this.value = bigDecimal.validate(num); + }; + bigDecimal.getPrettyValue = function (number, digits, separator) { + if (digits === void 0) { digits = 3; } + if (separator === void 0) { separator = ","; } + // if (!(digits || separator)) { + // digits = 3; + // separator = ','; + // } else if (!(digits && separator)) { + // throw Error('Illegal Arguments. Should pass both digits and separator or pass none'); + // } + number = bigDecimal.validate(number); + var neg = number.charAt(0) == "-"; + if (neg) + number = number.substring(1); + var len = number.indexOf("."); + len = len > 0 ? len : number.length; + var temp = ""; + for (var i = len; i > 0;) { + if (i < digits) { + digits = i; + i = 0; + } + else + i -= digits; + temp = + number.substring(i, i + digits) + + (i < len - digits && i >= 0 ? separator : "") + + temp; + } + return (neg ? "-" : "") + temp + number.substring(len); + }; + bigDecimal.prototype.getPrettyValue = function (digits, separator) { + if (digits === void 0) { digits = 3; } + if (separator === void 0) { separator = ","; } + return bigDecimal.getPrettyValue(this.value, digits, separator); + }; + bigDecimal.round = function (number, precision, mode) { + if (precision === void 0) { precision = 0; } + if (mode === void 0) { mode = roundingModes_1.RoundingModes.HALF_EVEN; } + number = bigDecimal.validate(number); + // console.log(number) + if (isNaN(precision)) + throw Error("Precision is not a number: " + precision); + return (0, round_1.roundOff)(number, precision, mode); + }; + bigDecimal.prototype.round = function (precision, mode) { + if (precision === void 0) { precision = 0; } + if (mode === void 0) { mode = roundingModes_1.RoundingModes.HALF_EVEN; } + if (isNaN(precision)) + throw Error("Precision is not a number: " + precision); + return new bigDecimal((0, round_1.roundOff)(this.value, precision, mode)); + }; + bigDecimal.abs = function (number) { + number = bigDecimal.validate(number); + return (0, abs_1.abs)(number); + }; + bigDecimal.prototype.abs = function () { + return new bigDecimal((0, abs_1.abs)(this.value)); + }; + bigDecimal.floor = function (number) { + number = bigDecimal.validate(number); + if (number.indexOf(".") === -1) + return number; + return bigDecimal.round(number, 0, roundingModes_1.RoundingModes.FLOOR); + }; + bigDecimal.prototype.floor = function () { + if (this.value.indexOf(".") === -1) + return new bigDecimal(this.value); + return new bigDecimal(this.value).round(0, roundingModes_1.RoundingModes.FLOOR); + }; + bigDecimal.ceil = function (number) { + number = bigDecimal.validate(number); + if (number.indexOf(".") === -1) + return number; + return bigDecimal.round(number, 0, roundingModes_1.RoundingModes.CEILING); + }; + bigDecimal.prototype.ceil = function () { + if (this.value.indexOf(".") === -1) + return new bigDecimal(this.value); + return new bigDecimal(this.value).round(0, roundingModes_1.RoundingModes.CEILING); + }; + bigDecimal.add = function (number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return (0, add_1.add)(number1, number2); + }; + bigDecimal.prototype.add = function (number) { + return new bigDecimal((0, add_1.add)(this.value, number.getValue())); + }; + bigDecimal.subtract = function (number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return (0, subtract_1.subtract)(number1, number2); + }; + bigDecimal.prototype.subtract = function (number) { + return new bigDecimal((0, subtract_1.subtract)(this.value, number.getValue())); + }; + bigDecimal.multiply = function (number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return (0, multiply_1.multiply)(number1, number2); + }; + bigDecimal.prototype.multiply = function (number) { + return new bigDecimal((0, multiply_1.multiply)(this.value, number.getValue())); + }; + bigDecimal.divide = function (number1, number2, precision) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return (0, divide_1.divide)(number1, number2, precision); + }; + bigDecimal.prototype.divide = function (number, precision) { + return new bigDecimal((0, divide_1.divide)(this.value, number.getValue(), precision)); + }; + bigDecimal.modulus = function (number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return (0, modulus_1.modulus)(number1, number2); + }; + bigDecimal.prototype.modulus = function (number) { + return new bigDecimal((0, modulus_1.modulus)(this.value, number.getValue())); + }; + bigDecimal.compareTo = function (number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return (0, compareTo_1.compareTo)(number1, number2); + }; + bigDecimal.prototype.compareTo = function (number) { + return (0, compareTo_1.compareTo)(this.value, number.getValue()); + }; + bigDecimal.negate = function (number) { + number = bigDecimal.validate(number); + return (0, subtract_1.negate)(number); + }; + bigDecimal.prototype.negate = function () { + return new bigDecimal((0, subtract_1.negate)(this.value)); + }; + bigDecimal.RoundingModes = roundingModes_1.RoundingModes; + return bigDecimal; +}()); +exports["default"] = bigDecimal; + +}(); +bigDecimal = __webpack_exports__; /******/ })() ; \ No newline at end of file diff --git a/dist/web/js-big-decimal.min.js b/dist/web/js-big-decimal.min.js index afc0262..4617445 100644 --- a/dist/web/js-big-decimal.min.js +++ b/dist/web/js-big-decimal.min.js @@ -1 +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="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=0?(i=parseInt(i)+t.indexOf("."),t=t.replace(".","")):i=parseInt(i)+t.length,n=t.length=i&&i>0?o+(0,r.trim)(t.substring(0,i))+(t.length>i?"."+t.substring(i):""):o+"0."+new Array(1-i).join("0")+t}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){if(t||r){if(!t||!r)throw Error("Illegal Arguments. Should pass both digits and separator or pass none")}else t=3,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=0?r:"")+u;return(i?"-":"")+u+e.substring(o)},n.prototype.getPrettyValue=function(e,t){return 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(e,t){return e=n.validate(e),t=n.validate(t),(0,r.add)(e,t)},n.prototype.add=function(e){return new n((0,r.add)(this.value,e.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){return e=n.validate(e),t=n.validate(t),(0,a.divide)(e,t,r)},n.prototype.divide=function(e,t){return new n((0,a.divide)(this.value,e.getValue(),t))},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.RoundingModes=f.RoundingModes,n}();n.exports=g},664:function(n,e,t){Object.defineProperty(e,"__esModule",{value:!0}),e.compareTo=void 0;var r=t(217);e.compareTo=function(n,e){var t,i=!1;if("-"==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),i=!0),n=(t=(0,r.pad)(n,e))[0],e=t[1],0==n.localeCompare(e))return 0;for(var o=0;oe[o]?i?-1:1:i?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);e.divide=function(n,e,t){if(void 0===t&&(t=8),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 o=0;"-"==e[0]&&(e=e.substring(1),o++),"-"==n[0]&&(n=n.substring(1),o++);var u=e.indexOf(".")>0?e.length-e.indexOf(".")-1:-1;if(e=(0,r.trim)(e.replace(".","")),u>=0){var a=n.indexOf(".")>0?n.length-n.indexOf(".")-1:-1;if(-1==a)n=(0,r.trim)(n+new Array(u+1).join("0"));else if(u>a)n=n.replace(".",""),n=(0,r.trim)(n+new Array(u-a+1).join("0"));else if(u-1&&n.indexOf(".")-1&&n.indexOf(".")-1){var v=g.length-g.indexOf(".")-1;l>(g=g.replace(".","")).length&&(v+=l-g.length,g+=new Array(l-g.length+1).join("0")),d=v,f="0."+new Array(v).join("0")}for(t+=2;d<=t;){for(var c=0;parseInt(g)>=parseInt(e);)g=(0,r.add)(g,"-"+e),c++;f+=c,n?("."==n[0]&&(f+=".",d++,n=n.substring(1)),g+=n.substring(0,1),n=n.substring(1)):(d||(f+="."),d++,g+="0")}return(1==o?"-":"")+(0,r.trim)((0,i.roundOff)(f,t-2))}},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){function t(n){for(;"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),n}Object.defineProperty(e,"__esModule",{value:!0}),e.multiply=void 0,e.multiply=function(n,e){n=n.toString(),e=e.toString();var r=0;"-"==n[0]&&(r++,n=n.substr(1)),"-"==e[0]&&(r++,e=e.substr(1)),n=t(n),e=t(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=t(n.replace(".","")),e=t(e.replace(".","")),n.length=v&&b>=0;b--)g[b]>-1&&g[b]=s.length?new Array(d-s.length+1).join("0")+s:s).substr(0,s.length-d)+"."+s.substr(s.length-d,d))),1==r&&(c="-"+c),c}},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=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].lengtht?(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={}))},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={};var t=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}(423);bigDecimal=t}(); \ No newline at end of file +var bigDecimal;!function(){"use strict";var e={165:function(e,n){Object.defineProperty(n,"__esModule",{value:!0}),n.abs=void 0,n.abs=function(e){return"number"!=typeof e&&"bigint"!=typeof e||(e=e.toString()),"-"==e[0]?e.substring(1):e}},217:function(e,n){function t(e){if(u(e))return e;for(var n="",t=e.length,r=e.split(".")[1],i=r?r.length:0,a=0;a="0"&&e[a]<="9"?n+=9-parseInt(e[a]):n+=e[a];return o(n,i>0?"0."+new Array(i).join("0")+"1":"1")}function r(e){var n=e.split(".");for(n[0]||(n[0]="0");"0"==n[0][0]&&n[0].length>1;)n[0]=n[0].substring(1);return n[0]+(n[1]?"."+n[1]:"")}function i(e,n){var t=e.split("."),r=n.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")),[e=t[0]+(t[1]?"."+t[1]:""),n=r[0]+(r[1]?"."+r[1]:"")]}function o(e,n){var t;e=(t=i(e,n))[0],n=t[1];for(var r="",o=0,u=e.length-1;u>=0;u--)if("."!==e[u]){var a=parseInt(e[u])+parseInt(n[u])+o;r=a%10+r,o=Math.floor(a/10)}else r="."+r;return o?o.toString()+r:r}function u(e){return/^0[0]*[.]{0,1}[0]*$/.test(e)}Object.defineProperty(n,"__esModule",{value:!0}),n.pad=n.trim=n.add=void 0,n.add=function(e,n){var a;void 0===n&&(n="0");var s=0,d=-1;"-"==e[0]&&(u(e=e.substring(1))||(s++,d=1,e.length)),"-"==n[0]&&(u(n=n.substring(1))||(s++,d=2,n.length)),e=r(e),n=r(n),e=(a=i(r(e),r(n)))[0],n=a[1],1==s&&(1===d?e=t(e):2===d&&(n=t(n)));var l=o(e,n);return s?2==s?"-"+r(l):e.lengthn[o]?i?-1:1:i?1:-1;return 0}},415:function(e,n,t){Object.defineProperty(n,"__esModule",{value:!0}),n.divide=void 0;var r=t(217),i=t(350);n.divide=function(e,n,t){if(void 0===t&&(t=8),0==n)throw new Error("Cannot divide by 0");if(e=e.toString(),n=n.toString(),e=e.replace(/(\.\d*?[1-9])0+$/g,"$1").replace(/\.0+$/,""),n=n.replace(/(\.\d*?[1-9])0+$/g,"$1").replace(/\.0+$/,""),0==e)return"0";var o=0;"-"==n[0]&&(n=n.substring(1),o++),"-"==e[0]&&(e=e.substring(1),o++);var u=n.indexOf(".")>0?n.length-n.indexOf(".")-1:-1;if(n=(0,r.trim)(n.replace(".","")),u>=0){var a=e.indexOf(".")>0?e.length-e.indexOf(".")-1:-1;if(-1==a)e=(0,r.trim)(e+new Array(u+1).join("0"));else if(u>a)e=e.replace(".",""),e=(0,r.trim)(e+new Array(u-a+1).join("0"));else if(u-1&&e.indexOf(".")-1&&e.indexOf(".")-1){var v=g.length-g.indexOf(".")-1;l>(g=g.replace(".","")).length&&(v+=l-g.length,g+=new Array(l-g.length+1).join("0")),d=v,f="0."+new Array(v).join("0")}for(t+=2;d<=t;){for(var c=0;parseInt(g)>=parseInt(n);)g=(0,r.add)(g,"-"+n),c++;f+=c,e?("."==e[0]&&(f+=".",d++,e=e.substring(1)),g+=e.substring(0,1),e=e.substring(1)):(d||(f+="."),d++,g+="0")}return(1==o?"-":"")+(0,r.trim)((0,i.roundOff)(f,t-2))}},213:function(e,n,t){Object.defineProperty(n,"__esModule",{value:!0}),n.modulus=void 0;var r=t(415),i=t(350),o=t(182),u=t(26),a=t(916);function s(e){if(-1!=e.indexOf("."))throw new Error("Modulus of non-integers not supported")}n.modulus=function(e,n){if(0==n)throw new Error("Cannot divide by 0");e=e.toString(),n=n.toString(),s(e),s(n);var t="";return"-"==e[0]&&(t="-",e=e.substr(1)),"-"==n[0]&&(n=n.substr(1)),t+(0,u.subtract)(e,(0,o.multiply)(n,(0,i.roundOff)((0,r.divide)(e,n),0,a.RoundingModes.FLOOR)))}},182:function(e,n){function t(e){for(;"0"==e[0];)e=e.substr(1);if(-1!=e.indexOf("."))for(;"0"==e[e.length-1];)e=e.substr(0,e.length-1);return""==e||"."==e?e="0":"."==e[e.length-1]&&(e=e.substr(0,e.length-1)),"."==e[0]&&(e="0"+e),e}Object.defineProperty(n,"__esModule",{value:!0}),n.multiply=void 0,n.multiply=function(e,n){e=e.toString(),n=n.toString();var r=0;"-"==e[0]&&(r++,e=e.substr(1)),"-"==n[0]&&(r++,n=n.substr(1)),e=t(e),n=t(n);var i=0,o=0;-1!=e.indexOf(".")&&(i=e.length-e.indexOf(".")-1),-1!=n.indexOf(".")&&(o=n.length-n.indexOf(".")-1);var u=i+o;if(e=t(e.replace(".","")),n=t(n.replace(".","")),e.length=v&&b>=0;b--)g[b]>-1&&g[b]=s.length?new Array(d-s.length+1).join("0")+s:s).substr(0,s.length-d)+"."+s.substr(s.length-d,d))),1==r&&(c="-"+c),c}},350:function(e,n,t){Object.defineProperty(n,"__esModule",{value:!0}),n.roundOff=void 0;var r=t(916);function i(e,n,t,i){if(!e||e===new Array(e.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(e.length).join("0");if(e>o)return!0;if(e=0;r--){var i=parseInt(e[r])+n;10==i?(n=1,i=0):n=0,t+=i}return n&&(t+=n),t.split("").reverse().join("")}n.roundOff=function e(n,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 n&&"bigint"!=typeof n||(n=n.toString());var a=!1;"-"===n[0]&&(a=!0,n=n.substring(1));var s=n.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=e(n=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].lengtht?(a?"-":"")+o(d,parseInt(l[0]))+"."+l.substring(1):(a&&(parseInt(d)||parseInt(l))?"-":"")+d+"."+l}},916:function(e,n){Object.defineProperty(n,"__esModule",{value:!0}),n.RoundingModes=void 0,function(e){e[e.CEILING=0]="CEILING",e[e.DOWN=1]="DOWN",e[e.FLOOR=2]="FLOOR",e[e.HALF_DOWN=3]="HALF_DOWN",e[e.HALF_EVEN=4]="HALF_EVEN",e[e.HALF_UP=5]="HALF_UP",e[e.UNNECESSARY=6]="UNNECESSARY",e[e.UP=7]="UP"}(n.RoundingModes||(n.RoundingModes={}))},26:function(e,n,t){Object.defineProperty(n,"__esModule",{value:!0}),n.negate=n.subtract=void 0;var r=t(217);function i(e){return e="-"==e[0]?e.substr(1):"-"+e}n.subtract=function(e,n){return e=e.toString(),n=i(n=n.toString()),(0,r.add)(e,n)},n.negate=i}},n={};function t(r){var i=n[r];if(void 0!==i)return i.exports;var o=n[r]={exports:{}};return e[r](o,o.exports,t),o.exports}var r={};!function(){var e=r;Object.defineProperty(e,"__esModule",{value:!0});var n=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=function(){function e(n){void 0===n&&(n="0"),this.value=e.validate(n)}return e.validate=function(e){if(e){if(e=e.toString(),isNaN(e))throw Error("Parameter is not a number: "+e);"+"==e[0]&&(e=e.substring(1))}else e="0";if(e.startsWith(".")?e="0"+e:e.startsWith("-.")&&(e="-0"+e.substr(1)),/e/i.test(e)){var t=e.split(/[eE]/),r=t[0],i=t[1],o="";"-"==(r=(0,n.trim)(r))[0]&&(o="-",r=r.substring(1)),r.indexOf(".")>=0?(i=parseInt(i)+r.indexOf("."),r=r.replace(".","")):i=parseInt(i)+r.length,e=r.length=i&&i>0?o+(0,n.trim)(r.substring(0,i))+(r.length>i?"."+r.substring(i):""):o+"0."+new Array(1-i).join("0")+r}return e},e.prototype.getValue=function(){return this.value},e.prototype.setValue=function(n){this.value=e.validate(n)},e.getPrettyValue=function(n,t,r){void 0===t&&(t=3),void 0===r&&(r=",");var i="-"==(n=e.validate(n)).charAt(0);i&&(n=n.substring(1));for(var o=n.indexOf("."),u="",a=o=o>0?o:n.length;a>0;)a=0?r:"")+u;return(i?"-":"")+u+n.substring(o)},e.prototype.getPrettyValue=function(n,t){return void 0===n&&(n=3),void 0===t&&(t=","),e.getPrettyValue(this.value,n,t)},e.round=function(n,t,r){if(void 0===t&&(t=0),void 0===r&&(r=f.RoundingModes.HALF_EVEN),n=e.validate(n),isNaN(t))throw Error("Precision is not a number: "+t);return(0,o.roundOff)(n,t,r)},e.prototype.round=function(n,t){if(void 0===n&&(n=0),void 0===t&&(t=f.RoundingModes.HALF_EVEN),isNaN(n))throw Error("Precision is not a number: "+n);return new e((0,o.roundOff)(this.value,n,t))},e.abs=function(n){return n=e.validate(n),(0,i.abs)(n)},e.prototype.abs=function(){return new e((0,i.abs)(this.value))},e.floor=function(n){return-1===(n=e.validate(n)).indexOf(".")?n:e.round(n,0,f.RoundingModes.FLOOR)},e.prototype.floor=function(){return-1===this.value.indexOf(".")?new e(this.value):new e(this.value).round(0,f.RoundingModes.FLOOR)},e.ceil=function(n){return-1===(n=e.validate(n)).indexOf(".")?n:e.round(n,0,f.RoundingModes.CEILING)},e.prototype.ceil=function(){return-1===this.value.indexOf(".")?new e(this.value):new e(this.value).round(0,f.RoundingModes.CEILING)},e.add=function(t,r){return t=e.validate(t),r=e.validate(r),(0,n.add)(t,r)},e.prototype.add=function(t){return new e((0,n.add)(this.value,t.getValue()))},e.subtract=function(n,t){return n=e.validate(n),t=e.validate(t),(0,l.subtract)(n,t)},e.prototype.subtract=function(n){return new e((0,l.subtract)(this.value,n.getValue()))},e.multiply=function(n,t){return n=e.validate(n),t=e.validate(t),(0,u.multiply)(n,t)},e.prototype.multiply=function(n){return new e((0,u.multiply)(this.value,n.getValue()))},e.divide=function(n,t,r){return n=e.validate(n),t=e.validate(t),(0,a.divide)(n,t,r)},e.prototype.divide=function(n,t){return new e((0,a.divide)(this.value,n.getValue(),t))},e.modulus=function(n,t){return n=e.validate(n),t=e.validate(t),(0,s.modulus)(n,t)},e.prototype.modulus=function(n){return new e((0,s.modulus)(this.value,n.getValue()))},e.compareTo=function(n,t){return n=e.validate(n),t=e.validate(t),(0,d.compareTo)(n,t)},e.prototype.compareTo=function(e){return(0,d.compareTo)(this.value,e.getValue())},e.negate=function(n){return n=e.validate(n),(0,l.negate)(n)},e.prototype.negate=function(){return new e((0,l.negate)(this.value))},e.RoundingModes=f.RoundingModes,e}();e.default=g}(),bigDecimal=r}(); \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 1802e5e..1b6d543 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,6 +1,8 @@ var gulp = require('gulp'); var del = require('del'); var run = require('gulp-run'); +var ru = require('rollup'); +var ruTS = require('@rollup/plugin-typescript'); const paths = { src: ['./src/**/*.ts', '!./src/**/*.spec.ts'], @@ -16,6 +18,21 @@ gulp.task('clean', function () { }) gulp.task('dist', gulp.series('clean', function (done) { + // build es module with rollup + ru.rollup({ + input: paths.entry, + plugins: [ + ruTS.default({ + outDir: paths.dist + 'esm', + }), + ], + }).then((bundle) => { + bundle.write({ + dir: paths.dist + 'esm', + format: 'esm', + sourcemap: true, + }); + }); var cmd = new run.Command('webpack-cli', { silent: true }); diff --git a/package-lock.json b/package-lock.json index 71320f2..8fcef55 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,14 +1,15 @@ { "name": "js-big-decimal", - "version": "1.4.1", + "version": "2.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "js-big-decimal", - "version": "1.4.1", + "version": "2.0.0", "license": "MIT", "devDependencies": { + "@rollup/plugin-typescript": "^11.1.0", "@types/jasmine": "^4.3.1", "@types/node": "^18.11.18", "chokidar-cli": "^3.0.0", @@ -23,8 +24,10 @@ "jasmine-spec-reporter": "^7.0.0", "npm-run-all": "^4.1.5", "nyc": "^15.1.0", + "rollup": "^3.21.0", "ts-node": "^10.9.1", - "typescript": "^4.9.4", + "tslib": "^2.5.0", + "typescript": "^4.9.5", "webpack": "^5.75.0", "webpack-cli": "^4.10.0" } @@ -545,6 +548,60 @@ "node": ">= 8" } }, + "node_modules/@rollup/plugin-typescript": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-11.1.0.tgz", + "integrity": "sha512-86flrfE+bSHB69znnTV6kVjkncs2LBMhcTCyxWgRxLyfXfQrxg4UwlAqENnjrrxnSNS/XKCDJCl8EkdFJVHOxw==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "resolve": "^1.22.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^2.14.0||^3.0.0", + "tslib": "*", + "typescript": ">=3.7.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + }, + "tslib": { + "optional": true + } + } + }, + "node_modules/@rollup/pluginutils": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.2.tgz", + "integrity": "sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==", + "dev": true, + "dependencies": { + "@types/estree": "^1.0.0", + "estree-walker": "^2.0.2", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/pluginutils/node_modules/@types/estree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.1.tgz", + "integrity": "sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==", + "dev": true + }, "node_modules/@textlint/ast-node-types": { "version": "12.3.0", "resolved": "https://registry.npmjs.org/@textlint/ast-node-types/-/ast-node-types-12.3.0.tgz", @@ -2672,6 +2729,12 @@ "node": ">=4.0" } }, + "node_modules/estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "dev": true + }, "node_modules/events": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", @@ -8192,6 +8255,22 @@ "node": "*" } }, + "node_modules/rollup": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.21.0.tgz", + "integrity": "sha512-ANPhVcyeHvYdQMUyCbczy33nbLzI7RzrBje4uvNiTDJGIMtlKoOStmympwr9OtS1LZxiDmE2wvxHyVhoLtf1KQ==", + "dev": true, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=14.18.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -9346,6 +9425,12 @@ } } }, + "node_modules/tslib": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz", + "integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==", + "dev": true + }, "node_modules/tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", @@ -9395,9 +9480,9 @@ } }, "node_modules/typescript": { - "version": "4.9.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", - "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -10712,6 +10797,35 @@ "fastq": "^1.6.0" } }, + "@rollup/plugin-typescript": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-11.1.0.tgz", + "integrity": "sha512-86flrfE+bSHB69znnTV6kVjkncs2LBMhcTCyxWgRxLyfXfQrxg4UwlAqENnjrrxnSNS/XKCDJCl8EkdFJVHOxw==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^5.0.1", + "resolve": "^1.22.1" + } + }, + "@rollup/pluginutils": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.2.tgz", + "integrity": "sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==", + "dev": true, + "requires": { + "@types/estree": "^1.0.0", + "estree-walker": "^2.0.2", + "picomatch": "^2.3.1" + }, + "dependencies": { + "@types/estree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.1.tgz", + "integrity": "sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==", + "dev": true + } + } + }, "@textlint/ast-node-types": { "version": "12.3.0", "resolved": "https://registry.npmjs.org/@textlint/ast-node-types/-/ast-node-types-12.3.0.tgz", @@ -12403,6 +12517,12 @@ "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", "dev": true }, + "estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "dev": true + }, "events": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", @@ -14594,12 +14714,6 @@ "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "dev": true }, - "json5": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", - "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", - "dev": true - }, "jsprim": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz", @@ -16713,6 +16827,15 @@ } } }, + "rollup": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.21.0.tgz", + "integrity": "sha512-ANPhVcyeHvYdQMUyCbczy33nbLzI7RzrBje4uvNiTDJGIMtlKoOStmympwr9OtS1LZxiDmE2wvxHyVhoLtf1KQ==", + "dev": true, + "requires": { + "fsevents": "~2.3.2" + } + }, "run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -17608,6 +17731,12 @@ "yn": "3.1.1" } }, + "tslib": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz", + "integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==", + "dev": true + }, "tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", @@ -17651,9 +17780,9 @@ } }, "typescript": { - "version": "4.9.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", - "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "dev": true }, "unbox-primitive": { diff --git a/package.json b/package.json index def429c..3ab0a6d 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "name": "js-big-decimal", - "version": "1.4.1", - "description": "Work with large numbers on the client side. Round them off to any required precission.", + "version": "2.0.0", + "description": "Work with large numbers on the client side. Round them off to any required precision.", "main": "dist/node/js-big-decimal", "types": "dist/node/big-decimal", + "module": "dist/esm/big-decimal.js", "scripts": { "test": "ts-node node_modules/jasmine/bin/jasmine --config=spec/jasmine.json --helper=spec/helper/*.js", "test:watch": "chokidar \"src/**/*.ts\" -c \"npm run travis-test\"", @@ -46,6 +47,7 @@ }, "homepage": "https://github.com/royNiladri/js-big-decimal#readme", "devDependencies": { + "@rollup/plugin-typescript": "^11.1.0", "@types/jasmine": "^4.3.1", "@types/node": "^18.11.18", "chokidar-cli": "^3.0.0", @@ -60,8 +62,10 @@ "jasmine-spec-reporter": "^7.0.0", "npm-run-all": "^4.1.5", "nyc": "^15.1.0", + "rollup": "^3.21.0", "ts-node": "^10.9.1", - "typescript": "^4.9.4", + "tslib": "^2.5.0", + "typescript": "^4.9.5", "webpack": "^5.75.0", "webpack-cli": "^4.10.0" }, diff --git a/src/abs.ts b/src/abs.ts index 159c71b..658a007 100644 --- a/src/abs.ts +++ b/src/abs.ts @@ -1,7 +1,5 @@ -export function abs(n: number|string|bigint){ - if (typeof n == 'number' || typeof n == 'bigint') - n = n.toString(); - if (n[0] == '-') - return n.substring(1); - return n; -} \ No newline at end of file +export function abs(n: number | string | bigint) { + if (typeof n == "number" || typeof n == "bigint") n = n.toString(); + if (n[0] == "-") return n.substring(1); + return n; +} diff --git a/src/add.spec.ts b/src/add.spec.ts index 1cdcc2d..e1bccac 100644 --- a/src/add.spec.ts +++ b/src/add.spec.ts @@ -1,58 +1,57 @@ -var add = require('./big-decimal').add; - -describe('add', function () { - it('should be defined', function () { - expect(add).toBeDefined(); - }); - - it('should: 12+13 = 25', function () { - expect(add('12', '13')).toBe('25'); - }); - - it('should: 12-13 = -1', function () { - expect(add('12', '-13')).toBe('-1'); - }); - - it('should: 12.12+13.94 = 26.06', function () { - expect(add('12.12', '13.94')).toBe('26.06'); - }); - - it('should: 12-135 = -123', function () { - expect(add('12', '-135')).toBe('-123'); - }); - - it('should: 12.67+13 = 25.67', function () { - expect(add('12.67', '13')).toBe('25.67'); - }); - - it('should: -12.67+13 = 0.33', function () { - expect(add('-12.67', '13')).toBe('0.33'); - }); - - it('should: 12.67-13 = -0.33', function () { - expect(add('12.67', '-13')).toBe('-0.33'); - }); - - it('should: -12.67-13 = -0.33', function () { - expect(add('-12.67', '-13')).toBe('-25.67'); - }); - - it('should: 12.67+.13 = 12.80', function () { - expect(add('12.67', '.13')).toBe('12.80'); - }); - - it('should: 100-12 = 88', function () { - expect(add('100', '-12')).toBe('88'); - }); - - it('should: 126.7-13 = 113.7', function () { - expect(add('126.7', '-13')).toBe('113.7'); - }); - it('should: 12.67-130.7 = -118.03', function () { - expect(add('12.67', '-130.7')).toBe('-118.03'); - }); - it('should: 10+(-0) = 10', function() { - expect(add('10', '-0')).toBe('10'); - }); - -}) \ No newline at end of file +import { add } from "./add"; + +describe("add", function () { + it("should be defined", function () { + expect(add).toBeDefined(); + }); + + it("should: 12+13 = 25", function () { + expect(add("12", "13")).toBe("25"); + }); + + it("should: 12-13 = -1", function () { + expect(add("12", "-13")).toBe("-1"); + }); + + it("should: 12.12+13.94 = 26.06", function () { + expect(add("12.12", "13.94")).toBe("26.06"); + }); + + it("should: 12-135 = -123", function () { + expect(add("12", "-135")).toBe("-123"); + }); + + it("should: 12.67+13 = 25.67", function () { + expect(add("12.67", "13")).toBe("25.67"); + }); + + it("should: -12.67+13 = 0.33", function () { + expect(add("-12.67", "13")).toBe("0.33"); + }); + + it("should: 12.67-13 = -0.33", function () { + expect(add("12.67", "-13")).toBe("-0.33"); + }); + + it("should: -12.67-13 = -0.33", function () { + expect(add("-12.67", "-13")).toBe("-25.67"); + }); + + it("should: 12.67+.13 = 12.80", function () { + expect(add("12.67", ".13")).toBe("12.80"); + }); + + it("should: 100-12 = 88", function () { + expect(add("100", "-12")).toBe("88"); + }); + + it("should: 126.7-13 = 113.7", function () { + expect(add("126.7", "-13")).toBe("113.7"); + }); + it("should: 12.67-130.7 = -118.03", function () { + expect(add("12.67", "-130.7")).toBe("-118.03"); + }); + it("should: 10+(-0) = 10", function () { + expect(add("10", "-0")).toBe("10"); + }); +}); diff --git a/src/add.ts b/src/add.ts index daf309b..f677a4f 100644 --- a/src/add.ts +++ b/src/add.ts @@ -1,133 +1,134 @@ //function add { export function add(number1: string, number2 = "0") { - let neg = 0, ind = -1, neg_len; - - //check for negatives - if (number1[0] == '-') { - number1 = number1.substring(1); - if(!testZero(number1)){ - neg++; - ind = 1; - neg_len = number1.length; - } + let neg = 0, + ind = -1, + neg_len; + + //check for negatives + if (number1[0] == "-") { + number1 = number1.substring(1); + if (!testZero(number1)) { + neg++; + ind = 1; + neg_len = number1.length; } - if (number2[0] == '-') { - number2 = number2.substring(1); - if(!testZero(number2)){ - neg++; - ind = 2; - neg_len = number2.length; - } + } + if (number2[0] == "-") { + number2 = number2.substring(1); + if (!testZero(number2)) { + neg++; + ind = 2; + neg_len = number2.length; } + } - number1 = trim(number1); - number2 = trim(number2); + number1 = trim(number1); + number2 = trim(number2); - [number1, number2] = pad(trim(number1), trim(number2)); + [number1, number2] = pad(trim(number1), trim(number2)); - if (neg == 1) { - if (ind === 1) - number1 = compliment(number1); - else if (ind === 2) - number2 = compliment(number2); - } + if (neg == 1) { + if (ind === 1) number1 = compliment(number1); + else if (ind === 2) number2 = compliment(number2); + } - let res = addCore(number1, number2); - if (!neg) - return trim(res); - else if (neg == 2) - return ('-' + trim(res)); - else { - if (number1.length<(res.length)) - return trim(res.substring(1)); - else - return ('-' + trim(compliment(res))); - } + let res = addCore(number1, number2); + if (!neg) return trim(res); + else if (neg == 2) return "-" + trim(res); + else { + if (number1.length < res.length) return trim(res.substring(1)); + else return "-" + trim(compliment(res)); + } } function compliment(number: string) { - if (testZero(number)){ - return number; - } + if (testZero(number)) { + return number; + } - let s = '', - l = number.length, - dec = number.split('.')[1], - ld = dec ? dec.length : 0; + let s = "", + l = number.length, + dec = number.split(".")[1], + ld = dec ? dec.length : 0; - for (let i = 0; i < l; i++) { - if (number[i] >= '0' && number[i] <= '9') - s += (9 - parseInt(number[i])); - else - s += number[i]; - } + for (let i = 0; i < l; i++) { + if (number[i] >= "0" && number[i] <= "9") s += 9 - parseInt(number[i]); + else s += number[i]; + } - let one = (ld > 0) ? ('0.' + (new Array(ld)).join('0') + '1') : '1'; + let one = ld > 0 ? "0." + new Array(ld).join("0") + "1" : "1"; - return addCore(s, one); + return addCore(s, one); } export function trim(number: string) { - let parts = number.split('.'); + let parts = number.split("."); - if (!parts[0]) - parts[0] = '0'; + if (!parts[0]) parts[0] = "0"; - while (parts[0][0] == '0' && parts[0].length > 1) - parts[0] = parts[0].substring(1); + while (parts[0][0] == "0" && parts[0].length > 1) + parts[0] = parts[0].substring(1); - return parts[0] + (parts[1] ? ('.' + parts[1]) : ''); + return parts[0] + (parts[1] ? "." + parts[1] : ""); } -export function pad(number1:string, number2:string){ - let parts1 = number1.split('.'), - parts2 = number2.split('.'); - - //pad integral part - let length1 = parts1[0].length, - length2 = parts2[0].length; +export function pad(number1: string, number2: string) { + let parts1 = number1.split("."), + parts2 = number2.split("."); + + //pad integral part + let length1 = parts1[0].length, + length2 = parts2[0].length; + if (length1 > length2) { + parts2[0] = + new Array(Math.abs(length1 - length2) + 1).join("0") + + (parts2[0] ? parts2[0] : ""); + } else { + parts1[0] = + new Array(Math.abs(length1 - length2) + 1).join("0") + + (parts1[0] ? parts1[0] : ""); + } + + //pad fractional part + (length1 = parts1[1] ? parts1[1].length : 0), + (length2 = parts2[1] ? parts2[1].length : 0); + if (length1 || length2) { if (length1 > length2) { - parts2[0] = (new Array(Math.abs(length1 - length2) + 1)).join('0') + (parts2[0] ? parts2[0] : ''); + parts2[1] = + (parts2[1] ? parts2[1] : "") + + new Array(Math.abs(length1 - length2) + 1).join("0"); } else { - parts1[0] = (new Array(Math.abs(length1 - length2) + 1)).join('0') + (parts1[0] ? parts1[0] : ''); + parts1[1] = + (parts1[1] ? parts1[1] : "") + + new Array(Math.abs(length1 - length2) + 1).join("0"); } + } - //pad fractional part - length1 = parts1[1] ? parts1[1].length : 0, - length2 = parts2[1] ? parts2[1].length : 0; - if (length1 || length2) { - if (length1 > length2) { - parts2[1] = (parts2[1] ? parts2[1] : '') + (new Array(Math.abs(length1 - length2) + 1)).join('0'); - } else { - parts1[1] = (parts1[1] ? parts1[1] : '') + (new Array(Math.abs(length1 - length2) + 1)).join('0'); - } - } - - number1 = parts1[0] + ((parts1[1]) ? ('.' + parts1[1]) : ''); - number2 = parts2[0] + ((parts2[1]) ? ('.' + parts2[1]) : ''); + number1 = parts1[0] + (parts1[1] ? "." + parts1[1] : ""); + number2 = parts2[0] + (parts2[1] ? "." + parts2[1] : ""); - return [number1, number2]; + return [number1, number2]; } function addCore(number1: string, number2: string) { - [number1, number2] = pad(number1, number2); - - let sum = '', - carry = 0; - - for (let i = number1.length - 1; i >= 0; i--) { - if (number1[i] === '.') { - sum = '.' + sum; - continue; - } - let temp = parseInt(number1[i]) + parseInt(number2[i]) + carry; - sum = (temp % 10) + sum; - carry = Math.floor(temp / 10); + [number1, number2] = pad(number1, number2); + + let sum = "", + carry = 0; + + for (let i = number1.length - 1; i >= 0; i--) { + if (number1[i] === ".") { + sum = "." + sum; + continue; } + let temp = parseInt(number1[i]) + parseInt(number2[i]) + carry; + sum = (temp % 10) + sum; + carry = Math.floor(temp / 10); + } - return carry ? (carry.toString() + sum) : sum; + return carry ? carry.toString() + sum : sum; } -function testZero(number: string){ - return (/^0[0]*[.]{0,1}[0]*$/.test(number)); -} \ No newline at end of file +function testZero(number: string) { + return /^0[0]*[.]{0,1}[0]*$/.test(number); +} diff --git a/src/big-decimal.spec.ts b/src/big-decimal.spec.ts index a82c29b..b609005 100644 --- a/src/big-decimal.spec.ts +++ b/src/big-decimal.spec.ts @@ -1,426 +1,472 @@ -var bigDecimal = require('./big-decimal'); - -describe('BIG-DECIMAL', function () { - //var bigDecimal = require('./big-decimal'); - - it('should be defined', function () { - expect(bigDecimal).toBeDefined(); - }); - - describe('constructor', function () { - it('should return same value after creating Object', function () { - var n = new bigDecimal(12.34); - expect(n.getValue()).toBe('12.34'); - }); - - it('should not take non-numeric argument', function () { - try { - var n = new bigDecimal('notAnumber'); - expect(true).toBe(false); - } catch (e) { - expect(e.toString()).toMatch('Parameter is not a number'); - } - }); - - describe('missing leadinh zero', function() { - it('should transform .123 to 0.123', function() { - var n = new bigDecimal('.123'); - expect(n.getValue()).toBe('0.123') - }) - it('should transform -.123 to -0.123', function() { - var n = new bigDecimal('-.123'); - expect(n.getValue()).toBe('-0.123') - }) - }) - - describe('exponentiation', function () { - it('should transform 13.45e-5 to 0.0001345', function () { - var n = new bigDecimal('13.45e-5'); - expect(n.getValue()).toBe('0.0001345'); - }); - it('should transform 13.45e-4 to 0.001345', function () { - var n = new bigDecimal('13.45e-4'); - expect(n.getValue()).toBe('0.001345'); - }); - it('should transform 13.45e-3 to 0.01345', function () { - var n = new bigDecimal('13.45e-3'); - expect(n.getValue()).toBe('0.01345'); - }); - it('should transform 13.45e-2 to 0.1345', function () { - var n = new bigDecimal('13.45e-2'); - expect(n.getValue()).toBe('0.1345'); - }); - it('should transform 13.45e-1 to 1.345', function () { - var n = new bigDecimal('13.45e-1'); - expect(n.getValue()).toBe('1.345'); - }); - it('should transform 13.45e0 to 13.45', function () { - var n = new bigDecimal('13.45e0'); - expect(n.getValue()).toBe('13.45'); - }); - it('should transform 13.45e1 to 134.5', function () { - var n = new bigDecimal('13.45e1'); - expect(n.getValue()).toBe('134.5'); - }); - it('should transform 13.45e2 to 1345', function () { - var n = new bigDecimal('13.45e2'); - expect(n.getValue()).toBe('1345'); - }); - it('should transform 13.45e+3 to 13450', function () { - var n = new bigDecimal('13.45e+3'); - expect(n.getValue()).toBe('13450'); - }); - it('should transform 13.45e4 to 134500', function () { - var n = new bigDecimal('13.45e4'); - expect(n.getValue()).toBe('134500'); - }); - - it('should transform 0.1345e2 to 13.45', function () { - var n = new bigDecimal('0.1345e2'); - expect(n.getValue()).toBe('13.45'); - }); - it('should transform 0.1345e1 to 1.345', function () { - var n = new bigDecimal('0.1345e1'); - expect(n.getValue()).toBe('1.345'); - }); - it('should transform 2e-2 to 0.02', function () { - var n = new bigDecimal('2e-2'); - expect(n.getValue()).toBe('0.02'); - }); - it('should transform 0.1345e-1 to 0.01345', function () { - var n = new bigDecimal('0.1345e-1'); - expect(n.getValue()).toBe('0.01345'); - }); - it('should transform 0.1345e-2 to 0.001345', function () { - var n = new bigDecimal('0.1345e-2'); - expect(n.getValue()).toBe('0.001345'); - }); - it('should transform 0.1345e-2 to 0.001345', function () { - var n = new bigDecimal('0.1345e-2'); - expect(n.getValue()).toBe('0.001345'); - }); - - it('should transform 0.0134e2 to 1.34', function () { - var n = new bigDecimal('0.0134e2'); - expect(n.getValue()).toBe('1.34'); - }); - it('should transform 0.0134e1 to 0.1345', function () { - var n = new bigDecimal('0.0134e1'); - expect(n.getValue()).toBe('0.134'); - }); - it('should transform 0.0134e0 to 0.0134', function () { - var n = new bigDecimal('0.0134e0'); - expect(n.getValue()).toBe('0.0134'); - }); - it('should transform 0.0134e-1 to 0.00134', function () { - var n = new bigDecimal('0.0134e-1'); - expect(n.getValue()).toBe('0.00134'); - }); - it('should transform 0.0134e-2 to 0.000134', function () { - var n = new bigDecimal('0.0134e-2'); - expect(n.getValue()).toBe('0.000134'); - }); - - it('should transform .1e0 to 0.1', function(){ - var n = new bigDecimal('.1e0'); - expect(n.getValue()).toBe('0.1'); - }); - - it('should transform .001e1 to 0.01', function(){ - var n = new bigDecimal('.001e1'); - expect(n.getValue()).toBe('0.01'); - }); - - it('should transform .001e2 to 0.1', function(){ - var n = new bigDecimal('.001e2'); - expect(n.getValue()).toBe('0.1'); - }); - - - it('should transform 1e0 to 1', function(){ - var n = new bigDecimal('1e0'); - expect(n.getValue()).toBe('1'); - }); - it('should transform 1e1 to 10', function(){ - var n = new bigDecimal('1e1'); - expect(n.getValue()).toBe('10'); - }); - - it('should transform 10e0 to 10', function(){ - var n = new bigDecimal('10e0'); - expect(n.getValue()).toBe('10'); - }); - it('should transform 10e1 to 100', function(){ - var n = new bigDecimal('10e1'); - expect(n.getValue()).toBe('100'); - }); - it('should transform 10e-1 to 1.0', function(){ - var n = new bigDecimal('10e-1'); - expect(n.getValue()).toBe('1.0'); - }); - it('should transform 11e-1 to 1.1', function(){ - var n = new bigDecimal('11e-1'); - expect(n.getValue()).toBe('1.1'); - }); - - it('should transform +1e0 to 1', function(){ - var n = new bigDecimal('+1e0'); - expect(n.getValue()).toBe('1'); - }); - - it('should transform 10.0e0 to 10.0', function(){ - var n = new bigDecimal('10.0e0'); - expect(n.getValue()).toBe('10.0'); - }); - it('should transform 10.0e1 to 100', function(){ - var n = new bigDecimal('10.0e1'); - expect(n.getValue()).toBe('100'); - }); - it('should transform 10.0e-1 to 1.00', function(){ - var n = new bigDecimal('10.0e-1'); - expect(n.getValue()).toBe('1.00'); - }); - it('should transform -10.0e-1 to 1.00', function(){ - var n = new bigDecimal('-10.0e-1'); - expect(n.getValue()).toBe('-1.00'); - }); - - it('should transform -1e0 to -1', function(){ - var n = new bigDecimal('-1e0'); - expect(n.getValue()).toBe('-1'); - }); - it('should transform -1e1 to -10', function(){ - var n = new bigDecimal('-1e1'); - expect(n.getValue()).toBe('-10'); - }); - it('should transform -0.0134e-2 to -0.000134', function () { - var n = new bigDecimal('-0.0134e-2'); - expect(n.getValue()).toBe('-0.000134'); - }); - }); - }); - - describe('setValue', function() { - it('should allow setting value', function() { - var n = new bigDecimal('123'); - n.setValue('456'); - expect(n.getValue()).toBe('456'); - }) - }) - - describe('abs', function () { - it('should return 1.345 for -1.345', function () { - var n = new bigDecimal('-1.345'); - expect(n.abs().getValue()).toBe('1.345'); - expect(bigDecimal.abs('-1.345')).toBe('1.345'); - }); - - it('should return 1.345 for 1.345', function () { - var n = new bigDecimal('1.345'); - expect(n.abs().getValue()).toBe('1.345'); - expect(bigDecimal.abs('1.345')).toBe('1.345'); - }); - }); - - describe('round', function () { - it('should round off 12.678 to 12.68 if precision is set to 2', function () { - var n = new bigDecimal('12.678'); - expect(n.round(2).getValue()).toBe('12.68'); - }); - - it('should round off 12.678 to 13 if precision is not passed', function () { - var n = new bigDecimal('12.678'); - expect(n.round().getValue()).toBe('13'); - }); - - it('should round off 12.2678 to 12 if precision is set to 0', function () { - expect(bigDecimal.round('12.2678',0)).toBe('12'); - }); - - it('should round off to throw error if precision is not a number', function () { - try { - var n = new bigDecimal('12.2678'); - var r = n.round('zero'); - expect(true).toBeFalsy(); - } catch (e) { - expect(e).toMatch('Precision is not a number'); - } - }); - }); - - describe('pretty', function () { - it('should transform 1567866522.26567 to 1,567,866,522.26567 if pretty is called without arguments', function () { - var n = new bigDecimal('1567866522.26567'); - expect(n.getPrettyValue()).toBe('1,567,866,522.26567'); - }); - - it('should transform 1234567890123456 to 1234-5678-9012-3456 if pretty is called with 4, -', function () { - var n = new bigDecimal('1234567890123456'); - expect(n.getPrettyValue(4, '-')).toBe('1234-5678-9012-3456'); - }); - it('should transform 1567866522.26567 to 1,567,866,522.26567 if pretty is called without arguments', function () { - expect(bigDecimal.getPrettyValue('1567866522.26567')).toBe('1,567,866,522.26567'); - }); - - it('should transform 1234567890123456 to 1234-5678-9012-3456 if pretty is called with 4, -', function () { - expect(bigDecimal.getPrettyValue('1234567890123456', 4, '-')).toBe('1234-5678-9012-3456'); - }); - it('should transform -12.69 to -12.69', function(){ - expect(bigDecimal.getPrettyValue('-12.69')).toBe('-12.69'); - }); - it('should transform -123.69 to -123.69', function(){ - expect(bigDecimal.getPrettyValue('-123.69')).toBe('-123.69'); - }); - it('should transform -1234.69 to -1,234.69', function(){ - expect(bigDecimal.getPrettyValue('-1234.69')).toBe('-1,234.69'); - }) - }); - - describe('add', function () { - it('should produce 23.678+67.34=91.018', function () { - expect(bigDecimal.add('23.678', '67.34')).toBe('91.018'); - }); - - it('should produce -23.678+67.34=43.662', function () { - expect(bigDecimal.add('-23.678', '67.34')).toBe('43.662'); - }); - - it('should produce -23.678-67.34=-91.018', function () { - expect(bigDecimal.add('-23.678', '-67.34')).toBe('-91.018'); - }); - - it('should produce -23.678-67.34=-91.018', function () { - let bigDecimal1 = new bigDecimal('-23.678'); - expect(new bigDecimal('-23.678').add(new bigDecimal('-67.34')).getValue()).toBe(new bigDecimal('-91.018').getValue()); - }); - - it('should produce -23.678=-23.678', function () { - expect(bigDecimal.add('-23.678')).toBe('-23.678'); - }); - - it('should not take non-numeric argument', function () { - try { - var sum = bigDecimal.add('notAnumber', '89'); - expect(true).toBe(false); - } catch (e) { - expect(e.toString()).toMatch('Parameter is not a number'); - } - }); - it('should add -0 & 10 properly', function(){ - const n1 = new bigDecimal('-0'); - const n2 = new bigDecimal('10'); - const sum = n1.add(n2); - expect(sum.getValue()).toBe('10'); - }); - it('should add -0 & -10 properly', function(){ - const n1 = new bigDecimal('-0'); - const n2 = new bigDecimal('-10'); - const sum = n1.add(n2); - expect(sum.getValue()).toBe('-10'); - }); - }); - - describe('compareTo', function () { - it('should produce 23.678, 67.34= -1', function () { - expect(bigDecimal.compareTo('23.678', '67.34')).toBe(-1); - }); - it('should produce 23.678, -67.34= 1', function () { - expect(bigDecimal.compareTo('23.678', '-67.34')).toBe(1); - }); - it('should produce .678, 0.67800= 0', function () { - expect(bigDecimal.compareTo('.678', '0.67800')).toBe(0); - }); - it('should produce 23.678, 67.34= -1', function () { - expect(new bigDecimal('23.678').compareTo(new bigDecimal('67.34'))).toBe(-1); - }); - it('should produce 23.678, -67.34= 1', function () { - expect(new bigDecimal('23.678').compareTo(new bigDecimal('-67.34'))).toBe(1); - }); - it('should produce .678, 0.67800= 0', function () { - expect(new bigDecimal('.678').compareTo(new bigDecimal('0.67800'))).toBe(0); - }); - }); - - describe('multiply', function () { - it('should: -12 * 0 = 0', function () { - expect(new bigDecimal('-12').multiply(new bigDecimal('0')).getValue()).toBe('0'); - }); - - it('should: 12 * -0 = 0', function () { - expect(new bigDecimal('12').multiply(new bigDecimal('-0')).getValue()).toBe('0'); - }); - - - it('should: -12 * -0 = 0', function () { - expect(new bigDecimal('-12').multiply(new bigDecimal('-0')).getValue()).toBe('0'); - }); - it('should: -0.0000005 * 13 = -0.0000065', function () { - expect(new bigDecimal('-0.0000005').multiply(new bigDecimal('13')).getValue()).toBe('-0.0000065'); - }); - - it('should: 12 * 13 = 156', function () { - expect(new bigDecimal('12').multiply(new bigDecimal('13')).getValue()).toBe('156'); - }); - - it('should: 13 * 130 = 1690', function () { - expect(new bigDecimal('13').multiply(new bigDecimal('130')).getValue()).toBe('1690'); - }); - - it('should: 0.13 * 0.00130 = 0.000169', function () { - expect(new bigDecimal('0.13').multiply(new bigDecimal('0.00130')).getValue()).toBe('0.000169'); - }); - - it('should: 0.5 * 0.2 = 0.1', function () { - expect(new bigDecimal('0.5').multiply(new bigDecimal('0.2')).getValue()).toBe('0.1'); - }); - - it('should: -0.13 * 0.00130 = -0.000169', function () { - expect(new bigDecimal('-0.13').multiply(new bigDecimal('0.00130')).getValue()).toBe('-0.000169'); - }); - - it('should: 13.0 * 0.00130 = 0.000169', function () { - expect(bigDecimal.multiply('13.0', '0.00130')).toBe('0.0169'); - }); - - it('should: -0.05 * -0.02 = 0.001', function () { - expect(new bigDecimal('-0.05').multiply(new bigDecimal('-0.02')).getValue()).toBe('0.001'); - }); - - it('should: .05 * .02 = 0.001', function () { - expect(new bigDecimal('.05').multiply(new bigDecimal('.02')).getValue()).toBe('0.001'); - }); - }); - - describe('divide', function(){ - it('should: 22 / 7 = 3.1428571429', function(){ - expect(bigDecimal.divide('22', '7', 10)).toBe('3.1428571429'); - }); - it('should: 72 / 13 = 5.53846153846154', function(){ - expect(bigDecimal.divide('72', '13')).toBe('5.53846154'); - }); - it('should: 24 / 120 = 0.2', function(){ - expect(new bigDecimal('24').divide(new bigDecimal('120'), 2).getValue()).toBe('0.20'); - }); - }) - - describe('subtract', function () { - it('should: -12 - 0 = -12', function () { - expect(new bigDecimal('-12').subtract(new bigDecimal('0')).getValue()).toBe('-12'); - }); - it('should: 0 - 12 = -12', function () { - expect(new bigDecimal('0').subtract(new bigDecimal('12')).getValue()).toBe('-12'); - }); - it('should: 12 - 12 = 0', function () { - expect(new bigDecimal('12').subtract(new bigDecimal('12')).getValue()).toBe('0'); - }); - it('should: -12 - 12 = -24', function () { - expect(new bigDecimal('-12').subtract(new bigDecimal('12')).getValue()).toBe('-24'); - }); - it('should: 12 - -12 = 24', function () { - expect(new bigDecimal('12').subtract(new bigDecimal('-12')).getValue()).toBe('24'); - }); - it('should: 12 - -12.0 = 24', function () { - expect(new bigDecimal('12').subtract(new bigDecimal('-12.0')).getValue()).toBe('24.0'); - }); - }); -}) \ No newline at end of file +import bigDecimal from "./big-decimal"; + +describe("BIG-DECIMAL", function () { + //var bigDecimal = require('./big-decimal'); + + it("should be defined", function () { + expect(bigDecimal).toBeDefined(); + }); + + describe("constructor", function () { + it("should return same value after creating Object", function () { + var n = new bigDecimal(12.34); + expect(n.getValue()).toBe("12.34"); + }); + + it("should not take non-numeric argument", function () { + try { + var n = new bigDecimal("notAnumber"); + expect(true).toBe(false); + } catch (e) { + expect(e.toString()).toMatch("Parameter is not a number"); + } + }); + + describe("missing leadinh zero", function () { + it("should transform .123 to 0.123", function () { + var n = new bigDecimal(".123"); + expect(n.getValue()).toBe("0.123"); + }); + it("should transform -.123 to -0.123", function () { + var n = new bigDecimal("-.123"); + expect(n.getValue()).toBe("-0.123"); + }); + }); + + describe("exponentiation", function () { + it("should transform 13.45e-5 to 0.0001345", function () { + var n = new bigDecimal("13.45e-5"); + expect(n.getValue()).toBe("0.0001345"); + }); + it("should transform 13.45e-4 to 0.001345", function () { + var n = new bigDecimal("13.45e-4"); + expect(n.getValue()).toBe("0.001345"); + }); + it("should transform 13.45e-3 to 0.01345", function () { + var n = new bigDecimal("13.45e-3"); + expect(n.getValue()).toBe("0.01345"); + }); + it("should transform 13.45e-2 to 0.1345", function () { + var n = new bigDecimal("13.45e-2"); + expect(n.getValue()).toBe("0.1345"); + }); + it("should transform 13.45e-1 to 1.345", function () { + var n = new bigDecimal("13.45e-1"); + expect(n.getValue()).toBe("1.345"); + }); + it("should transform 13.45e0 to 13.45", function () { + var n = new bigDecimal("13.45e0"); + expect(n.getValue()).toBe("13.45"); + }); + it("should transform 13.45e1 to 134.5", function () { + var n = new bigDecimal("13.45e1"); + expect(n.getValue()).toBe("134.5"); + }); + it("should transform 13.45e2 to 1345", function () { + var n = new bigDecimal("13.45e2"); + expect(n.getValue()).toBe("1345"); + }); + it("should transform 13.45e+3 to 13450", function () { + var n = new bigDecimal("13.45e+3"); + expect(n.getValue()).toBe("13450"); + }); + it("should transform 13.45e4 to 134500", function () { + var n = new bigDecimal("13.45e4"); + expect(n.getValue()).toBe("134500"); + }); + + it("should transform 0.1345e2 to 13.45", function () { + var n = new bigDecimal("0.1345e2"); + expect(n.getValue()).toBe("13.45"); + }); + it("should transform 0.1345e1 to 1.345", function () { + var n = new bigDecimal("0.1345e1"); + expect(n.getValue()).toBe("1.345"); + }); + it("should transform 2e-2 to 0.02", function () { + var n = new bigDecimal("2e-2"); + expect(n.getValue()).toBe("0.02"); + }); + it("should transform 0.1345e-1 to 0.01345", function () { + var n = new bigDecimal("0.1345e-1"); + expect(n.getValue()).toBe("0.01345"); + }); + it("should transform 0.1345e-2 to 0.001345", function () { + var n = new bigDecimal("0.1345e-2"); + expect(n.getValue()).toBe("0.001345"); + }); + it("should transform 0.1345e-2 to 0.001345", function () { + var n = new bigDecimal("0.1345e-2"); + expect(n.getValue()).toBe("0.001345"); + }); + + it("should transform 0.0134e2 to 1.34", function () { + var n = new bigDecimal("0.0134e2"); + expect(n.getValue()).toBe("1.34"); + }); + it("should transform 0.0134e1 to 0.1345", function () { + var n = new bigDecimal("0.0134e1"); + expect(n.getValue()).toBe("0.134"); + }); + it("should transform 0.0134e0 to 0.0134", function () { + var n = new bigDecimal("0.0134e0"); + expect(n.getValue()).toBe("0.0134"); + }); + it("should transform 0.0134e-1 to 0.00134", function () { + var n = new bigDecimal("0.0134e-1"); + expect(n.getValue()).toBe("0.00134"); + }); + it("should transform 0.0134e-2 to 0.000134", function () { + var n = new bigDecimal("0.0134e-2"); + expect(n.getValue()).toBe("0.000134"); + }); + + it("should transform .1e0 to 0.1", function () { + var n = new bigDecimal(".1e0"); + expect(n.getValue()).toBe("0.1"); + }); + + it("should transform .001e1 to 0.01", function () { + var n = new bigDecimal(".001e1"); + expect(n.getValue()).toBe("0.01"); + }); + + it("should transform .001e2 to 0.1", function () { + var n = new bigDecimal(".001e2"); + expect(n.getValue()).toBe("0.1"); + }); + + it("should transform 1e0 to 1", function () { + var n = new bigDecimal("1e0"); + expect(n.getValue()).toBe("1"); + }); + it("should transform 1e1 to 10", function () { + var n = new bigDecimal("1e1"); + expect(n.getValue()).toBe("10"); + }); + + it("should transform 10e0 to 10", function () { + var n = new bigDecimal("10e0"); + expect(n.getValue()).toBe("10"); + }); + it("should transform 10e1 to 100", function () { + var n = new bigDecimal("10e1"); + expect(n.getValue()).toBe("100"); + }); + it("should transform 10e-1 to 1.0", function () { + var n = new bigDecimal("10e-1"); + expect(n.getValue()).toBe("1.0"); + }); + it("should transform 11e-1 to 1.1", function () { + var n = new bigDecimal("11e-1"); + expect(n.getValue()).toBe("1.1"); + }); + + it("should transform +1e0 to 1", function () { + var n = new bigDecimal("+1e0"); + expect(n.getValue()).toBe("1"); + }); + + it("should transform 10.0e0 to 10.0", function () { + var n = new bigDecimal("10.0e0"); + expect(n.getValue()).toBe("10.0"); + }); + it("should transform 10.0e1 to 100", function () { + var n = new bigDecimal("10.0e1"); + expect(n.getValue()).toBe("100"); + }); + it("should transform 10.0e-1 to 1.00", function () { + var n = new bigDecimal("10.0e-1"); + expect(n.getValue()).toBe("1.00"); + }); + it("should transform -10.0e-1 to 1.00", function () { + var n = new bigDecimal("-10.0e-1"); + expect(n.getValue()).toBe("-1.00"); + }); + + it("should transform -1e0 to -1", function () { + var n = new bigDecimal("-1e0"); + expect(n.getValue()).toBe("-1"); + }); + it("should transform -1e1 to -10", function () { + var n = new bigDecimal("-1e1"); + expect(n.getValue()).toBe("-10"); + }); + it("should transform -0.0134e-2 to -0.000134", function () { + var n = new bigDecimal("-0.0134e-2"); + expect(n.getValue()).toBe("-0.000134"); + }); + }); + }); + + describe("setValue", function () { + it("should allow setting value", function () { + var n = new bigDecimal("123"); + n.setValue("456"); + expect(n.getValue()).toBe("456"); + }); + }); + + describe("abs", function () { + it("should return 1.345 for -1.345", function () { + var n = new bigDecimal("-1.345"); + expect(n.abs().getValue()).toBe("1.345"); + expect(bigDecimal.abs("-1.345")).toBe("1.345"); + }); + + it("should return 1.345 for 1.345", function () { + var n = new bigDecimal("1.345"); + expect(n.abs().getValue()).toBe("1.345"); + expect(bigDecimal.abs("1.345")).toBe("1.345"); + }); + }); + + describe("round", function () { + it("should round off 12.678 to 12.68 if precision is set to 2", function () { + var n = new bigDecimal("12.678"); + expect(n.round(2).getValue()).toBe("12.68"); + }); + + it("should round off 12.678 to 13 if precision is not passed", function () { + var n = new bigDecimal("12.678"); + expect(n.round().getValue()).toBe("13"); + }); + + it("should round off 12.2678 to 12 if precision is set to 0", function () { + expect(bigDecimal.round("12.2678", 0)).toBe("12"); + }); + + // it("should round off to throw error if precision is not a number", function () { + // try { + // var n = new bigDecimal("12.2678"); + // var r = n.round("zero"); + // expect(true).toBeFalsy(); + // } catch (e) { + // expect(e).toMatch("Precision is not a number"); + // } + // }); + }); + + describe("pretty", function () { + it("should transform 1567866522.26567 to 1,567,866,522.26567 if pretty is called without arguments", function () { + var n = new bigDecimal("1567866522.26567"); + expect(n.getPrettyValue()).toBe("1,567,866,522.26567"); + }); + + it("should transform 1234567890123456 to 1234-5678-9012-3456 if pretty is called with 4, -", function () { + var n = new bigDecimal("1234567890123456"); + expect(n.getPrettyValue(4, "-")).toBe("1234-5678-9012-3456"); + }); + it("should transform 1567866522.26567 to 1,567,866,522.26567 if pretty is called without arguments", function () { + expect(bigDecimal.getPrettyValue("1567866522.26567")).toBe( + "1,567,866,522.26567" + ); + }); + + it("should transform 1234567890123456 to 1234-5678-9012-3456 if pretty is called with 4, -", function () { + expect(bigDecimal.getPrettyValue("1234567890123456", 4, "-")).toBe( + "1234-5678-9012-3456" + ); + }); + it("should transform -12.69 to -12.69", function () { + expect(bigDecimal.getPrettyValue("-12.69")).toBe("-12.69"); + }); + it("should transform -123.69 to -123.69", function () { + expect(bigDecimal.getPrettyValue("-123.69")).toBe("-123.69"); + }); + it("should transform -1234.69 to -1,234.69", function () { + expect(bigDecimal.getPrettyValue("-1234.69")).toBe("-1,234.69"); + }); + }); + + describe("add", function () { + it("should produce 23.678+67.34=91.018", function () { + expect(bigDecimal.add("23.678", "67.34")).toBe("91.018"); + }); + + it("should produce -23.678+67.34=43.662", function () { + expect(bigDecimal.add("-23.678", "67.34")).toBe("43.662"); + }); + + it("should produce -23.678-67.34=-91.018", function () { + expect(bigDecimal.add("-23.678", "-67.34")).toBe("-91.018"); + }); + + it("should produce -23.678-67.34=-91.018", function () { + let bigDecimal1 = new bigDecimal("-23.678"); + expect( + new bigDecimal("-23.678").add(new bigDecimal("-67.34")).getValue() + ).toBe(new bigDecimal("-91.018").getValue()); + }); + + // it("should produce -23.678=-23.678", function () { + // expect(bigDecimal.add("-23.678")).toBe("-23.678"); + // }); + + it("should not take non-numeric argument", function () { + try { + var sum = bigDecimal.add("notAnumber", "89"); + expect(true).toBe(false); + } catch (e) { + expect(e.toString()).toMatch("Parameter is not a number"); + } + }); + it("should add -0 & 10 properly", function () { + const n1 = new bigDecimal("-0"); + const n2 = new bigDecimal("10"); + const sum = n1.add(n2); + expect(sum.getValue()).toBe("10"); + }); + it("should add -0 & -10 properly", function () { + const n1 = new bigDecimal("-0"); + const n2 = new bigDecimal("-10"); + const sum = n1.add(n2); + expect(sum.getValue()).toBe("-10"); + }); + }); + + describe("compareTo", function () { + it("should produce 23.678, 67.34= -1", function () { + expect(bigDecimal.compareTo("23.678", "67.34")).toBe(-1); + }); + it("should produce 23.678, -67.34= 1", function () { + expect(bigDecimal.compareTo("23.678", "-67.34")).toBe(1); + }); + it("should produce .678, 0.67800= 0", function () { + expect(bigDecimal.compareTo(".678", "0.67800")).toBe(0); + }); + it("should produce 23.678, 67.34= -1", function () { + expect(new bigDecimal("23.678").compareTo(new bigDecimal("67.34"))).toBe( + -1 + ); + }); + it("should produce 23.678, -67.34= 1", function () { + expect(new bigDecimal("23.678").compareTo(new bigDecimal("-67.34"))).toBe( + 1 + ); + }); + it("should produce .678, 0.67800= 0", function () { + expect(new bigDecimal(".678").compareTo(new bigDecimal("0.67800"))).toBe( + 0 + ); + }); + }); + + describe("multiply", function () { + it("should: -12 * 0 = 0", function () { + expect( + new bigDecimal("-12").multiply(new bigDecimal("0")).getValue() + ).toBe("0"); + }); + + it("should: 12 * -0 = 0", function () { + expect( + new bigDecimal("12").multiply(new bigDecimal("-0")).getValue() + ).toBe("0"); + }); + + it("should: -12 * -0 = 0", function () { + expect( + new bigDecimal("-12").multiply(new bigDecimal("-0")).getValue() + ).toBe("0"); + }); + it("should: -0.0000005 * 13 = -0.0000065", function () { + expect( + new bigDecimal("-0.0000005").multiply(new bigDecimal("13")).getValue() + ).toBe("-0.0000065"); + }); + + it("should: 12 * 13 = 156", function () { + expect( + new bigDecimal("12").multiply(new bigDecimal("13")).getValue() + ).toBe("156"); + }); + + it("should: 13 * 130 = 1690", function () { + expect( + new bigDecimal("13").multiply(new bigDecimal("130")).getValue() + ).toBe("1690"); + }); + + it("should: 0.13 * 0.00130 = 0.000169", function () { + expect( + new bigDecimal("0.13").multiply(new bigDecimal("0.00130")).getValue() + ).toBe("0.000169"); + }); + + it("should: 0.5 * 0.2 = 0.1", function () { + expect( + new bigDecimal("0.5").multiply(new bigDecimal("0.2")).getValue() + ).toBe("0.1"); + }); + + it("should: -0.13 * 0.00130 = -0.000169", function () { + expect( + new bigDecimal("-0.13").multiply(new bigDecimal("0.00130")).getValue() + ).toBe("-0.000169"); + }); + + it("should: 13.0 * 0.00130 = 0.000169", function () { + expect(bigDecimal.multiply("13.0", "0.00130")).toBe("0.0169"); + }); + + it("should: -0.05 * -0.02 = 0.001", function () { + expect( + new bigDecimal("-0.05").multiply(new bigDecimal("-0.02")).getValue() + ).toBe("0.001"); + }); + + it("should: .05 * .02 = 0.001", function () { + expect( + new bigDecimal(".05").multiply(new bigDecimal(".02")).getValue() + ).toBe("0.001"); + }); + }); + + describe("divide", function () { + it("should: 22 / 7 = 3.1428571429", function () { + expect(bigDecimal.divide("22", "7", 10)).toBe("3.1428571429"); + }); + it("should: 72 / 13 = 5.53846153846154", function () { + expect(bigDecimal.divide("72", "13")).toBe("5.53846154"); + }); + it("should: 24 / 120 = 0.2", function () { + expect( + new bigDecimal("24").divide(new bigDecimal("120"), 2).getValue() + ).toBe("0.20"); + }); + }); + + describe("subtract", function () { + it("should: -12 - 0 = -12", function () { + expect( + new bigDecimal("-12").subtract(new bigDecimal("0")).getValue() + ).toBe("-12"); + }); + it("should: 0 - 12 = -12", function () { + expect( + new bigDecimal("0").subtract(new bigDecimal("12")).getValue() + ).toBe("-12"); + }); + it("should: 12 - 12 = 0", function () { + expect( + new bigDecimal("12").subtract(new bigDecimal("12")).getValue() + ).toBe("0"); + }); + it("should: -12 - 12 = -24", function () { + expect( + new bigDecimal("-12").subtract(new bigDecimal("12")).getValue() + ).toBe("-24"); + }); + it("should: 12 - -12 = 24", function () { + expect( + new bigDecimal("12").subtract(new bigDecimal("-12")).getValue() + ).toBe("24"); + }); + it("should: 12 - -12.0 = 24", function () { + expect( + new bigDecimal("12").subtract(new bigDecimal("-12.0")).getValue() + ).toBe("24.0"); + }); + }); +}); diff --git a/src/big-decimal.ts b/src/big-decimal.ts index 5ab258f..582dd3c 100644 --- a/src/big-decimal.ts +++ b/src/big-decimal.ts @@ -1,225 +1,218 @@ -import { add, trim } from './add'; -import { abs } from './abs'; -import { roundOff } from './round'; -import { multiply } from './multiply'; -import { divide } from './divide'; -import { modulus } from './modulus'; -import { compareTo } from './compareTo'; -import { subtract, negate } from './subtract'; -import { RoundingModes as Modes, RoundingModes } from './roundingModes'; +import { add, trim } from "./add"; +import { abs } from "./abs"; +import { roundOff } from "./round"; +import { multiply } from "./multiply"; +import { divide } from "./divide"; +import { modulus } from "./modulus"; +import { compareTo } from "./compareTo"; +import { subtract, negate } from "./subtract"; +import { RoundingModes as Modes, RoundingModes } from "./roundingModes"; class bigDecimal { - - private value: string; - static RoundingModes = Modes; - - private static validate(number): string { - if (number) { - number = number.toString(); - if (isNaN(number)) - throw Error("Parameter is not a number: " + number); - - if (number[0] == '+') - number = number.substring(1); - } else - number = '0'; - - //handle missing leading zero - if (number.startsWith('.')) - number = '0' + number; - else if (number.startsWith('-.')) - number = '-0' + number.substr(1); - - //handle exponentiation - if (/e/i.test(number)) { - let [mantisa, exponent] = number.split(/[eE]/); - mantisa = trim(mantisa); - - let sign = ''; - if (mantisa[0] == '-') { - sign = '-'; - mantisa = mantisa.substring(1); - } - - if (mantisa.indexOf('.') >= 0) { - exponent = parseInt(exponent) + mantisa.indexOf('.'); - mantisa = mantisa.replace('.', ''); - } else { - exponent = parseInt(exponent) + mantisa.length; - } - - if (mantisa.length < exponent) { - number = sign + mantisa + (new Array(exponent - mantisa.length + 1)).join('0'); - } else if (mantisa.length >= exponent && exponent > 0) { - number = sign + trim(mantisa.substring(0, exponent)) + - ((mantisa.length > exponent) ? ('.' + mantisa.substring(exponent)) : ''); - } else { - number = sign + '0.' + (new Array(-exponent + 1)).join('0') + mantisa; - } - } - - return number; - } - - constructor(number: (number | string | bigint) = '0') { - this.value = bigDecimal.validate(number); - } - - getValue() { - return this.value; - } - - setValue(num: (number | string | bigint)) { - this.value = bigDecimal.validate(num); - } - - static getPrettyValue(number, digits, separator): string { - if (!(digits || separator)) { - digits = 3; - separator = ','; - } else if (!(digits && separator)) { - throw Error('Illegal Arguments. Should pass both digits and separator or pass none'); - } - number = bigDecimal.validate(number); - let neg = number.charAt(0) == '-'; - if (neg) - number = number.substring(1); - var len = number.indexOf('.'); - len = len > 0 ? len : (number.length); - var temp = ''; - for (var i = len; i > 0;) { - if (i < digits) { - digits = i; - i = 0; - } else - i -= digits; - - temp = number.substring(i, i + digits) + ((i < (len - digits) && i >= 0) ? separator : '') + temp; - } - return (neg ? '-' : '') + temp + number.substring(len); - } - getPrettyValue(digits, separator) { - return bigDecimal.getPrettyValue(this.value, digits, separator); - } - - static round(number, precision = 0, mode = Modes.HALF_EVEN) { - number = bigDecimal.validate(number); - // console.log(number) - if (isNaN(precision)) - throw Error("Precision is not a number: " + precision); - return roundOff(number, precision, mode); - } - - round(precision = 0, mode = Modes.HALF_EVEN) { - if (isNaN(precision)) - throw Error("Precision is not a number: " + precision); - - return new bigDecimal(roundOff(this.value, precision, mode)); - } - - static abs(number) { - number = bigDecimal.validate(number); - return abs(number); - } - - abs() { - return new bigDecimal(abs(this.value)); - } - - static floor(number) { - number = bigDecimal.validate(number); - if (number.indexOf('.') === -1) - return number; - return bigDecimal.round(number, 0, RoundingModes.FLOOR); - } - - floor() { - if (this.value.indexOf('.') === -1) - return new bigDecimal(this.value); - return new bigDecimal(this.value).round(0, RoundingModes.FLOOR); - } - - static ceil(number) { - number = bigDecimal.validate(number); - if (number.indexOf('.') === -1) - return number; - return bigDecimal.round(number, 0, RoundingModes.CEILING); - } - - ceil() { - if (this.value.indexOf('.') === -1) - return new bigDecimal(this.value); - return new bigDecimal(this.value).round(0, RoundingModes.CEILING); - } - - - static add(number1, number2) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return add(number1, number2); - } - - add(number: bigDecimal) { - return new bigDecimal(add(this.value, number.getValue())); - } - - static subtract(number1, number2) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return subtract(number1, number2); - } - - subtract(number: bigDecimal) { - return new bigDecimal(subtract(this.value, number.getValue())); - } - - static multiply(number1, number2) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return multiply(number1, number2); - } - - multiply(number: bigDecimal) { - return new bigDecimal(multiply(this.value, number.getValue())); - } - - static divide(number1, number2, precision) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return divide(number1, number2, precision); - } - - divide(number: bigDecimal, precision) { - return new bigDecimal(divide(this.value, number.getValue(), precision)); - } - - static modulus(number1, number2) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return modulus(number1, number2); - } - - modulus(number: bigDecimal) { - return new bigDecimal(modulus(this.value, number.getValue())); - } - - static compareTo(number1, number2) { - number1 = bigDecimal.validate(number1); - number2 = bigDecimal.validate(number2); - return compareTo(number1, number2); - } - - compareTo(number: bigDecimal) { - return compareTo(this.value, number.getValue()); - } - - static negate(number) { - number = bigDecimal.validate(number); - return negate(number); - } - - negate() { - return new bigDecimal(negate(this.value)); - } + private value: string; + static RoundingModes = Modes; + + private static validate(number): string { + if (number) { + number = number.toString(); + if (isNaN(number)) throw Error("Parameter is not a number: " + number); + + if (number[0] == "+") number = number.substring(1); + } else number = "0"; + + //handle missing leading zero + if (number.startsWith(".")) number = "0" + number; + else if (number.startsWith("-.")) number = "-0" + number.substr(1); + + //handle exponentiation + if (/e/i.test(number)) { + let [mantisa, exponent] = number.split(/[eE]/); + mantisa = trim(mantisa); + + let sign = ""; + if (mantisa[0] == "-") { + sign = "-"; + mantisa = mantisa.substring(1); + } + + if (mantisa.indexOf(".") >= 0) { + exponent = parseInt(exponent) + mantisa.indexOf("."); + mantisa = mantisa.replace(".", ""); + } else { + exponent = parseInt(exponent) + mantisa.length; + } + + if (mantisa.length < exponent) { + number = + sign + mantisa + new Array(exponent - mantisa.length + 1).join("0"); + } else if (mantisa.length >= exponent && exponent > 0) { + number = + sign + + trim(mantisa.substring(0, exponent)) + + (mantisa.length > exponent ? "." + mantisa.substring(exponent) : ""); + } else { + number = sign + "0." + new Array(-exponent + 1).join("0") + mantisa; + } + } + + return number; + } + + constructor(number: number | string | bigint = "0") { + this.value = bigDecimal.validate(number); + } + + getValue() { + return this.value; + } + + setValue(num: number | string | bigint) { + this.value = bigDecimal.validate(num); + } + + static getPrettyValue(number, digits = 3, separator = ","): string { + // if (!(digits || separator)) { + // digits = 3; + // separator = ','; + // } else if (!(digits && separator)) { + // throw Error('Illegal Arguments. Should pass both digits and separator or pass none'); + // } + number = bigDecimal.validate(number); + let neg = number.charAt(0) == "-"; + if (neg) number = number.substring(1); + var len = number.indexOf("."); + len = len > 0 ? len : number.length; + var temp = ""; + for (var i = len; i > 0; ) { + if (i < digits) { + digits = i; + i = 0; + } else i -= digits; + + temp = + number.substring(i, i + digits) + + (i < len - digits && i >= 0 ? separator : "") + + temp; + } + return (neg ? "-" : "") + temp + number.substring(len); + } + getPrettyValue(digits = 3, separator = ",") { + return bigDecimal.getPrettyValue(this.value, digits, separator); + } + + static round(number, precision = 0, mode = Modes.HALF_EVEN) { + number = bigDecimal.validate(number); + // console.log(number) + if (isNaN(precision)) + throw Error("Precision is not a number: " + precision); + return roundOff(number, precision, mode); + } + + round(precision = 0, mode = Modes.HALF_EVEN) { + if (isNaN(precision)) + throw Error("Precision is not a number: " + precision); + + return new bigDecimal(roundOff(this.value, precision, mode)); + } + + static abs(number) { + number = bigDecimal.validate(number); + return abs(number); + } + + abs() { + return new bigDecimal(abs(this.value)); + } + + static floor(number) { + number = bigDecimal.validate(number); + if (number.indexOf(".") === -1) return number; + return bigDecimal.round(number, 0, RoundingModes.FLOOR); + } + + floor() { + if (this.value.indexOf(".") === -1) return new bigDecimal(this.value); + return new bigDecimal(this.value).round(0, RoundingModes.FLOOR); + } + + static ceil(number) { + number = bigDecimal.validate(number); + if (number.indexOf(".") === -1) return number; + return bigDecimal.round(number, 0, RoundingModes.CEILING); + } + + ceil() { + if (this.value.indexOf(".") === -1) return new bigDecimal(this.value); + return new bigDecimal(this.value).round(0, RoundingModes.CEILING); + } + + static add(number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return add(number1, number2); + } + + add(number: bigDecimal) { + return new bigDecimal(add(this.value, number.getValue())); + } + + static subtract(number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return subtract(number1, number2); + } + + subtract(number: bigDecimal) { + return new bigDecimal(subtract(this.value, number.getValue())); + } + + static multiply(number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return multiply(number1, number2); + } + + multiply(number: bigDecimal) { + return new bigDecimal(multiply(this.value, number.getValue())); + } + + static divide(number1, number2, precision?: number) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return divide(number1, number2, precision); + } + + divide(number: bigDecimal, precision) { + return new bigDecimal(divide(this.value, number.getValue(), precision)); + } + + static modulus(number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return modulus(number1, number2); + } + + modulus(number: bigDecimal) { + return new bigDecimal(modulus(this.value, number.getValue())); + } + + static compareTo(number1, number2) { + number1 = bigDecimal.validate(number1); + number2 = bigDecimal.validate(number2); + return compareTo(number1, number2); + } + + compareTo(number: bigDecimal) { + return compareTo(this.value, number.getValue()); + } + + static negate(number) { + number = bigDecimal.validate(number); + return negate(number); + } + + negate() { + return new bigDecimal(negate(this.value)); + } } -export = bigDecimal; \ No newline at end of file +export default bigDecimal; diff --git a/src/compareTo.spec.ts b/src/compareTo.spec.ts index 490b826..13c0360 100644 --- a/src/compareTo.spec.ts +++ b/src/compareTo.spec.ts @@ -1,68 +1,66 @@ -var compareTo = require('./big-decimal').compareTo; +import { compareTo } from "./compareTo"; -describe('compareTo', function () { - it('should be defined', function () { - expect(compareTo).toBeDefined(); - }); +describe("compareTo", function () { + it("should be defined", function () { + expect(compareTo).toBeDefined(); + }); + it("should: 12 , 13 = -1", function () { + expect(compareTo("12", "13")).toBe(-1); + }); - it('should: 12 , 13 = -1', function () { - expect(compareTo('12', '13')).toBe(-1); - }); + it("should: 12 , -13 = 1", function () { + expect(compareTo("12", "-13")).toBe(1); + }); - it('should: 12 , -13 = 1', function () { - expect(compareTo('12', '-13')).toBe(1); - }); + it("should: 12.12, 13.94 = -1", function () { + expect(compareTo("12.12", "13.94")).toBe(-1); + }); - it('should: 12.12, 13.94 = -1', function () { - expect(compareTo('12.12', '13.94')).toBe(-1); - }); + it("should: 12, -135 = 1", function () { + expect(compareTo("12", "-135")).toBe(1); + }); - it('should: 12, -135 = 1', function () { - expect(compareTo('12', '-135')).toBe(1); - }); + it("should: 12.67, 13 = -1", function () { + expect(compareTo("12.67", "13")).toBe(-1); + }); - it('should: 12.67, 13 = -1', function () { - expect(compareTo('12.67', '13')).toBe(-1); - }); + it("should: -12.67, 13 = -1", function () { + expect(compareTo("-12.67", "13")).toBe(-1); + }); - it('should: -12.67, 13 = -1', function () { - expect(compareTo('-12.67', '13')).toBe(-1); - }); + it("should: 12.67, -13 = 1", function () { + expect(compareTo("12.67", "-13")).toBe(1); + }); - it('should: 12.67, -13 = 1', function () { - expect(compareTo('12.67', '-13')).toBe(1); - }); + it("should: -12.67, -13 = 1", function () { + expect(compareTo("-12.67", "-13")).toBe(1); + }); - it('should: -12.67, -13 = 1', function () { - expect(compareTo('-12.67', '-13')).toBe(1); - }); + it("should: 12.67, .13 = 1", function () { + expect(compareTo("12.67", ".13")).toBe(1); + }); - it('should: 12.67, .13 = 1', function () { - expect(compareTo('12.67', '.13')).toBe(1); - }); + it("should: 100, -12 = 1", function () { + expect(compareTo("100", "-12")).toBe(1); + }); - it('should: 100, -12 = 1', function () { - expect(compareTo('100', '-12')).toBe(1); - }); - - it('should: 126.7, -13 = 1', function () { - expect(compareTo('126.7', '-13')).toBe(1); - }); - it('should: 12.67, -12.67 = 1', function () { - expect(compareTo('12.67', '-12.67')).toBe(1); - }); - it('should: 12.67, 12.67 = 0', function () { - expect(compareTo('12.67', '12.67')).toBe(0); - }); - it('should: 12.67, 12.6700 = 0', function () { - expect(compareTo('12.67', '12.6700')).toBe(0); - }); - it('should: -12.67, -12.6700 = 0', function () { - expect(compareTo('-12.67', '-12.6700')).toBe(0); - }); - it('should: 0.67, .6700 = 0', function () { - expect(compareTo('0.67', '.6700')).toBe(0); - }); - -}) \ No newline at end of file + it("should: 126.7, -13 = 1", function () { + expect(compareTo("126.7", "-13")).toBe(1); + }); + it("should: 12.67, -12.67 = 1", function () { + expect(compareTo("12.67", "-12.67")).toBe(1); + }); + it("should: 12.67, 12.67 = 0", function () { + expect(compareTo("12.67", "12.67")).toBe(0); + }); + it("should: 12.67, 12.6700 = 0", function () { + expect(compareTo("12.67", "12.6700")).toBe(0); + }); + it("should: -12.67, -12.6700 = 0", function () { + expect(compareTo("-12.67", "-12.6700")).toBe(0); + }); + it("should: 0.67, .6700 = 0", function () { + expect(compareTo("0.67", ".6700")).toBe(0); + }); +}); diff --git a/src/divide.spec.ts b/src/divide.spec.ts index 79e85c6..0c7d83e 100644 --- a/src/divide.spec.ts +++ b/src/divide.spec.ts @@ -1,85 +1,103 @@ -const divide = require('./big-decimal').divide; +import bigDecimal from "./big-decimal"; +const divide = bigDecimal.divide; -describe('divide', function(){ - it('test failing scenario', function(){ - expect(divide('509365950.27576', '0.003802940215600348', 16)).toBe('133940036234.6609666927392804'); - }) - xit('STRESS TEST - should return correct result', function(){ - let count = 2000, err = 0; - while(count-- > 0){ - let dividend:any = (Math.random()*(Math.pow(10, Math.floor(Math.random()*10)))).toFixed(5); - let divisor:any = (Math.random()*(Math.pow(10, Math.floor(Math.random()*10)))); - if(divisor==0){ - count++; - continue; - } - let jsOut = dividend/divisor; - let myOut = parseFloat(divide(dividend.toString(), divisor.toString(), 5)); - if(isNaN(myOut) || Math.abs(jsOut-myOut)>0.00001){ - console.log(`${dividend}/${divisor} = ${jsOut} != ${myOut}`); - err++; - }else - { - //console.log(`${dividend}/${divisor} = ${jsOut} == ${myOut}`); - } - } - expect(err).toBe(0); - }); - it('should do basic integer division', function(){ - expect(divide(1234, 12, 2)).toBe('102.83'); - }); - it('should do basic floating point division', function(){ - expect(divide(12.34, 12, 2)).toBe('1.03'); - }); - it('should do basic floating point division', function(){ - expect(divide(29629629362962961839.48344234, 12345678901234567890, 2)).toBe('2.40'); - }); - it('should do basic floating point division', function(){ - expect(divide('296296293629629614563475463462345345235412412341235436563456829629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683939296296293629629614563475463462345345235412412341235436563456829629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683939.48344234', '1000', 10)).toBe('296296293629629614563475463462345345235412412341235436563456829629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683939296296293629629614563475463462345345235412412341235436563456829629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683.9394834423'); - }); - it('should do basic floating point division', function(){ - expect(divide(45, -4, 2)).toBe('-11.25'); - }); - it('should do basic floating point division', function(){ - expect(divide(-45, -4, 2)).toBe('11.25'); - }); - it('1 / 25 = 0.04', function(){ - expect(divide('1', '25', 2)).toBe('0.04'); - }); - it('-1 / 25 = -0.04', function(){ - expect(divide('-1', '25', 2)).toBe('-0.04'); - }); - it('1 / -25 = -0.04', function(){ - expect(divide('1', '-25', 2)).toBe('-0.04'); - }); - it('-1 / -25 = 0.04', function(){ - expect(divide('-1', '-25', 2)).toBe('0.04'); - }); - it('-1 / -1 = 1', function(){ - expect(divide('-1', '-1', 0)).toBe('1'); - }); - it('10.8 / 10 = 1.08', function(){ - expect(divide('10.8', '10')).toBe('1.08000000'); - }); - it('10.8 / 100 = 0.108', function(){ - expect(divide('10.8', '100')).toBe('0.10800000'); - }); - it('10.8 / 1000 = 0.0108', function(){ - expect(divide('10.8', '1000')).toBe('0.01080000'); - }); - it('10.8 / 10000 = 0.00108', function(){ - expect(divide('10.8', '10000')).toBe('0.00108000'); - }); - it('2.00 / 0.5 = 4.00', function(){ - expect(divide('2.00', '0.5', 2)).toBe('4.00'); - }); - it('0.11005 / 0.1 = 1.1005', function(){ - expect(divide('0.11005', '0.1', 4)).toBe('1.1005'); - }); - it('123456789.123456 / .0123456 = 10000063919.40902022', function(){ - expect(divide('123456789.123456', '.0123456')).toBe('10000063919.40902022'); - }); - it('.102 / .0383292 = 2.66115651', function(){ - expect(divide('.102', '.0383292',8)).toBe('2.66115651'); - }); -}) \ No newline at end of file +describe("divide", function () { + it("test failing scenario", function () { + expect(divide("509365950.27576", "0.003802940215600348", 16)).toBe( + "133940036234.6609666927392804" + ); + }); + xit("STRESS TEST - should return correct result", function () { + let count = 2000, + err = 0; + while (count-- > 0) { + let dividend: any = ( + Math.random() * Math.pow(10, Math.floor(Math.random() * 10)) + ).toFixed(5); + let divisor: any = + Math.random() * Math.pow(10, Math.floor(Math.random() * 10)); + if (divisor == 0) { + count++; + continue; + } + let jsOut = dividend / divisor; + let myOut = parseFloat( + divide(dividend.toString(), divisor.toString(), 5) + ); + if (isNaN(myOut) || Math.abs(jsOut - myOut) > 0.00001) { + console.log(`${dividend}/${divisor} = ${jsOut} != ${myOut}`); + err++; + } else { + //console.log(`${dividend}/${divisor} = ${jsOut} == ${myOut}`); + } + } + expect(err).toBe(0); + }); + it("should do basic integer division", function () { + expect(divide(1234, 12, 2)).toBe("102.83"); + }); + it("should do basic floating point division", function () { + expect(divide(12.34, 12, 2)).toBe("1.03"); + }); + it("should do basic floating point division", function () { + expect(divide(29629629362962961839.48344234, 12345678901234567890, 2)).toBe( + "2.40" + ); + }); + it("should do basic floating point division", function () { + expect( + divide( + "296296293629629614563475463462345345235412412341235436563456829629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683939296296293629629614563475463462345345235412412341235436563456829629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683939.48344234", + "1000", + 10 + ) + ).toBe( + "296296293629629614563475463462345345235412412341235436563456829629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683939296296293629629614563475463462345345235412412341235436563456829629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683929629629362962961456347546346234534523541241234123543656345683.9394834423" + ); + }); + it("should do basic floating point division", function () { + expect(divide(45, -4, 2)).toBe("-11.25"); + }); + it("should do basic floating point division", function () { + expect(divide(-45, -4, 2)).toBe("11.25"); + }); + it("1 / 25 = 0.04", function () { + expect(divide("1", "25", 2)).toBe("0.04"); + }); + it("-1 / 25 = -0.04", function () { + expect(divide("-1", "25", 2)).toBe("-0.04"); + }); + it("1 / -25 = -0.04", function () { + expect(divide("1", "-25", 2)).toBe("-0.04"); + }); + it("-1 / -25 = 0.04", function () { + expect(divide("-1", "-25", 2)).toBe("0.04"); + }); + it("-1 / -1 = 1", function () { + expect(divide("-1", "-1", 0)).toBe("1"); + }); + it("10.8 / 10 = 1.08", function () { + expect(divide("10.8", "10")).toBe("1.08000000"); + }); + it("10.8 / 100 = 0.108", function () { + expect(divide("10.8", "100")).toBe("0.10800000"); + }); + it("10.8 / 1000 = 0.0108", function () { + expect(divide("10.8", "1000")).toBe("0.01080000"); + }); + it("10.8 / 10000 = 0.00108", function () { + expect(divide("10.8", "10000")).toBe("0.00108000"); + }); + it("2.00 / 0.5 = 4.00", function () { + expect(divide("2.00", "0.5", 2)).toBe("4.00"); + }); + it("0.11005 / 0.1 = 1.1005", function () { + expect(divide("0.11005", "0.1", 4)).toBe("1.1005"); + }); + it("123456789.123456 / .0123456 = 10000063919.40902022", function () { + expect(divide("123456789.123456", ".0123456")).toBe("10000063919.40902022"); + }); + it(".102 / .0383292 = 2.66115651", function () { + expect(divide(".102", ".0383292", 8)).toBe("2.66115651"); + }); +}); diff --git a/src/modulus.spec.ts b/src/modulus.spec.ts index 28f2b4d..b07734f 100644 --- a/src/modulus.spec.ts +++ b/src/modulus.spec.ts @@ -1,34 +1,33 @@ -const modulus = require('./big-decimal').modulus; +import { modulus } from "./modulus"; -describe('modulus', function(){ - it('should modulus(7,4) = 3', function() { - expect(modulus(7,4)).toBe('3'); - }) - it('should modulus(-7,4) = -3', function() { - expect(modulus(-7,4)).toBe('-3'); - }) - it('should modulus(7,-4) = 3', function() { - expect(modulus(7,-4)).toBe('3'); - }) - it('should modulus(-7,-4) = 3', function() { - expect(modulus(-7,-4)).toBe('-3'); - }) - it('should modulus(-7,0) throw', function() { - expect(()=> modulus(-7,0)).toThrowError(); - }) - - it('should modulus(76457896543456%77732) = 45352', function() { - expect(modulus('76457896543456','77732')).toBe('45352'); - }) +describe("modulus", function () { + it("should modulus(7,4) = 3", function () { + expect(modulus(7, 4)).toBe("3"); + }); + it("should modulus(-7,4) = -3", function () { + expect(modulus(-7, 4)).toBe("-3"); + }); + it("should modulus(7,-4) = 3", function () { + expect(modulus(7, -4)).toBe("3"); + }); + it("should modulus(-7,-4) = 3", function () { + expect(modulus(-7, -4)).toBe("-3"); + }); + it("should modulus(-7,0) throw", function () { + expect(() => modulus(-7, 0)).toThrowError(); + }); - it('should modulus(7.5%3.2) to throw error', function() { - expect(()=> modulus('7.5','3.2')).toThrowError(); - }) - it('should modulus(75%3.2) to throw error', function() { - expect(()=> modulus('75','3.2')).toThrowError(); - }) - it('should modulus(7.5%32) to throw error', function() { - expect(()=> modulus('7.5','32')).toThrowError(); - }) + it("should modulus(76457896543456%77732) = 45352", function () { + expect(modulus("76457896543456", "77732")).toBe("45352"); + }); -}) \ No newline at end of file + it("should modulus(7.5%3.2) to throw error", function () { + expect(() => modulus("7.5", "3.2")).toThrowError(); + }); + it("should modulus(75%3.2) to throw error", function () { + expect(() => modulus("75", "3.2")).toThrowError(); + }); + it("should modulus(7.5%32) to throw error", function () { + expect(() => modulus("7.5", "32")).toThrowError(); + }); +}); diff --git a/src/multiply.spec.ts b/src/multiply.spec.ts index 53250af..3214b38 100644 --- a/src/multiply.spec.ts +++ b/src/multiply.spec.ts @@ -1,87 +1,89 @@ -var multiply = require('./big-decimal').multiply; - -describe('multiply', function () { - xit('STRESS TEST - should return correct result', function(){ - let count = 100, err = 0; - while(count-- > 0){ - let dividend = Math.round(Math.random()*(Math.pow(10, Math.floor(Math.random()*5)))); - let divisor = Math.round(Math.random()*(Math.pow(10, Math.floor(Math.random()*5)))); - //if(divisor==0) - //continue; - let jsOut = dividend*divisor; - let myOut = parseFloat(multiply(dividend, divisor)); - if(Math.abs(jsOut-myOut)>0.001){ - //console.log(`${dividend}/${divisor} = ${jsOut} != ${myOut}`); - err++; - }else - { - //console.log(`${dividend}/${divisor} = ${jsOut} == ${myOut}`); - } - } - expect(err).toBe(0); - }); - it('should be defined', function () { - expect(multiply).toBeDefined(); - }); - - it('should: 12 * 13 = 156', function () { - expect(multiply('12', '13')).toBe('156'); - }); - - it('should: 12 * 0 = 0', function () { - expect(multiply('12', '0')).toBe('0'); - }); - - it('should: 13 * 130 = 1690', function () { - expect(multiply('13', '130')).toBe('1690'); - }); - - it('should: 0.13 * 0.00130 = 0.000169', function () { - expect(multiply('0.13', '0.00130')).toBe('0.000169'); - }); - - it('should: 0.5 * 0.2 = 0.1', function () { - expect(multiply('0.5', '0.2')).toBe('0.1'); - }); - - it('should: 0.05 * 0.02 = 0.001', function () { - expect(multiply('0.05', '0.02')).toBe('0.001'); - }); - - it('should: 0.5 * 0.02 = 0.01', function () { - expect(multiply('0.5', '0.02')).toBe('0.01'); - }); - - - it('should: -0.13 * 0.00130 = -0.000169', function () { - expect(multiply('-0.13', '0.00130')).toBe('-0.000169'); - }); - - it('should: 0.5 * -0.2 = -0.1', function () { - expect(multiply('0.5', '-0.2')).toBe('-0.1'); - }); - - it('should: -0.05 * -0.02 = 0.001', function () { - expect(multiply('-0.05', '-0.02')).toBe('0.001'); - }); - - it('should: -12 * 13 = -156', function () { - expect(multiply('-12', '13')).toBe('-156'); - }); - - it('should: -12 * 0 = 0', function () { - expect(multiply('-12', '0')).toBe('0'); - }); - - it('should: 12 * -0 = 0', function () { - expect(multiply('12', '-0')).toBe('0'); - }); - - - it('should: -12 * -0 = 0', function () { - expect(multiply('-12', '-0')).toBe('0'); - }); - it('should: -0.0000005 * 13 = -0.0000065', function () { - expect(multiply('-0.0000005', '13')).toBe('-0.0000065'); - }); -}) \ No newline at end of file +import { multiply } from "./multiply"; + +describe("multiply", function () { + xit("STRESS TEST - should return correct result", function () { + let count = 100, + err = 0; + while (count-- > 0) { + let dividend = Math.round( + Math.random() * Math.pow(10, Math.floor(Math.random() * 5)) + ); + let divisor = Math.round( + Math.random() * Math.pow(10, Math.floor(Math.random() * 5)) + ); + //if(divisor==0) + //continue; + let jsOut = dividend * divisor; + let myOut = parseFloat(multiply(dividend, divisor)); + if (Math.abs(jsOut - myOut) > 0.001) { + //console.log(`${dividend}/${divisor} = ${jsOut} != ${myOut}`); + err++; + } else { + //console.log(`${dividend}/${divisor} = ${jsOut} == ${myOut}`); + } + } + expect(err).toBe(0); + }); + it("should be defined", function () { + expect(multiply).toBeDefined(); + }); + + it("should: 12 * 13 = 156", function () { + expect(multiply("12", "13")).toBe("156"); + }); + + it("should: 12 * 0 = 0", function () { + expect(multiply("12", "0")).toBe("0"); + }); + + it("should: 13 * 130 = 1690", function () { + expect(multiply("13", "130")).toBe("1690"); + }); + + it("should: 0.13 * 0.00130 = 0.000169", function () { + expect(multiply("0.13", "0.00130")).toBe("0.000169"); + }); + + it("should: 0.5 * 0.2 = 0.1", function () { + expect(multiply("0.5", "0.2")).toBe("0.1"); + }); + + it("should: 0.05 * 0.02 = 0.001", function () { + expect(multiply("0.05", "0.02")).toBe("0.001"); + }); + + it("should: 0.5 * 0.02 = 0.01", function () { + expect(multiply("0.5", "0.02")).toBe("0.01"); + }); + + it("should: -0.13 * 0.00130 = -0.000169", function () { + expect(multiply("-0.13", "0.00130")).toBe("-0.000169"); + }); + + it("should: 0.5 * -0.2 = -0.1", function () { + expect(multiply("0.5", "-0.2")).toBe("-0.1"); + }); + + it("should: -0.05 * -0.02 = 0.001", function () { + expect(multiply("-0.05", "-0.02")).toBe("0.001"); + }); + + it("should: -12 * 13 = -156", function () { + expect(multiply("-12", "13")).toBe("-156"); + }); + + it("should: -12 * 0 = 0", function () { + expect(multiply("-12", "0")).toBe("0"); + }); + + it("should: 12 * -0 = 0", function () { + expect(multiply("12", "-0")).toBe("0"); + }); + + it("should: -12 * -0 = 0", function () { + expect(multiply("-12", "-0")).toBe("0"); + }); + it("should: -0.0000005 * 13 = -0.0000065", function () { + expect(multiply("-0.0000005", "13")).toBe("-0.0000065"); + }); +}); diff --git a/src/round.spec.ts b/src/round.spec.ts index 297216e..a0b3ea4 100644 --- a/src/round.spec.ts +++ b/src/round.spec.ts @@ -1,338 +1,337 @@ -let big = require('./big-decimal'), - RoundingModes = big.RoundingModes, - roundOff = big.round, - floor = big.floor, - ceil = big.ceil; +import big from "./big-decimal"; +import { RoundingModes } from "./roundingModes"; -describe('round', function () { +const ceil = big.ceil; +const floor = big.floor; +const roundOff = big.round; - it('should return integer unchanged', function () { - expect(roundOff(123456)).toBe('123456'); - }); +describe("round", function () { + it("should return integer unchanged", function () { + expect(roundOff(123456)).toBe("123456"); + }); - it('should return float with padded zeros if second argument is non-zero and first is integer', function () { - expect(roundOff(123456, 2)).toBe('123456.00'); - }); - it('should return float with padded zeros if second argument is non-zero and first is floating', function () { - expect(roundOff(12345.6, 2)).toBe('12345.60'); - }) - it('should return float with padded zeros if second argument is non-zero and first is floating', function () { - expect(roundOff('044909.987', 5)).toBe('044909.98700'); - }) - it('should return float rounded appropriately if second argument is non-zero and first is floating', function () { - expect(roundOff('96227983951.7293581', 5)).toBe('96227983951.72936'); - }) - it("should round(87.45, -1) = 90", function () { - expect(roundOff('87.45', -1)).toBe('90'); - }) - it("should round(84.45, -1) = 80", function () { - expect(roundOff('84.45', -1)).toBe('80'); - }) - it("should round(87.45, -2) = 0", function () { - expect(roundOff('87.45', -2)).toBe('0'); - }) - it("should round(87.45, -3) = 0", function () { - expect(roundOff('87.45', -3)).toBe('0'); - }) - it("should round(87, -1) = 90", function () { - expect(roundOff('87', -1)).toBe('90'); - }) - it("should round(82, -1) = 80", function () { - expect(roundOff('82', -1)).toBe('80'); - }) - it("should round('1e-8',10) = 0.00000001", function() { - expect(roundOff(0.00000001,10)).toBe('0.0000000100') - }) - it("should round small negative to zero", function() { - expect(roundOff(-0.00000001,0)).toBe('0'); - }) - it("should round small negative to zero", function() { - expect(roundOff(-0.00000001,2)).toBe('0.00'); - }) - it("should handle small -ve values", function() { - expect(roundOff(-0.1234,2)).toBe('-0.12'); - }) - it("should handle small -ve values", function() { - expect(roundOff(-0.0000000000001234,14)).toBe('-0.00000000000012'); - }) + it("should return float with padded zeros if second argument is non-zero and first is integer", function () { + expect(roundOff(123456, 2)).toBe("123456.00"); + }); + it("should return float with padded zeros if second argument is non-zero and first is floating", function () { + expect(roundOff(12345.6, 2)).toBe("12345.60"); + }); + it("should return float with padded zeros if second argument is non-zero and first is floating", function () { + expect(roundOff("044909.987", 5)).toBe("044909.98700"); + }); + it("should return float rounded appropriately if second argument is non-zero and first is floating", function () { + expect(roundOff("96227983951.7293581", 5)).toBe("96227983951.72936"); + }); + it("should round(87.45, -1) = 90", function () { + expect(roundOff("87.45", -1)).toBe("90"); + }); + it("should round(84.45, -1) = 80", function () { + expect(roundOff("84.45", -1)).toBe("80"); + }); + it("should round(87.45, -2) = 0", function () { + expect(roundOff("87.45", -2)).toBe("0"); + }); + it("should round(87.45, -3) = 0", function () { + expect(roundOff("87.45", -3)).toBe("0"); + }); + it("should round(87, -1) = 90", function () { + expect(roundOff("87", -1)).toBe("90"); + }); + it("should round(82, -1) = 80", function () { + expect(roundOff("82", -1)).toBe("80"); + }); + it("should round('1e-8',10) = 0.00000001", function () { + expect(roundOff(0.00000001, 10)).toBe("0.0000000100"); + }); + it("should round small negative to zero", function () { + expect(roundOff(-0.00000001, 0)).toBe("0"); + }); + it("should round small negative to zero", function () { + expect(roundOff(-0.00000001, 2)).toBe("0.00"); + }); + it("should handle small -ve values", function () { + expect(roundOff(-0.1234, 2)).toBe("-0.12"); + }); + it("should handle small -ve values", function () { + expect(roundOff(-0.0000000000001234, 14)).toBe("-0.00000000000012"); + }); - describe("test rounding mode UP", function () { - it("should round(5.5, 0, UP) = 6", function () { - expect(roundOff('5.5', 0, RoundingModes.UP)).toBe('6'); - }); - it("should round(2.6, 0, UP) = 3", function () { - expect(roundOff('2.6', 0, RoundingModes.UP)).toBe('3'); - }); - it("should round(1.1, 0, UP) = 2", function () { - expect(roundOff('1.1', 0, RoundingModes.UP)).toBe('2'); - }); - it("should round(1.0, 0, UP) = 1", function () { - expect(roundOff('1.0', 0, RoundingModes.UP)).toBe('1'); - }); - it("should round(1, 0, UP) = 1", function () { - expect(roundOff('1', 0, RoundingModes.UP)).toBe('1'); - }); - it("should round(-1.0, 0, UP) = -1", function () { - expect(roundOff('-1.0', 0, RoundingModes.UP)).toBe('-1'); - }); - it("should round(-1.1, 0, UP) = -2", function () { - expect(roundOff('-1.1', 0, RoundingModes.UP)).toBe('-2'); - }); - it("should round(-1.6, 0, UP) = -2", function () { - expect(roundOff('-1.6', 0, RoundingModes.UP)).toBe('-2'); - }); - it("should round(-2.5, 0, UP) = -3", function () { - expect(roundOff('-2.5', 0, RoundingModes.UP)).toBe('-3'); - }); + describe("test rounding mode UP", function () { + it("should round(5.5, 0, UP) = 6", function () { + expect(roundOff("5.5", 0, RoundingModes.UP)).toBe("6"); }); + it("should round(2.6, 0, UP) = 3", function () { + expect(roundOff("2.6", 0, RoundingModes.UP)).toBe("3"); + }); + it("should round(1.1, 0, UP) = 2", function () { + expect(roundOff("1.1", 0, RoundingModes.UP)).toBe("2"); + }); + it("should round(1.0, 0, UP) = 1", function () { + expect(roundOff("1.0", 0, RoundingModes.UP)).toBe("1"); + }); + it("should round(1, 0, UP) = 1", function () { + expect(roundOff("1", 0, RoundingModes.UP)).toBe("1"); + }); + it("should round(-1.0, 0, UP) = -1", function () { + expect(roundOff("-1.0", 0, RoundingModes.UP)).toBe("-1"); + }); + it("should round(-1.1, 0, UP) = -2", function () { + expect(roundOff("-1.1", 0, RoundingModes.UP)).toBe("-2"); + }); + it("should round(-1.6, 0, UP) = -2", function () { + expect(roundOff("-1.6", 0, RoundingModes.UP)).toBe("-2"); + }); + it("should round(-2.5, 0, UP) = -3", function () { + expect(roundOff("-2.5", 0, RoundingModes.UP)).toBe("-3"); + }); + }); - describe("test rounding mode DOWN", function () { - it("should round(5.5, 0, DOWN) = 5", function () { - expect(roundOff('5.5', 0, RoundingModes.DOWN)).toBe('5'); - }); - it("should round(2.6, 0, DOWN) = 2", function () { - expect(roundOff('2.6', 0, RoundingModes.DOWN)).toBe('2'); - }); - it("should round(1.1, 0, DOWN) = 1", function () { - expect(roundOff('1.1', 0, RoundingModes.DOWN)).toBe('1'); - }); - it("should round(1.0, 0, DOWN) = 1", function () { - expect(roundOff('1.0', 0, RoundingModes.DOWN)).toBe('1'); - }); - it("should round(1, 0, DOWN) = 1", function () { - expect(roundOff('1', 0, RoundingModes.DOWN)).toBe('1'); - }); - it("should round(-1.0, 0, DOWN) = -1", function () { - expect(roundOff('-1.0', 0, RoundingModes.DOWN)).toBe('-1'); - }); - it("should round(-1.1, 0, DOWN) = -1", function () { - expect(roundOff('-1.1', 0, RoundingModes.DOWN)).toBe('-1'); - }); - it("should round(-1.6, 0, DOWN) = -1", function () { - expect(roundOff('-1.6', 0, RoundingModes.DOWN)).toBe('-1'); - }); - it("should round(-2.5, 0, DOWN) = -2", function () { - expect(roundOff('-2.5', 0, RoundingModes.DOWN)).toBe('-2'); - }); - }) - - describe("test rounding mode CEILING", function () { - it("should round(5.5, 0, CEILING) = 6", function () { - expect(roundOff('5.5', 0, RoundingModes.CEILING)).toBe('6'); - }); - it("should round(2.6, 0, CEILING) = 3", function () { - expect(roundOff('2.6', 0, RoundingModes.CEILING)).toBe('3'); - }); - it("should round(1.1, 0, CEILING) = 2", function () { - expect(roundOff('1.1', 0, RoundingModes.CEILING)).toBe('2'); - }); - it("should round(1.0, 0, CEILING) = 1", function () { - expect(roundOff('1.0', 0, RoundingModes.CEILING)).toBe('1'); - }); - it("should round(1, 0, CEILING) = 1", function () { - expect(roundOff('1', 0, RoundingModes.CEILING)).toBe('1'); - }); - it("should round(-1.0, 0, CEILING) = -1", function () { - expect(roundOff('-1.0', 0, RoundingModes.CEILING)).toBe('-1'); - }); - it("should round(-1.1, 0, CEILING) = -1", function () { - expect(roundOff('-1.1', 0, RoundingModes.CEILING)).toBe('-1'); - }); - it("should round(-1.6, 0, CEILING) = -1", function () { - expect(roundOff('-1.6', 0, RoundingModes.CEILING)).toBe('-1'); - }); - it("should round(-2.5, 0, CEILING) = -2", function () { - expect(roundOff('-2.5', 0, RoundingModes.CEILING)).toBe('-2'); - }); + describe("test rounding mode DOWN", function () { + it("should round(5.5, 0, DOWN) = 5", function () { + expect(roundOff("5.5", 0, RoundingModes.DOWN)).toBe("5"); + }); + it("should round(2.6, 0, DOWN) = 2", function () { + expect(roundOff("2.6", 0, RoundingModes.DOWN)).toBe("2"); + }); + it("should round(1.1, 0, DOWN) = 1", function () { + expect(roundOff("1.1", 0, RoundingModes.DOWN)).toBe("1"); + }); + it("should round(1.0, 0, DOWN) = 1", function () { + expect(roundOff("1.0", 0, RoundingModes.DOWN)).toBe("1"); + }); + it("should round(1, 0, DOWN) = 1", function () { + expect(roundOff("1", 0, RoundingModes.DOWN)).toBe("1"); + }); + it("should round(-1.0, 0, DOWN) = -1", function () { + expect(roundOff("-1.0", 0, RoundingModes.DOWN)).toBe("-1"); + }); + it("should round(-1.1, 0, DOWN) = -1", function () { + expect(roundOff("-1.1", 0, RoundingModes.DOWN)).toBe("-1"); + }); + it("should round(-1.6, 0, DOWN) = -1", function () { + expect(roundOff("-1.6", 0, RoundingModes.DOWN)).toBe("-1"); }); + it("should round(-2.5, 0, DOWN) = -2", function () { + expect(roundOff("-2.5", 0, RoundingModes.DOWN)).toBe("-2"); + }); + }); - describe("test rounding mode FLOOR", function () { - it("should round(5.5, 0, FLOOR) = 5", function () { - expect(roundOff('5.5', 0, RoundingModes.FLOOR)).toBe('5'); - }); - it("should round(2.6, 0, FLOOR) = 2", function () { - expect(roundOff('2.6', 0, RoundingModes.FLOOR)).toBe('2'); - }); - it("should round(1.1, 0, FLOOR) = 1", function () { - expect(roundOff('1.1', 0, RoundingModes.FLOOR)).toBe('1'); - }); - it("should round(1.0, 0, FLOOR) = 1", function () { - expect(roundOff('1.0', 0, RoundingModes.FLOOR)).toBe('1'); - }); - it("should round(1, 0, FLOOR) = 1", function () { - expect(roundOff('1', 0, RoundingModes.FLOOR)).toBe('1'); - }); - it("should round(-1.0, 0, FLOOR) = -1", function () { - expect(roundOff('-1.0', 0, RoundingModes.FLOOR)).toBe('-1'); - }); - it("should round(-1.1, 0, FLOOR) = -2", function () { - expect(roundOff('-1.1', 0, RoundingModes.FLOOR)).toBe('-2'); - }); - it("should round(-1.6, 0, FLOOR) = -2", function () { - expect(roundOff('-1.6', 0, RoundingModes.FLOOR)).toBe('-2'); - }); - it("should round(-2.5, 0, FLOOR) = -3", function () { - expect(roundOff('-2.5', 0, RoundingModes.FLOOR)).toBe('-3'); - }); + describe("test rounding mode CEILING", function () { + it("should round(5.5, 0, CEILING) = 6", function () { + expect(roundOff("5.5", 0, RoundingModes.CEILING)).toBe("6"); + }); + it("should round(2.6, 0, CEILING) = 3", function () { + expect(roundOff("2.6", 0, RoundingModes.CEILING)).toBe("3"); + }); + it("should round(1.1, 0, CEILING) = 2", function () { + expect(roundOff("1.1", 0, RoundingModes.CEILING)).toBe("2"); + }); + it("should round(1.0, 0, CEILING) = 1", function () { + expect(roundOff("1.0", 0, RoundingModes.CEILING)).toBe("1"); + }); + it("should round(1, 0, CEILING) = 1", function () { + expect(roundOff("1", 0, RoundingModes.CEILING)).toBe("1"); + }); + it("should round(-1.0, 0, CEILING) = -1", function () { + expect(roundOff("-1.0", 0, RoundingModes.CEILING)).toBe("-1"); + }); + it("should round(-1.1, 0, CEILING) = -1", function () { + expect(roundOff("-1.1", 0, RoundingModes.CEILING)).toBe("-1"); + }); + it("should round(-1.6, 0, CEILING) = -1", function () { + expect(roundOff("-1.6", 0, RoundingModes.CEILING)).toBe("-1"); }); + it("should round(-2.5, 0, CEILING) = -2", function () { + expect(roundOff("-2.5", 0, RoundingModes.CEILING)).toBe("-2"); + }); + }); - describe("test rounding mode HALF_UP", function () { - it("should round(5.5, 0, HALF_UP) = 6", function () { - expect(roundOff('5.5', 0, RoundingModes.HALF_UP)).toBe('6'); - }); - it("should round(6.5, 0, HALF_UP) = 7", function () { - expect(roundOff('6.5', 0, RoundingModes.HALF_UP)).toBe('7'); - }); - it("should round(2.6, 0, HALF_UP) = 3", function () { - expect(roundOff('2.6', 0, RoundingModes.HALF_UP)).toBe('3'); - }); - it("should round(1.1, 0, HALF_UP) = 1", function () { - expect(roundOff('1.1', 0, RoundingModes.HALF_UP)).toBe('1'); - }); - it("should round(1.0, 0, HALF_UP) = 1", function () { - expect(roundOff('1.0', 0, RoundingModes.HALF_UP)).toBe('1'); - }); - it("should round(1, 0, HALF_UP) = 1", function () { - expect(roundOff('1', 0, RoundingModes.HALF_UP)).toBe('1'); - }); - it("should round(-1.0, 0, HALF_UP) = -1", function () { - expect(roundOff('-1.0', 0, RoundingModes.HALF_UP)).toBe('-1'); - }); - it("should round(-1.1, 0, HALF_UP) = -1", function () { - expect(roundOff('-1.1', 0, RoundingModes.HALF_UP)).toBe('-1'); - }); - it("should round(-1.6, 0, HALF_UP) = -2", function () { - expect(roundOff('-1.6', 0, RoundingModes.HALF_UP)).toBe('-2'); - }); - it("should round(-2.5, 0, HALF_UP) = -3", function () { - expect(roundOff('-2.5', 0, RoundingModes.HALF_UP)).toBe('-3'); - }); - it("should round(-3.5, 0, HALF_UP) = -4", function () { - expect(roundOff('-3.5', 0, RoundingModes.HALF_UP)).toBe('-4'); - }); - it("should round(-597.998, 2, HALF_UP) = -598.00", function () { - expect(roundOff('-597.998', 2, RoundingModes.HALF_UP)).toBe('-598.00'); - }); + describe("test rounding mode FLOOR", function () { + it("should round(5.5, 0, FLOOR) = 5", function () { + expect(roundOff("5.5", 0, RoundingModes.FLOOR)).toBe("5"); + }); + it("should round(2.6, 0, FLOOR) = 2", function () { + expect(roundOff("2.6", 0, RoundingModes.FLOOR)).toBe("2"); + }); + it("should round(1.1, 0, FLOOR) = 1", function () { + expect(roundOff("1.1", 0, RoundingModes.FLOOR)).toBe("1"); + }); + it("should round(1.0, 0, FLOOR) = 1", function () { + expect(roundOff("1.0", 0, RoundingModes.FLOOR)).toBe("1"); + }); + it("should round(1, 0, FLOOR) = 1", function () { + expect(roundOff("1", 0, RoundingModes.FLOOR)).toBe("1"); + }); + it("should round(-1.0, 0, FLOOR) = -1", function () { + expect(roundOff("-1.0", 0, RoundingModes.FLOOR)).toBe("-1"); + }); + it("should round(-1.1, 0, FLOOR) = -2", function () { + expect(roundOff("-1.1", 0, RoundingModes.FLOOR)).toBe("-2"); + }); + it("should round(-1.6, 0, FLOOR) = -2", function () { + expect(roundOff("-1.6", 0, RoundingModes.FLOOR)).toBe("-2"); }); + it("should round(-2.5, 0, FLOOR) = -3", function () { + expect(roundOff("-2.5", 0, RoundingModes.FLOOR)).toBe("-3"); + }); + }); - describe("test rounding mode HALF_DOWN", function () { - it("should round(5.5, 0, HALF_DOWN) = 5", function () { - expect(roundOff('5.5', 0, RoundingModes.HALF_DOWN)).toBe('5'); - }); - it("should round(6.5, 0, HALF_DOWN) = 6", function () { - expect(roundOff('6.5', 0, RoundingModes.HALF_DOWN)).toBe('6'); - }); - it("should round(2.6, 0, HALF_DOWN) = 3", function () { - expect(roundOff('2.6', 0, RoundingModes.HALF_DOWN)).toBe('3'); - }); - it("should round(1.1, 0, HALF_DOWN) = 1", function () { - expect(roundOff('1.1', 0, RoundingModes.HALF_DOWN)).toBe('1'); - }); - it("should round(1.0, 0, HALF_DOWN) = 1", function () { - expect(roundOff('1.0', 0, RoundingModes.HALF_DOWN)).toBe('1'); - }); - it("should round(1, 0, HALF_DOWN) = 1", function () { - expect(roundOff('1', 0, RoundingModes.HALF_DOWN)).toBe('1'); - }); - it("should round(-1.0, 0, HALF_DOWN) = -1", function () { - expect(roundOff('-1.0', 0, RoundingModes.HALF_DOWN)).toBe('-1'); - }); - it("should round(-1.1, 0, HALF_DOWN) = -1", function () { - expect(roundOff('-1.1', 0, RoundingModes.HALF_DOWN)).toBe('-1'); - }); - it("should round(-1.6, 0, HALF_DOWN) = -2", function () { - expect(roundOff('-1.6', 0, RoundingModes.HALF_DOWN)).toBe('-2'); - }); - it("should round(-2.5, 0, HALF_DOWN) = -2", function () { - expect(roundOff('-2.5', 0, RoundingModes.HALF_DOWN)).toBe('-2'); - }); - it("should round(-3.5, 0, HALF_DOWN) = -3", function () { - expect(roundOff('-3.5', 0, RoundingModes.HALF_DOWN)).toBe('-3'); - }); + describe("test rounding mode HALF_UP", function () { + it("should round(5.5, 0, HALF_UP) = 6", function () { + expect(roundOff("5.5", 0, RoundingModes.HALF_UP)).toBe("6"); + }); + it("should round(6.5, 0, HALF_UP) = 7", function () { + expect(roundOff("6.5", 0, RoundingModes.HALF_UP)).toBe("7"); + }); + it("should round(2.6, 0, HALF_UP) = 3", function () { + expect(roundOff("2.6", 0, RoundingModes.HALF_UP)).toBe("3"); + }); + it("should round(1.1, 0, HALF_UP) = 1", function () { + expect(roundOff("1.1", 0, RoundingModes.HALF_UP)).toBe("1"); + }); + it("should round(1.0, 0, HALF_UP) = 1", function () { + expect(roundOff("1.0", 0, RoundingModes.HALF_UP)).toBe("1"); + }); + it("should round(1, 0, HALF_UP) = 1", function () { + expect(roundOff("1", 0, RoundingModes.HALF_UP)).toBe("1"); + }); + it("should round(-1.0, 0, HALF_UP) = -1", function () { + expect(roundOff("-1.0", 0, RoundingModes.HALF_UP)).toBe("-1"); + }); + it("should round(-1.1, 0, HALF_UP) = -1", function () { + expect(roundOff("-1.1", 0, RoundingModes.HALF_UP)).toBe("-1"); + }); + it("should round(-1.6, 0, HALF_UP) = -2", function () { + expect(roundOff("-1.6", 0, RoundingModes.HALF_UP)).toBe("-2"); }); + it("should round(-2.5, 0, HALF_UP) = -3", function () { + expect(roundOff("-2.5", 0, RoundingModes.HALF_UP)).toBe("-3"); + }); + it("should round(-3.5, 0, HALF_UP) = -4", function () { + expect(roundOff("-3.5", 0, RoundingModes.HALF_UP)).toBe("-4"); + }); + it("should round(-597.998, 2, HALF_UP) = -598.00", function () { + expect(roundOff("-597.998", 2, RoundingModes.HALF_UP)).toBe("-598.00"); + }); + }); - describe("test rounding mode HALF_EVEN - default", function () { - it("should round(5.5, 0) = 6", function () { - expect(roundOff('5.5', 0)).toBe('6'); - }); - it("should round(6.5, 0) = 6", function () { - expect(roundOff('6.5', 0)).toBe('6'); - }); - it("should round(2.6, 0) = 3", function () { - expect(roundOff('2.6', 0)).toBe('3'); - }); - it("should round(1.1, 0) = 1", function () { - expect(roundOff('1.1', 0)).toBe('1'); - }); - it("should round(1.0, 0) = 1", function () { - expect(roundOff('1.0', 0)).toBe('1'); - }); - it("should round(1, 0) = 1", function () { - expect(roundOff('1', 0)).toBe('1'); - }); - it("should round(-1.0, 0) = -1", function () { - expect(roundOff('-1.0', 0)).toBe('-1'); - }); - it("should round(-1.1, 0) = -1", function () { - expect(roundOff('-1.1', 0)).toBe('-1'); - }); - it("should round(-1.6, 0) = -2", function () { - expect(roundOff('-1.6', 0)).toBe('-2'); - }); - it("should round(-2.5, 0) = -2", function () { - expect(roundOff('-2.5', 0)).toBe('-2'); - }); - it("should round(-3.5, 0) = -4", function () { - expect(roundOff('-3.5', 0)).toBe('-4'); - }); + describe("test rounding mode HALF_DOWN", function () { + it("should round(5.5, 0, HALF_DOWN) = 5", function () { + expect(roundOff("5.5", 0, RoundingModes.HALF_DOWN)).toBe("5"); + }); + it("should round(6.5, 0, HALF_DOWN) = 6", function () { + expect(roundOff("6.5", 0, RoundingModes.HALF_DOWN)).toBe("6"); + }); + it("should round(2.6, 0, HALF_DOWN) = 3", function () { + expect(roundOff("2.6", 0, RoundingModes.HALF_DOWN)).toBe("3"); + }); + it("should round(1.1, 0, HALF_DOWN) = 1", function () { + expect(roundOff("1.1", 0, RoundingModes.HALF_DOWN)).toBe("1"); + }); + it("should round(1.0, 0, HALF_DOWN) = 1", function () { + expect(roundOff("1.0", 0, RoundingModes.HALF_DOWN)).toBe("1"); + }); + it("should round(1, 0, HALF_DOWN) = 1", function () { + expect(roundOff("1", 0, RoundingModes.HALF_DOWN)).toBe("1"); }); + it("should round(-1.0, 0, HALF_DOWN) = -1", function () { + expect(roundOff("-1.0", 0, RoundingModes.HALF_DOWN)).toBe("-1"); + }); + it("should round(-1.1, 0, HALF_DOWN) = -1", function () { + expect(roundOff("-1.1", 0, RoundingModes.HALF_DOWN)).toBe("-1"); + }); + it("should round(-1.6, 0, HALF_DOWN) = -2", function () { + expect(roundOff("-1.6", 0, RoundingModes.HALF_DOWN)).toBe("-2"); + }); + it("should round(-2.5, 0, HALF_DOWN) = -2", function () { + expect(roundOff("-2.5", 0, RoundingModes.HALF_DOWN)).toBe("-2"); + }); + it("should round(-3.5, 0, HALF_DOWN) = -3", function () { + expect(roundOff("-3.5", 0, RoundingModes.HALF_DOWN)).toBe("-3"); + }); + }); + describe("test rounding mode HALF_EVEN - default", function () { + it("should round(5.5, 0) = 6", function () { + expect(roundOff("5.5", 0)).toBe("6"); + }); + it("should round(6.5, 0) = 6", function () { + expect(roundOff("6.5", 0)).toBe("6"); + }); + it("should round(2.6, 0) = 3", function () { + expect(roundOff("2.6", 0)).toBe("3"); + }); + it("should round(1.1, 0) = 1", function () { + expect(roundOff("1.1", 0)).toBe("1"); + }); + it("should round(1.0, 0) = 1", function () { + expect(roundOff("1.0", 0)).toBe("1"); + }); + it("should round(1, 0) = 1", function () { + expect(roundOff("1", 0)).toBe("1"); + }); + it("should round(-1.0, 0) = -1", function () { + expect(roundOff("-1.0", 0)).toBe("-1"); + }); + it("should round(-1.1, 0) = -1", function () { + expect(roundOff("-1.1", 0)).toBe("-1"); + }); + it("should round(-1.6, 0) = -2", function () { + expect(roundOff("-1.6", 0)).toBe("-2"); + }); + it("should round(-2.5, 0) = -2", function () { + expect(roundOff("-2.5", 0)).toBe("-2"); + }); + it("should round(-3.5, 0) = -4", function () { + expect(roundOff("-3.5", 0)).toBe("-4"); + }); + }); - it("should ceil(0) = 0", function () { - expect(ceil(0)).toBe('0'); - }) - it("should floor(0) = 0", function () { - expect(floor(0)).toBe('0'); - }) + it("should ceil(0) = 0", function () { + expect(ceil(0)).toBe("0"); + }); + it("should floor(0) = 0", function () { + expect(floor(0)).toBe("0"); + }); - it("should ceil(0.00001341) = 1", function () { - expect(ceil('0.00001341')).toBe('1'); - }) - it("should floor('0.00001341') = 0", function () { - expect(floor('0.00001341')).toBe('0'); - }) - it("should floor(0.00001341) = 0", function () { - expect(floor(0.00001341)).toBe('0'); - }) + it("should ceil(0.00001341) = 1", function () { + expect(ceil("0.00001341")).toBe("1"); + }); + it("should floor('0.00001341') = 0", function () { + expect(floor("0.00001341")).toBe("0"); + }); + it("should floor(0.00001341) = 0", function () { + expect(floor(0.00001341)).toBe("0"); + }); - it("should ceil(13) = 13", function () { - expect(ceil(13)).toBe('13'); - }) - it("should floor(13) = 13", function () { - expect(floor(13)).toBe('13'); - }) - it("should ceil(13.3) = 14", function () { - expect(ceil(13.3)).toBe('14'); - }) - it("should floor(13.3) = 13", function () { - expect(floor(13.3)).toBe('13'); - }) - it("should ceil(13.8) = 14", function () { - expect(ceil(13.8)).toBe('14'); - }) - it("should floor(13.8) = 13", function () { - expect(floor(13.8)).toBe('13'); - }) - it("should ceil(-13.3) = -13", function () { - expect(ceil(-13.3)).toBe('-13'); - }) - it("should floor(-13.3) = -14", function () { - expect(floor(-13.3)).toBe('-14'); - }) - it("should ceil(-13.8) = -13", function () { - expect(ceil(-13.8)).toBe('-13'); - }) - it("should floor(-13.8) = -14", function () { - expect(floor(-13.8)).toBe('-14'); - }) -}) \ No newline at end of file + it("should ceil(13) = 13", function () { + expect(ceil(13)).toBe("13"); + }); + it("should floor(13) = 13", function () { + expect(floor(13)).toBe("13"); + }); + it("should ceil(13.3) = 14", function () { + expect(ceil(13.3)).toBe("14"); + }); + it("should floor(13.3) = 13", function () { + expect(floor(13.3)).toBe("13"); + }); + it("should ceil(13.8) = 14", function () { + expect(ceil(13.8)).toBe("14"); + }); + it("should floor(13.8) = 13", function () { + expect(floor(13.8)).toBe("13"); + }); + it("should ceil(-13.3) = -13", function () { + expect(ceil(-13.3)).toBe("-13"); + }); + it("should floor(-13.3) = -14", function () { + expect(floor(-13.3)).toBe("-14"); + }); + it("should ceil(-13.8) = -13", function () { + expect(ceil(-13.8)).toBe("-13"); + }); + it("should floor(-13.8) = -14", function () { + expect(floor(-13.8)).toBe("-14"); + }); +}); diff --git a/src/subtract.spec.ts b/src/subtract.spec.ts index 950cea2..3ae0fc1 100644 --- a/src/subtract.spec.ts +++ b/src/subtract.spec.ts @@ -1,31 +1,30 @@ -var subtract = require('./big-decimal').subtract; +import { subtract } from "./subtract"; -describe('subtract', function () { - it('should be defined', function () { - expect(subtract).toBeDefined(); - }); +describe("subtract", function () { + it("should be defined", function () { + expect(subtract).toBeDefined(); + }); - it('should: 12-13 = -1', function () { - expect(subtract('12', '13')).toBe('-1'); - }); + it("should: 12-13 = -1", function () { + expect(subtract("12", "13")).toBe("-1"); + }); - it('should: 12.67-13 = -0.33', function () { - expect(subtract('12.67', '13')).toBe('-0.33'); - }); + it("should: 12.67-13 = -0.33", function () { + expect(subtract("12.67", "13")).toBe("-0.33"); + }); - it('should: 12.67-.13 = 12.54', function () { - expect(subtract('12.67', '.13')).toBe('12.54'); - }); + it("should: 12.67-.13 = 12.54", function () { + expect(subtract("12.67", ".13")).toBe("12.54"); + }); - it('should: 100-12 = 88', function () { - expect(subtract('100', '12')).toBe('88'); - }); + it("should: 100-12 = 88", function () { + expect(subtract("100", "12")).toBe("88"); + }); - it('should: 126.7-13 = 113.7', function () { - expect(subtract('126.7', '13')).toBe('113.7'); - }); - it('should: 12.67-130.7 = -118.03', function () { - expect(subtract('12.67', '130.7')).toBe('-118.03'); - }); - -}) \ No newline at end of file + it("should: 126.7-13 = 113.7", function () { + expect(subtract("126.7", "13")).toBe("113.7"); + }); + it("should: 12.67-130.7 = -118.03", function () { + expect(subtract("12.67", "130.7")).toBe("-118.03"); + }); +});