Skip to content

Commit

Permalink
fix: 2e != e2
Browse files Browse the repository at this point in the history
This is a supplement to the last commit.
  • Loading branch information
NriotHrreion committed Aug 13, 2024
1 parent 794823a commit a98c997
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/compiler/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default class Compiler {
} else {
this.pushVariable(symbol);

if(Is.variable(symbol) && Is.number(this.raw[i + 1], this.isProgrammingMode)) {
if(Is.pureNumber(this.raw[i + 1])) {
this.pushOperator(Operator.MUL);
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/compiler/Is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ export default class Is {
return number.indexOf(symbol) > -1;
}
}

public static pureNumber(symbol: string): boolean {
const number = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "."];
if(!symbol) return false;

return number.indexOf(symbol) > -1;
}

public static operator(symbol: string): boolean {
const operator = [
Expand Down
17 changes: 10 additions & 7 deletions src/test/compiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,20 @@ describe("Compiler tests", () => {
const f9 = "( 2 e ) \\pi";
expect(calculate(f9)).toBe("17.07946844534713");

const f10 = "( e \\pi ) 2";
expect(calculate(f10)).toBe("17.07946844534714");
const f10 = "( e 2 ) \\pi";
expect(calculate(f10)).toBe("17.07946844534713");

const f11 = "2 ^2 e";
expect(calculate(f11)).toBe("10.87312731383618");
const f11 = "( e \\pi ) 2";
expect(calculate(f11)).toBe("17.07946844534714");

const f12 = "3 1 b";
expect(calculate(f12, variables)).toBe("403");
const f12 = "2 ^2 e";
expect(calculate(f12)).toBe("10.87312731383618");

const f13 = "b 3 1";
const f13 = "3 1 b";
expect(calculate(f13, variables)).toBe("403");

const f14 = "b 3 1";
expect(calculate(f14, variables)).toBe("403");
});

test("Integrated Calculations", () => {
Expand Down

1 comment on commit a98c997

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.