Other simple Complex class for testing mixed arithmetic.
| 251 | numbers.Complex.register(Polar) |
| 252 | |
| 253 | class Rect: |
| 254 | """Other simple Complex class for testing mixed arithmetic.""" |
| 255 | def __init__(self, x, y): |
| 256 | self.x = x |
| 257 | self.y = y |
| 258 | def __mul__(self, other): |
| 259 | if isinstance(other, F): |
| 260 | return NotImplemented |
| 261 | return self.__class__(self.x * other, self.y * other) |
| 262 | def __rmul__(self, other): |
| 263 | return self.__class__(other * self.x, other * self.y) |
| 264 | def __truediv__(self, other): |
| 265 | if isinstance(other, F): |
| 266 | return NotImplemented |
| 267 | return self.__class__(self.x / other, self.y / other) |
| 268 | def __rtruediv__(self, other): |
| 269 | r = self.x * self.x + self.y * self.y |
| 270 | return self.__class__(other * (self.x / r), other * (self.y / r)) |
| 271 | def __rpow__(self, other): |
| 272 | return Polar(other ** self.x, math.log(other) * self.y) |
| 273 | def __complex__(self): |
| 274 | return complex(self.x, self.y) |
| 275 | def __eq__(self, other): |
| 276 | if self.__class__ != other.__class__: |
| 277 | return NotImplemented |
| 278 | return typed_approx_eq(self.x, other.x) and typed_approx_eq(self.y, other.y) |
| 279 | def __repr__(self): |
| 280 | return f'{self.__class__.__name__}({self.x!r}, {self.y!r})' |
| 281 | numbers.Complex.register(Rect) |
| 282 | |
| 283 | class RectComplex(Rect, complex): |
no outgoing calls
searching dependent graphs…