MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / __pow__

Method __pow__

tools/python-3.11.9-amd64/Lib/fractions.py:541–569  ·  view source on GitHub ↗

a ** b If b is not an integer, the result will be a float or complex since roots are generally irrational. If b is an integer, the result will be rational.

(a, b)

Source from the content-addressed store, hash-verified

539 __mod__, __rmod__ = _operator_fallbacks(_mod, operator.mod)
540
541 def __pow__(a, b):
542 """a ** b
543
544 If b is not an integer, the result will be a float or complex
545 since roots are generally irrational. If b is an integer, the
546 result will be rational.
547
548 """
549 if isinstance(b, numbers.Rational):
550 if b.denominator == 1:
551 power = b.numerator
552 if power >= 0:
553 return Fraction(a._numerator ** power,
554 a._denominator ** power,
555 _normalize=False)
556 elif a._numerator >= 0:
557 return Fraction(a._denominator ** -power,
558 a._numerator ** -power,
559 _normalize=False)
560 else:
561 return Fraction((-a._denominator) ** -power,
562 (-a._numerator) ** -power,
563 _normalize=False)
564 else:
565 # A fractional power will generally produce an
566 # irrational number.
567 return float(a) ** float(b)
568 else:
569 return float(a) ** b
570
571 def __rpow__(b, a):
572 """a ** b"""

Callers

nothing calls this directly

Calls 1

FractionClass · 0.85

Tested by

no test coverage detected