Simple Real class for testing mixed arithmetic.
| 191 | numbers.Rational.register(Rat) |
| 192 | |
| 193 | class 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})' |
| 222 | numbers.Real.register(Root) |
| 223 | |
| 224 | class Polar: |
no outgoing calls
searching dependent graphs…