-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathmain.js
More file actions
34 lines (31 loc) · 801 Bytes
/
main.js
File metadata and controls
34 lines (31 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Calculator {
exp(x) {
if (!Number.isFinite(x)) {
throw Error('unsupported operand type');
}
const result = Math.exp(x);
if (result === Infinity) {
throw Error('overflow');
}
return result;
}
log(x) {
if (!Number.isFinite(x)) {
throw Error('unsupported operand type');
}
const result = Math.log(x);
if (result === -Infinity) {
throw Error('math domain error (1)');
}
if (Number.isNaN(result)) {
throw Error('math domain error (2)');
}
return result;
}
}
// const calculator = new Calculator();
// console.log(calculator.exp(87));
// console.log(calculator.log(48763));
module.exports = {
Calculator
};