Simple Complex class for testing mixed arithmetic.
| 222 | numbers.Real.register(Root) |
| 223 | |
| 224 | class Polar: |
| 225 | """Simple Complex class for testing mixed arithmetic.""" |
| 226 | def __init__(self, r, phi): |
| 227 | self.r = r |
| 228 | self.phi = phi |
| 229 | def __mul__(self, other): |
| 230 | if isinstance(other, F): |
| 231 | return NotImplemented |
| 232 | return self.__class__(self.r * other, self.phi) |
| 233 | def __rmul__(self, other): |
| 234 | return self.__class__(other * self.r, self.phi) |
| 235 | def __truediv__(self, other): |
| 236 | if isinstance(other, F): |
| 237 | return NotImplemented |
| 238 | return self.__class__(self.r / other, self.phi) |
| 239 | def __rtruediv__(self, other): |
| 240 | return self.__class__(other / self.r, -self.phi) |
| 241 | def __pow__(self, other): |
| 242 | if isinstance(other, F): |
| 243 | return NotImplemented |
| 244 | return self.__class__(self.r ** other, self.phi * other) |
| 245 | def __eq__(self, other): |
| 246 | if self.__class__ != other.__class__: |
| 247 | return NotImplemented |
| 248 | return typed_approx_eq(self.r, other.r) and typed_approx_eq(self.phi, other.phi) |
| 249 | def __repr__(self): |
| 250 | return f'{self.__class__.__name__}({self.r!r}, {self.phi!r})' |
| 251 | numbers.Complex.register(Polar) |
| 252 | |
| 253 | class Rect: |
no outgoing calls
searching dependent graphs…