-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.py
138 lines (117 loc) · 3.33 KB
/
calculator.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from errors import Errors
import math
class Calculator:
"""
The main class for our computation logics.
"""
def __init__(self, name):
"""
The constructor method for the calculator class.
:param name: str
The name of this instance of the calculator.
"""
self.name = name
def compute_add(self, op1, op2):
"""
This function return sum of its inputs
:param op1: float
The first operand
:param op2: float
The second operand
:return : float
return the sum of two operands
"""
return op1 + op2
def compute_sub(self, op1, op2):
"""
The computer method for subtract operation.
:param op1: float
The first operand
:param op2: float
The second operand
:return : float
return the subtraction of two operands
"""
return op1 - op2
def compute_div(self, op1, op2):
"""
The computer method for divition operation.
:param op1: float
The first operand
:param op2: float
The second operand
:return : float
return the division of two operands
"""
if op2 == 0:
return Errors.DIV_BY_ZERO
return op1 / op2
def compute_mul(self, op1, op2):
"""
The computer method for multiplication operation.
:param op1: float
The first operand
:param op2: float
The second operand
:return : float
return the multiplication of two operands
"""
return op1 * op2
def compute_sqrt(self, op1):
"""
The computer method for multiplication operation.
:param op1: float
The first operand
:return : float
return the square root of the input
"""
if op1 < 0:
return Errors.NEGATIVE_SQRT
return math.sqrt(op1)
def compute_pow(self, op1, op2):
"""
The computer method for power operation.
:param op1: float
The first operand
:param op2: float
The second operand
:return : float
return the power of first operands into second operand
"""
return op1 ** op2
def compute_sin(self, op1):
"""
The computer method for Sin operation.
:param op1: float
The first operand
:return : float
return the Sin of first operand
"""
return math.sin(op1)
def compute_cos(self, op1):
"""
The computer method for Cos operation.
:param op1: float
The first operand
:return : float
return the Cos of first operand
"""
return math.cos(op1)
def compute_tan(self, op1):
"""
The computer method for Tan operation.
:param op1: float
The first operand
:return : float
return the Tan of first operand
"""
return math.tan(op1)
def compute_cot(self, op1):
"""
The computer method for Cot operation.
:param op1: float
The first operand
:return : float
return the Cot of first operand
"""
return 1 / math.tan(op1)