Skip to content

Commit

Permalink
Merge pull request #67 from pie-framework/fix/PD-4410
Browse files Browse the repository at this point in the history
fix(trailing-zeros): Skip LaTeX-to-AST and AST-to-MathJS conversions for numeric equality checks PD-4410
  • Loading branch information
CarlaCostea authored Dec 12, 2024
2 parents 86ea83b + 4393169 commit 359b9fe
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
export default {
mode: "symbolic",
tests: [
{
target: "12.35",
eq: [
"12.350", "12.350000",
],
},
{
target: "10.2",
eq: [
"10.20",
],
},
{
target: "5.05",
eq: [
"5.050",
],
},
{
target: "5.4",
eq: [
"5.40000",
],
},
{
target: "3.3",
eq: [
"3.300",
],
},
{
target: "0.004",
eq: [
"0.0040",
],
},
{
target: "5.7",
eq: [
"5.70",
],
},
{
target: "23.598",
eq: [
"23.5980",
],
},
{
target: "0.00278",
eq: [
"0.002780",
],
},
{
target: "32.279",
eq: [
"32.2790",
],
},
{
target: "0.65",
eq: [
"0.650",
],
},
{
target: "45.3",
eq: [
"45.300",
],
},
],
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
export default {
mode: "symbolic",
tests: [
{
target: "5.5",
eq: [
"5.50", "5.50000",
],
},
{
target: "15",
eq: [
"15.000",
],
},
{
target: "\\frac{5}{4}",
eq: [
"1.25000",
],
},
{
target: "45",
eq: [
"45.00",
],
},
{
target: "-45.3",
eq: [
"-45.300",
],
},
{
target: "11.25",
eq: [
"11.250", "11.2500",
],
},
{
target: "11.25x",
eq: [
"11.2500x",
],
},
{
target: "0.75",
eq: [
"0.750",
],
},
{
target: "16",
eq: [
"16.00",
],
},
{
target: "1.30",
eq: [
"1.300",
],
},
{
target: "8",
eq: [
"8.0",
],
},
],
};

12 changes: 12 additions & 0 deletions src/latex-equal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const lta = new LatexToAst();
const atm = new AstToMathJs();

export const latexEqual = (a: Latex, b: Latex, opts: Opts) => {
const isNumeric = (str: string): boolean => /^-?\d+(\.\d+)?$/.test(str);

if (!a || !b) {
return false;
}
Expand All @@ -25,6 +27,16 @@ export const latexEqual = (a: Latex, b: Latex, opts: Opts) => {
return true;
}

if (opts.mode === "symbolic" && isNumeric(a) && isNumeric(b)) {
const numA = parseFloat(a);
const numB = parseFloat(b);

if (numA === numB) {

return true;
}
}

const al = lta.convert(a);
const bl = lta.convert(b);

Expand Down

0 comments on commit 359b9fe

Please sign in to comment.