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

Function _float_sqrt_of_frac

Lib/statistics.py:1717–1727  ·  view source on GitHub ↗

Square root of n/m as a float, correctly rounded.

(n: int, m: int)

Source from the content-addressed store, hash-verified

1715
1716
1717def _float_sqrt_of_frac(n: int, m: int) -> float:
1718 """Square root of n/m as a float, correctly rounded."""
1719 # See principle and proof sketch at: https://bugs.python.org/msg407078
1720 q = (n.bit_length() - m.bit_length() - _sqrt_bit_width) // 2
1721 if q >= 0:
1722 numerator = _integer_sqrt_of_frac_rto(n, m << 2 * q) << q
1723 denominator = 1
1724 else:
1725 numerator = _integer_sqrt_of_frac_rto(n << -2 * q, m)
1726 denominator = 1 << -q
1727 return numerator / denominator # Convert to float
1728
1729
1730def _decimal_sqrt_of_frac(n: int, m: int) -> Decimal:

Callers 3

stdevFunction · 0.85
pstdevFunction · 0.85
_mean_stdevFunction · 0.85

Calls 2

bit_lengthMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…