MCPcopy Index your code
hub / github.com/python/cpython / Polar

Class Polar

Lib/test/test_fractions.py:224–250  ·  view source on GitHub ↗

Simple Complex class for testing mixed arithmetic.

Source from the content-addressed store, hash-verified

222numbers.Real.register(Root)
223
224class 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})'
251numbers.Complex.register(Polar)
252
253class Rect:

Callers 5

__rpow__Method · 0.85
testMixedDivisionMethod · 0.85
testMixedPowerMethod · 0.85

Calls

no outgoing calls

Tested by 5

__rpow__Method · 0.68
testMixedDivisionMethod · 0.68
testMixedPowerMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…