Given an integer p >= 0, return floor(10**p)*log(10). For example, self.getdigits(3) returns 2302.
(self, p)
| 5833 | self.digits = "23025850929940456840179914546843642076011014886" |
| 5834 | |
| 5835 | def getdigits(self, p): |
| 5836 | """Given an integer p >= 0, return floor(10**p)*log(10). |
| 5837 | |
| 5838 | For example, self.getdigits(3) returns 2302. |
| 5839 | """ |
| 5840 | # digits are stored as a string, for quick conversion to |
| 5841 | # integer in the case that we've already computed enough |
| 5842 | # digits; the stored digits should always be correct |
| 5843 | # (truncated, not rounded to nearest). |
| 5844 | if p < 0: |
| 5845 | raise ValueError("p should be nonnegative") |
| 5846 | |
| 5847 | if p >= len(self.digits): |
| 5848 | # compute p+3, p+6, p+9, ... digits; continue until at |
| 5849 | # least one of the extra digits is nonzero |
| 5850 | extra = 3 |
| 5851 | while True: |
| 5852 | # compute p+extra digits, correct to within 1ulp |
| 5853 | M = 10**(p+extra+2) |
| 5854 | digits = str(_div_nearest(_ilog(10*M, M), 100)) |
| 5855 | if digits[-extra:] != '0'*extra: |
| 5856 | break |
| 5857 | extra += 3 |
| 5858 | # keep all reliable digits so far; remove trailing zeros |
| 5859 | # and next nonzero digit |
| 5860 | self.digits = digits.rstrip('0')[:-1] |
| 5861 | return int(self.digits[:p+1]) |
| 5862 | |
| 5863 | _log10_digits = _Log10Memoize().getdigits |
| 5864 |
nothing calls this directly
no test coverage detected