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

Method _div

Lib/fractions.py:842–860  ·  view source on GitHub ↗

a / b

(a, b)

Source from the content-addressed store, hash-verified

840 __mul__, __rmul__ = _operator_fallbacks(_mul, operator.mul)
841
842 def _div(a, b):
843 """a / b"""
844 # Same as _mul(), with inversed b.
845 nb, db = b._numerator, b._denominator
846 if nb == 0:
847 raise ZeroDivisionError('Fraction(%s, 0)' % db)
848 na, da = a._numerator, a._denominator
849 g1 = math.gcd(na, nb)
850 if g1 > 1:
851 na //= g1
852 nb //= g1
853 g2 = math.gcd(db, da)
854 if g2 > 1:
855 da //= g2
856 db //= g2
857 n, d = na * db, nb * da
858 if d < 0:
859 n, d = -n, -d
860 return Fraction._from_coprime_ints(n, d)
861
862 __truediv__, __rtruediv__ = _operator_fallbacks(_div, operator.truediv)
863

Callers

nothing calls this directly

Calls 1

_from_coprime_intsMethod · 0.80

Tested by

no test coverage detected