Given integers c, e and p with c > 0, p >= 0, compute an integer approximation to 10**p * log10(c*10**e), with an absolute error of at most 1. Assumes that c*10**e is not exactly 1.
(c, e, p)
| 5751 | return _div_nearest(w*y, M) |
| 5752 | |
| 5753 | def _dlog10(c, e, p): |
| 5754 | """Given integers c, e and p with c > 0, p >= 0, compute an integer |
| 5755 | approximation to 10**p * log10(c*10**e), with an absolute error of |
| 5756 | at most 1. Assumes that c*10**e is not exactly 1.""" |
| 5757 | |
| 5758 | # increase precision by 2; compensate for this by dividing |
| 5759 | # final result by 100 |
| 5760 | p += 2 |
| 5761 | |
| 5762 | # write c*10**e as d*10**f with either: |
| 5763 | # f >= 0 and 1 <= d <= 10, or |
| 5764 | # f <= 0 and 0.1 <= d <= 1. |
| 5765 | # Thus for c*10**e close to 1, f = 0 |
| 5766 | l = len(str(c)) |
| 5767 | f = e+l - (e+l >= 1) |
| 5768 | |
| 5769 | if p > 0: |
| 5770 | M = 10**p |
| 5771 | k = e+p-f |
| 5772 | if k >= 0: |
| 5773 | c *= 10**k |
| 5774 | else: |
| 5775 | c = _div_nearest(c, 10**-k) |
| 5776 | |
| 5777 | log_d = _ilog(c, M) # error < 5 + 22 = 27 |
| 5778 | log_10 = _log10_digits(p) # error < 1 |
| 5779 | log_d = _div_nearest(log_d*M, log_10) |
| 5780 | log_tenpower = f*M # exact |
| 5781 | else: |
| 5782 | log_d = 0 # error < 2.31 |
| 5783 | log_tenpower = _div_nearest(f, 10**-p) # error < 0.5 |
| 5784 | |
| 5785 | return _div_nearest(log_tenpower+log_d, 100) |
| 5786 | |
| 5787 | def _dlog(c, e, p): |
| 5788 | """Given integers c, e and p with c > 0, compute an integer |
no test coverage detected
searching dependent graphs…