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

Method getdigits

tools/python-3.11.9-amd64/Lib/_pydecimal.py:5871–5897  ·  view source on GitHub ↗

Given an integer p >= 0, return floor(10**p)*log(10). For example, self.getdigits(3) returns 2302.

(self, p)

Source from the content-addressed store, hash-verified

5869 self.digits = "23025850929940456840179914546843642076011014886"
5870
5871 def getdigits(self, p):
5872 """Given an integer p >= 0, return floor(10**p)*log(10).
5873
5874 For example, self.getdigits(3) returns 2302.
5875 """
5876 # digits are stored as a string, for quick conversion to
5877 # integer in the case that we've already computed enough
5878 # digits; the stored digits should always be correct
5879 # (truncated, not rounded to nearest).
5880 if p < 0:
5881 raise ValueError("p should be nonnegative")
5882
5883 if p >= len(self.digits):
5884 # compute p+3, p+6, p+9, ... digits; continue until at
5885 # least one of the extra digits is nonzero
5886 extra = 3
5887 while True:
5888 # compute p+extra digits, correct to within 1ulp
5889 M = 10**(p+extra+2)
5890 digits = str(_div_nearest(_ilog(10*M, M), 100))
5891 if digits[-extra:] != '0'*extra:
5892 break
5893 extra += 3
5894 # keep all reliable digits so far; remove trailing zeros
5895 # and next nonzero digit
5896 self.digits = digits.rstrip('0')[:-1]
5897 return int(self.digits[:p+1])
5898
5899_log10_digits = _Log10Memoize().getdigits
5900

Callers

nothing calls this directly

Calls 4

strFunction · 0.85
_div_nearestFunction · 0.85
_ilogFunction · 0.85
rstripMethod · 0.45

Tested by

no test coverage detected