@libs.calculator.Calculator
@libs/calculator.Calculator
Calculator class for basic arithmetic operations.
• new Calculator(value?
): Calculator
Creates a new calculator.
Name | Type | Default value | Description |
---|---|---|---|
value |
number |
0 |
The initial value of the calculator. |
Example
const calc = new Calculator();
console.log(calc.value); // 0
Example
const calc = new Calculator(1);
console.log(calc.value); // 1
• value: number
The current value of the calculator.
▸ add(x
): void
Adds a number to the calculator.
@libs/arithmetic!Addition~add is used to add the number.
Name | Type | Description |
---|---|---|
x |
number |
The number to add. |
void
Example
const calc = new Calculator();
calc.add(1);
console.log(calc.value); // 1
▸ div(x
): void
Divides the calculator by a number.
@libs/arithmetic!Division~div is used to divide the calculator.
Name | Type | Description |
---|---|---|
x |
number |
The number to divide by. |
void
Example
const calc = new Calculator();
calc.div(2);
console.log(calc.value); // 0
Example
const calc = new Calculator(1);
calc.div(2);
console.log(calc.value); // 0.5
▸ mul(x
): void
Multiplies the calculator by a number.
@libs/arithmetic!Multiplication~mul is used to multiply the calculator.
Name | Type | Description |
---|---|---|
x |
number |
The number to multiply by. |
void
Example
const calc = new Calculator();
calc.mul(2);
console.log(calc.value); // 0
Example
const calc = new Calculator(1);
calc.mul(2);
console.log(calc.value); // 2
▸ sub(x
): void
Subtracts a number from the calculator.
@libs/arithmetic!Subtraction~sub is used to subtract the number.
Name | Type | Description |
---|---|---|
x |
number |
The number to subtract. |
void
Example
const calc = new Calculator();
calc.sub(1);
console.log(calc.value); // -1
▸ test(input
): void
Tests the calculator.
Name | Type | Description |
---|---|---|
input |
TestInput |
The input for the test. |
void
Example
const calc = new Calculator();
calc.test({ value: 1 });
If you want single repo example, please go to https://github.com/rhea-so/tsdoc-github-wiki-example