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

Class Root

Lib/test/test_fractions.py:193–221  ·  view source on GitHub ↗

Simple Real class for testing mixed arithmetic.

Source from the content-addressed store, hash-verified

191numbers.Rational.register(Rat)
192
193class Root:
194 """Simple Real class for testing mixed arithmetic."""
195 def __init__(self, v, n=F(2)):
196 self.base = v
197 self.degree = n
198 def __mul__(self, other):
199 if isinstance(other, F):
200 return NotImplemented
201 return self.__class__(self.base * other**self.degree, self.degree)
202 def __rmul__(self, other):
203 return self.__class__(other**self.degree * self.base, self.degree)
204 def __truediv__(self, other):
205 if isinstance(other, F):
206 return NotImplemented
207 return self.__class__(self.base / other**self.degree, self.degree)
208 def __rtruediv__(self, other):
209 return self.__class__(other**self.degree / self.base, self.degree)
210 def __pow__(self, other):
211 if isinstance(other, F):
212 return NotImplemented
213 return self.__class__(self.base, self.degree / other)
214 def __float__(self):
215 return float(self.base) ** (1 / float(self.degree))
216 def __eq__(self, other):
217 if self.__class__ != other.__class__:
218 return NotImplemented
219 return typed_approx_eq(self.base, other.base) and typed_approx_eq(self.degree, other.degree)
220 def __repr__(self):
221 return f'{self.__class__.__name__}({self.base!r}, {self.degree!r})'
222numbers.Real.register(Root)
223
224class Polar:

Callers 4

testMixedDivisionMethod · 0.70
testMixedPowerMethod · 0.70

Calls

no outgoing calls

Tested by 4

testMixedDivisionMethod · 0.56
testMixedPowerMethod · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…