-
Notifications
You must be signed in to change notification settings - Fork 0
/
multi_var_class.py
90 lines (77 loc) · 2.2 KB
/
multi_var_class.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
class multi_var():
def __init__(self, *simp_vars, **vars):
if 'si' in vars.keys():
self.si = vars['si']
else:
self.si=None
if 'sgs' in vars.keys():
self.sgs = vars['sgs']
else:
self.sgs = None
def __add__(self, other):
if isinstance(other, multi_var):
sgs_val = self.sgs+ other.sgs
si_val = self.si + other.si
return multi_var(si=si_val, sgs=sgs_val)
elif isinstance(other, (float, int)):
sgs_val = self.sgs + other
si_val = self.si + other
else:
sgs_val = self.sgs
si_val = self.si
return multi_var(si=si_val, sgs=sgs_val)
def __radd__(self, other):
return self.__add__(other)
def __rmul__(self, other):
return self.__mul__(other)
def __rtruediv__(self, other):
if isinstance(other, multi_var):
sgs_val = other.sgs / self.sgs
si_val = other.si / self.si
return multi_var(si=si_val, sgs=sgs_val)
elif isinstance(other, (float, int)):
sgs_val = other / self.sgs
si_val = other / self.si
else:
sgs_val = self.sgs
si_val = self.si
def __mul__(self, other):
if isinstance(other, multi_var):
sgs_val = self.sgs * other.sgs
si_val = self.si * other.si
return multi_var(si=si_val, sgs=sgs_val)
elif isinstance(other, (float, int)):
sgs_val = self.sgs * other
si_val = self.si * other
else:
sgs_val = self.sgs
si_val = self.si
return multi_var(si=si_val, sgs=sgs_val)
def __truediv__(self, other):
if isinstance(other, multi_var):
sgs_val = self.sgs / other.sgs
si_val = self.si / other.si
return multi_var(si=si_val, sgs=sgs_val)
elif isinstance(other, (float, int)):
sgs_val = self.sgs / other
si_val = self.si / other
else:
sgs_val = self.sgs
si_val = self.si
def __sub__(self, other):
if isinstance(other, multi_var):
sgs_val = self.sgs - other.sgs
si_val = self.si - other.si
return multi_var(si=si_val, sgs=sgs_val)
elif isinstance(other, (float, int)):
sgs_val = self.sgs - other
si_val = self.si - other
else:
sgs_val = self.sgs
si_val = self.si
def __repr__(self):
return [self.si, self.sgs]
def __str__(self):
return str([self.si, self.sgs])
def __pow__(self, other):
return multi_var(si=self.si**other, sgs=self.sgs**other)