@@ -34,80 +34,92 @@ def __float__(self) -> float:
3434 #
3535
3636 def __eq__ (self , other : object ) -> bool :
37- if isinstance (other , (int , float )):
38- return round (self ._value * self .__rr ) == round (other * self .__rr )
39- else :
40- return NotImplemented
37+ match other :
38+ case int () | float ():
39+ return round (self ._value * self .__rr ) == round (other * self .__rr )
40+ case _:
41+ return NotImplemented
4142
4243 def __ne__ (self , other : object ) -> bool :
43- if isinstance (other , (int , float )):
44- return round (self ._value * self .__rr ) != round (other * self .__rr )
45- else :
46- return NotImplemented
44+ match other :
45+ case int () | float ():
46+ return round (self ._value * self .__rr ) != round (other * self .__rr )
47+ case _:
48+ return NotImplemented
4749
4850 def __ge__ (self , other : object ) -> bool :
49- if isinstance (other , (int , float )):
50- return round (self ._value * self .__rr ) >= round (other * self .__rr )
51- else :
52- return NotImplemented
51+ match other :
52+ case int () | float ():
53+ return round (self ._value * self .__rr ) >= round (other * self .__rr )
54+ case _:
55+ return NotImplemented
5356
5457 def __gt__ (self , other : object ) -> bool :
55- if isinstance (other , (int , float )):
56- return round (self ._value * self .__rr ) > round (other * self .__rr )
57- else :
58- return NotImplemented
58+ match other :
59+ case int () | float ():
60+ return round (self ._value * self .__rr ) > round (other * self .__rr )
61+ case _:
62+ return NotImplemented
5963
6064 def __le__ (self , other : object ) -> bool :
61- if isinstance (other , (int , float )):
62- return round (self ._value * self .__rr ) <= round (other * self .__rr )
63- else :
64- return NotImplemented
65+ match other :
66+ case int () | float ():
67+ return round (self ._value * self .__rr ) <= round (other * self .__rr )
68+ case _:
69+ return NotImplemented
6570
6671 def __lt__ (self , other : object ) -> bool :
67- if isinstance (other , (int , float )):
68- return round (self ._value * self .__rr ) < round (other * self .__rr )
69- else :
70- return NotImplemented
72+ match other :
73+ case int () | float ():
74+ return round (self ._value * self .__rr ) < round (other * self .__rr )
75+ case _:
76+ return NotImplemented
7177
7278 #
7379 # Arithmetics:
7480 #
7581
7682 def __add__ (self , other : object ) -> float :
77- if isinstance (other , (int , float )):
78- return (round (self ._value * self .__rr ) + round (other * self .__rr )) / self .__rr
79- else :
80- return NotImplemented
83+ match other :
84+ case int () | float ():
85+ return (round (self ._value * self .__rr ) + round (other * self .__rr )) / self .__rr
86+ case _:
87+ return NotImplemented
8188
8289 def __sub__ (self , other : object ) -> float :
83- if isinstance (other , (int , float )):
84- return (round (self ._value * self .__rr ) - round (other * self .__rr )) / self .__rr
85- else :
86- return NotImplemented
90+ match other :
91+ case int () | float ():
92+ return (round (self ._value * self .__rr ) - round (other * self .__rr )) / self .__rr
93+ case _:
94+ return NotImplemented
8795
8896 def __mul__ (self , other : object ) -> float :
89- if isinstance (other , (int , float )):
90- return (round (self ._value * self .__rr ) * round (other * self .__rr )) / (self .__rr ** 2 )
91- else :
92- return NotImplemented
97+ match other :
98+ case int () | float ():
99+ return (round (self ._value * self .__rr ) * round (other * self .__rr )) / (self .__rr ** 2 )
100+ case _:
101+ return NotImplemented
93102
94103 def __floordiv__ (self , other : object ) -> float :
95- if isinstance (other , (int , float )):
96- return (round (self ._value * self .__rr ) // round (other * self .__rr ))
97- else :
98- return NotImplemented
104+ match other :
105+ case int () | float ():
106+ return (round (self ._value * self .__rr ) // round (other * self .__rr ))
107+ case _:
108+ return NotImplemented
99109
100110 def __truediv__ (self , other : object ) -> float :
101- if isinstance (other , (int , float )):
102- return (round (self ._value * self .__rr ) / round (other * self .__rr ))
103- else :
104- return NotImplemented
111+ match other :
112+ case int () | float ():
113+ return (round (self ._value * self .__rr ) / round (other * self .__rr ))
114+ case _:
115+ return NotImplemented
105116
106117 def __mod__ (self , other : object ) -> float :
107- if isinstance (other , (int , float )):
108- return (round (self ._value * self .__rr ) % round (other * self .__rr )) / (self .__rr )
109- else :
110- return NotImplemented
118+ match other :
119+ case int () | float ():
120+ return (round (self ._value * self .__rr ) % round (other * self .__rr )) / (self .__rr )
121+ case _:
122+ return NotImplemented
111123
112124 # See the StdLib's comments on pow() on why it is Any, not float.
113125 def __pow__ (self , power : float , modulo : None = None ) -> Any :
0 commit comments