diff --git a/packages/typescript/README.md b/packages/typescript/README.md index 5bb2300..3e43551 100644 --- a/packages/typescript/README.md +++ b/packages/typescript/README.md @@ -75,4 +75,4 @@ console.log(equationRoots.value); // Returns an array console.log(equationRoots.msg); // Returns a descriptive message ``` -Made by Gabriel Lima. +Made by Gabriel Logan. diff --git a/packages/typescript/dist/Main.js b/packages/typescript/dist/Main.js index 948e4a1..eda5f10 100644 --- a/packages/typescript/dist/Main.js +++ b/packages/typescript/dist/Main.js @@ -205,7 +205,9 @@ var Calculator = (function (_super) { else { return { value: [0, answer1], - msg: "The value of X1 = 0 and X2 is equal to: ".concat(answer1, " | X2 = X3"), + msg: "The value of X1 = 0 and X2 is equal to: ".concat(answer1.toLocaleString(locale, { + maximumFractionDigits: 20, + }), " | X2 = X3"), }; } } @@ -223,7 +225,9 @@ var Calculator = (function (_super) { else { return { value: [roots[0], answer2], - msg: "The value of X1 = ".concat(roots[0], " and X2 = ").concat(answer2, " | X1 = X3"), + msg: "The value of X1 = ".concat(roots[0], " and X2 = ").concat(answer2.toLocaleString(locale, { + maximumFractionDigits: 20, + }), " | X1 = X3"), }; } } @@ -239,7 +243,9 @@ var Calculator = (function (_super) { else { return { value: [roots[0], answer1], - msg: "The value of X1 = ".concat(roots[0], " and X2 it's the same as: ").concat(answer1, " | X1 = X3"), + msg: "The value of X1 = ".concat(roots[0], " and X2 it's the same as: ").concat(answer1.toLocaleString(locale, { + maximumFractionDigits: 20, + }), " | X1 = X3"), }; } } @@ -257,7 +263,11 @@ var Calculator = (function (_super) { else { return { value: [roots[0], answer1, answer2], - msg: "The value of X1 = ".concat(roots[0], ", X2 it's the same as: ").concat(answer1, " and The value of X3 it's the same as: ").concat(answer2), + msg: "The value of X1 = ".concat(roots[0], ", X2 it's the same as: ").concat(answer1.toLocaleString(locale, { + maximumFractionDigits: 20, + }), " and The value of X3 it's the same as: ").concat(answer2.toLocaleString(locale, { + maximumFractionDigits: 20, + })), }; } } @@ -407,7 +417,8 @@ var Calculator = (function (_super) { var timestamp = Date.now(); return min + (timestamp % (max - min + 1)); }; - Calculator.prototype.linearEquation = function (a, b) { + Calculator.prototype.linearEquation = function (a, b, locale) { + if (locale === void 0) { locale = "en-US"; } var numberA = Number(a); var numberB = Number(b); if (numberA === 0) { @@ -419,10 +430,13 @@ var Calculator = (function (_super) { var root = -numberB / numberA; return { value: root, - msg: "The value of x is the same as: ".concat(root), + msg: "The value of x is the same as: ".concat(root.toLocaleString(locale, { + maximumFractionDigits: 20, + })), }; }; - Calculator.prototype.quadraticEquation = function (a, b, c) { + Calculator.prototype.quadraticEquation = function (a, b, c, locale) { + if (locale === void 0) { locale = "en-US"; } var numberA = Number(a); var numberB = Number(b); var numberC = Number(c); @@ -445,13 +459,19 @@ var Calculator = (function (_super) { if (root1 === root2) { return { value: [root1], - msg: "It has only 1 real root in X = ".concat(root1), + msg: "It has only 1 real root in X = ".concat(root1.toLocaleString(locale, { + maximumFractionDigits: 20, + })), }; } else { return { value: [root1, root2], - msg: "The value of X1 = ".concat(root1, " and X2 = ").concat(root2), + msg: "The value of X1 = ".concat(root1.toLocaleString(locale, { + maximumFractionDigits: 20, + }), " and X2 = ").concat(root2.toLocaleString(locale, { + maximumFractionDigits: 20, + })), }; } } @@ -499,7 +519,9 @@ var Calculator = (function (_super) { else { return { value: [0, answer1], - msg: "The value of X1 = 0 and X2 is equal to: ".concat(answer1, " | X2 = X3"), + msg: "The value of X1 = 0 and X2 is equal to: ".concat(answer1.toLocaleString(locale, { + maximumFractionDigits: 20, + }), " | X2 = X3"), }; } } @@ -517,7 +539,9 @@ var Calculator = (function (_super) { else { return { value: [0, answer2], - msg: "The value of X1 = 0 and X2 = ".concat(answer2, " | X1 = X3"), + msg: "The value of X1 = 0 and X2 = ".concat(answer2.toLocaleString(locale, { + maximumFractionDigits: 20, + }), " | X1 = X3"), }; } } @@ -533,7 +557,9 @@ var Calculator = (function (_super) { else { return { value: [0, answer1], - msg: "The value of X1 = 0 and X2 is equal to: ".concat(answer1, " | X1 = X3"), + msg: "The value of X1 = 0 and X2 is equal to: ".concat(answer1.toLocaleString(locale, { + maximumFractionDigits: 20, + }), " | X1 = X3"), }; } } @@ -551,7 +577,11 @@ var Calculator = (function (_super) { else { return { value: [0, answer1, answer2], - msg: "The value of X1 = 0, X2 it's the same as: ".concat(answer1, " and The value of X3 it's the same as: ").concat(answer2), + msg: "The value of X1 = 0, X2 it's the same as: ".concat(answer1.toLocaleString(locale, { + maximumFractionDigits: 20, + }), " and The value of X3 it's the same as: ").concat(answer2.toLocaleString(locale, { + maximumFractionDigits: 20, + })), }; } } diff --git a/packages/typescript/package.json b/packages/typescript/package.json index a05d207..1aa3b78 100644 --- a/packages/typescript/package.json +++ b/packages/typescript/package.json @@ -1,6 +1,6 @@ { "name": "loganmatic", - "version": "1.1.7", + "version": "1.1.8", "description": "Math library with some functions to facilitate calculations", "publisher": "Gabriel Logan", "main": "./dist/loganmatic.js", diff --git a/packages/typescript/src/Main.ts b/packages/typescript/src/Main.ts index 9ef8825..4529076 100644 --- a/packages/typescript/src/Main.ts +++ b/packages/typescript/src/Main.ts @@ -282,7 +282,12 @@ export default class Calculator extends ArithmeticOp { } else { return { value: [0, answer1], - msg: `The value of X1 = 0 and X2 is equal to: ${answer1} | X2 = X3`, + msg: `The value of X1 = 0 and X2 is equal to: ${answer1.toLocaleString( + locale, + { + maximumFractionDigits: 20, + }, + )} | X2 = X3`, }; } } @@ -301,7 +306,12 @@ export default class Calculator extends ArithmeticOp { } else { return { value: [roots[0], answer2], - msg: `The value of X1 = ${roots[0]} and X2 = ${answer2} | X1 = X3`, + msg: `The value of X1 = ${roots[0]} and X2 = ${answer2.toLocaleString( + locale, + { + maximumFractionDigits: 20, + }, + )} | X1 = X3`, }; } } else if (answer2 == roots[0]) { @@ -318,7 +328,12 @@ export default class Calculator extends ArithmeticOp { } else { return { value: [roots[0], answer1], - msg: `The value of X1 = ${roots[0]} and X2 it's the same as: ${answer1} | X1 = X3`, + msg: `The value of X1 = ${roots[0]} and X2 it's the same as: ${answer1.toLocaleString( + locale, + { + maximumFractionDigits: 20, + }, + )} | X1 = X3`, }; } } else { @@ -340,7 +355,17 @@ export default class Calculator extends ArithmeticOp { } else { return { value: [roots[0], answer1, answer2], - msg: `The value of X1 = ${roots[0]}, X2 it's the same as: ${answer1} and The value of X3 it's the same as: ${answer2}`, + msg: `The value of X1 = ${roots[0]}, X2 it's the same as: ${answer1.toLocaleString( + locale, + { + maximumFractionDigits: 20, + }, + )} and The value of X3 it's the same as: ${answer2.toLocaleString( + locale, + { + maximumFractionDigits: 20, + }, + )}`, }; } } @@ -597,7 +622,11 @@ export default class Calculator extends ArithmeticOp { * Mathematics.linearEquation(2, 3) * @return - The result = x = -3/2 = -1.5 */ - linearEquation(a: number, b: number): ReturnTypesForEquation { + linearEquation( + a: number, + b: number, + locale = "en-US", + ): ReturnTypesForEquation { const numberA = Number(a); const numberB = Number(b); @@ -611,7 +640,9 @@ export default class Calculator extends ArithmeticOp { const root = -numberB / numberA; return { value: root, - msg: `The value of x is the same as: ${root}`, + msg: `The value of x is the same as: ${root.toLocaleString(locale, { + maximumFractionDigits: 20, + })}`, }; } @@ -637,6 +668,7 @@ export default class Calculator extends ArithmeticOp { a: number, b: number, c: number, + locale = "en-US", ): ReturnTypesForEquation2upDegree { const numberA = Number(a); const numberB = Number(b); @@ -664,12 +696,18 @@ export default class Calculator extends ArithmeticOp { if (root1 === root2) { return { value: [root1], - msg: `It has only 1 real root in X = ${root1}`, + msg: `It has only 1 real root in X = ${root1.toLocaleString(locale, { + maximumFractionDigits: 20, + })}`, }; } else { return { value: [root1, root2], - msg: `The value of X1 = ${root1} and X2 = ${root2}`, + msg: `The value of X1 = ${root1.toLocaleString(locale, { + maximumFractionDigits: 20, + })} and X2 = ${root2.toLocaleString(locale, { + maximumFractionDigits: 20, + })}`, }; } } @@ -742,7 +780,12 @@ export default class Calculator extends ArithmeticOp { } else { return { value: [0, answer1], - msg: `The value of X1 = 0 and X2 is equal to: ${answer1} | X2 = X3`, + msg: `The value of X1 = 0 and X2 is equal to: ${answer1.toLocaleString( + locale, + { + maximumFractionDigits: 20, + }, + )} | X2 = X3`, }; } } @@ -761,7 +804,12 @@ export default class Calculator extends ArithmeticOp { } else { return { value: [0, answer2], - msg: `The value of X1 = 0 and X2 = ${answer2} | X1 = X3`, + msg: `The value of X1 = 0 and X2 = ${answer2.toLocaleString( + locale, + { + maximumFractionDigits: 20, + }, + )} | X1 = X3`, }; } } else if (answer2 == x1) { @@ -778,7 +826,12 @@ export default class Calculator extends ArithmeticOp { } else { return { value: [0, answer1], - msg: `The value of X1 = 0 and X2 is equal to: ${answer1} | X1 = X3`, + msg: `The value of X1 = 0 and X2 is equal to: ${answer1.toLocaleString( + locale, + { + maximumFractionDigits: 20, + }, + )} | X1 = X3`, }; } } else { @@ -800,7 +853,17 @@ export default class Calculator extends ArithmeticOp { } else { return { value: [0, answer1, answer2], - msg: `The value of X1 = 0, X2 it's the same as: ${answer1} and The value of X3 it's the same as: ${answer2}`, + msg: `The value of X1 = 0, X2 it's the same as: ${answer1.toLocaleString( + locale, + { + maximumFractionDigits: 20, + }, + )} and The value of X3 it's the same as: ${answer2.toLocaleString( + locale, + { + maximumFractionDigits: 20, + }, + )}`, }; } } diff --git a/packages/typescript/types/Main.d.ts b/packages/typescript/types/Main.d.ts index f41630c..1af1618 100644 --- a/packages/typescript/types/Main.d.ts +++ b/packages/typescript/types/Main.d.ts @@ -26,7 +26,7 @@ export default class Calculator extends ArithmeticOp { * @param valueD * @param checkedYes */ - protected newtonMethod(valueA: number, valueB: number, valueC: number, valueD: number, checkedYes: boolean): { + protected newtonMethod(valueA: number, valueB: number, valueC: number, valueD: number, checkedYes: boolean, locale: string): { value: number[]; msg: string; }; @@ -38,7 +38,7 @@ export default class Calculator extends ArithmeticOp { * @param roots * @param checkedYes */ - protected ruffiniDevice(valueA: number, valueB: number, valueC: number, valueD: number, roots: number[], checkedYes: boolean): { + protected ruffiniDevice(valueA: number, valueB: number, valueC: number, valueD: number, roots: number[], checkedYes: boolean, locale: string): { value: number[]; msg: string; } | { @@ -130,7 +130,7 @@ export default class Calculator extends ArithmeticOp { * Mathematics.linearEquation(2, 3) * @return - The result = x = -3/2 = -1.5 */ - linearEquation(a: number, b: number): ReturnTypesForEquation; + linearEquation(a: number, b: number, locale?: string): ReturnTypesForEquation; /** * Method to calculate the root of a first-degree polynomial * @param a @@ -149,7 +149,7 @@ export default class Calculator extends ArithmeticOp { * Mathematics.quadraticEquation(1, 2, -3) * @return - The result = [1, -3] */ - quadraticEquation(a: number, b: number, c: number): ReturnTypesForEquation2upDegree; + quadraticEquation(a: number, b: number, c: number, locale?: string): ReturnTypesForEquation2upDegree; /** * Method to calculate the root of a third-degree polynomial * @param a @@ -157,6 +157,7 @@ export default class Calculator extends ArithmeticOp { * @param c * @param d * @param [approximate=false] + * @param [locale="en-US"] // The locale to format the number * @example Mathematics.cubicEquation(a, b, c, d) * * a = coefficient of (x^3) @@ -164,8 +165,10 @@ export default class Calculator extends ArithmeticOp { * c = coefficient of (x) * d = constant term * + * EX: a(x^3) + b(x^2) + c(x) + d = 0 + * * Mathematics.cubicEquation(1, 2, -3, 5) * @return - It has only 1 real root in X = -3.344171229347796 */ - cubicEquation(a?: number, b?: number, c?: number, d?: number, approximate?: boolean): ReturnTypesForEquation2upDegree; + cubicEquation(a?: number, b?: number, c?: number, d?: number, approximate?: boolean, locale?: string): ReturnTypesForEquation2upDegree; }