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)
| 5784 | return _div_nearest(w*y, M) |
| 5785 | |
| 5786 | def _dlog10(c, e, p): |
| 5787 | """Given integers c, e and p with c > 0, p >= 0, compute an integer |
| 5788 | approximation to 10**p * log10(c*10**e), with an absolute error of |
| 5789 | at most 1. Assumes that c*10**e is not exactly 1.""" |
| 5790 | |
| 5791 | # increase precision by 2; compensate for this by dividing |
| 5792 | # final result by 100 |
| 5793 | p += 2 |
| 5794 | |
| 5795 | # write c*10**e as d*10**f with either: |
| 5796 | # f >= 0 and 1 <= d <= 10, or |
| 5797 | # f <= 0 and 0.1 <= d <= 1. |
| 5798 | # Thus for c*10**e close to 1, f = 0 |
| 5799 | l = len(str(c)) |
| 5800 | f = e+l - (e+l >= 1) |
| 5801 | |
| 5802 | if p > 0: |
| 5803 | M = 10**p |
| 5804 | k = e+p-f |
| 5805 | if k >= 0: |
| 5806 | c *= 10**k |
| 5807 | else: |
| 5808 | c = _div_nearest(c, 10**-k) |
| 5809 | |
| 5810 | log_d = _ilog(c, M) # error < 5 + 22 = 27 |
| 5811 | log_10 = _log10_digits(p) # error < 1 |
| 5812 | log_d = _div_nearest(log_d*M, log_10) |
| 5813 | log_tenpower = f*M # exact |
| 5814 | else: |
| 5815 | log_d = 0 # error < 2.31 |
| 5816 | log_tenpower = _div_nearest(f, 10**-p) # error < 0.5 |
| 5817 | |
| 5818 | return _div_nearest(log_tenpower+log_d, 100) |
| 5819 | |
| 5820 | def _dlog(c, e, p): |
| 5821 | """Given integers c, e and p with c > 0, compute an integer |
no test coverage detected