Skip to content

Commit

Permalink
fix: return with to locale string
Browse files Browse the repository at this point in the history
publish new version 1.1.8
  • Loading branch information
gabriel-logan committed Apr 4, 2024
1 parent 9e0ef1c commit 2061509
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
56 changes: 43 additions & 13 deletions packages/typescript/dist/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
};
}
}
Expand All @@ -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"),
};
}
}
Expand All @@ -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"),
};
}
}
Expand All @@ -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,
})),
};
}
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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,
})),
};
}
}
Expand Down Expand Up @@ -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"),
};
}
}
Expand All @@ -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"),
};
}
}
Expand All @@ -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"),
};
}
}
Expand All @@ -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,
})),
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
87 changes: 75 additions & 12 deletions packages/typescript/src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
};
}
}
Expand All @@ -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]) {
Expand All @@ -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 {
Expand All @@ -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,
},
)}`,
};
}
}
Expand Down Expand Up @@ -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);

Expand All @@ -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,
})}`,
};
}

Expand All @@ -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);
Expand Down Expand Up @@ -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,
})}`,
};
}
}
Expand Down Expand Up @@ -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`,
};
}
}
Expand All @@ -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) {
Expand All @@ -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 {
Expand All @@ -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,
},
)}`,
};
}
}
Expand Down
13 changes: 8 additions & 5 deletions packages/typescript/types/Main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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;
} | {
Expand Down Expand Up @@ -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
Expand All @@ -149,23 +149,26 @@ 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
* @param b
* @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)
* b = coefficient of (x^2)
* 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;
}

0 comments on commit 2061509

Please sign in to comment.