def __rmul__(self, coefficient):
product = self.__class__(Nonee, None, self.a, self.b)
for _ in range(coefficient):
product += self
return product
coefficient の和訳は係数です。係数の数だけ点を加算します。
ビットの倍算だと以下のようになる。2進展開。
def __rmul__(self, coefficient):
coef = coefficient
current = self
result = self.__class__(Nonee, None, self.a, self.b)
while coef:
if coef & 1:
result += current
current += current
return result