Skip to content

Commit 0ed8578

Browse files
committed
feat(calculator.ts): add inverse method
1 parent f5d30cb commit 0ed8578

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/Calculator.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,9 @@ export default class Calculator {
7171
this.current = Math.tan(this.current);
7272
return this;
7373
}
74+
75+
public inverse() {
76+
this.current = div(1, this.current);
77+
return this;
78+
}
7479
}

tests/Calculator.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ describe("Calculator", () => {
2222
it("can cos", () => expect(calculator.cos().value()).equal(1));
2323
// prettier-ignore
2424
it("can tan", () => expect(calculator.clear().tan().value()).equal(0));
25+
// prettier-ignore
26+
it("can invert", () => expect(calculator.clear().add(2).inverse().value()).equal(1 / 2));
2527
});

0 commit comments

Comments
 (0)