Compute an approximation to exp(c*10**e), with p decimal places of precision. Returns integers d, f such that: 10**(p-1) <= d <= 10**p, and (d-1)*10**f < exp(c*10**e) < (d+1)*10**f In other words, d*10**f is an approximation to exp(c*10**e) with p digits of precision,
(c, e, p)
| 5900 | return M+y |
| 5901 | |
| 5902 | def _dexp(c, e, p): |
| 5903 | """Compute an approximation to exp(c*10**e), with p decimal places of |
| 5904 | precision. |
| 5905 | |
| 5906 | Returns integers d, f such that: |
| 5907 | |
| 5908 | 10**(p-1) <= d <= 10**p, and |
| 5909 | (d-1)*10**f < exp(c*10**e) < (d+1)*10**f |
| 5910 | |
| 5911 | In other words, d*10**f is an approximation to exp(c*10**e) with p |
| 5912 | digits of precision, and with an error in d of at most 1. This is |
| 5913 | almost, but not quite, the same as the error being < 1ulp: when d |
| 5914 | = 10**(p-1) the error could be up to 10 ulp.""" |
| 5915 | |
| 5916 | # we'll call iexp with M = 10**(p+2), giving p+3 digits of precision |
| 5917 | p += 2 |
| 5918 | |
| 5919 | # compute log(10) with extra precision = adjusted exponent of c*10**e |
| 5920 | extra = max(0, e + len(str(c)) - 1) |
| 5921 | q = p + extra |
| 5922 | |
| 5923 | # compute quotient c*10**e/(log(10)) = c*10**(e+q)/(log(10)*10**q), |
| 5924 | # rounding down |
| 5925 | shift = e+q |
| 5926 | if shift >= 0: |
| 5927 | cshift = c*10**shift |
| 5928 | else: |
| 5929 | cshift = c//10**-shift |
| 5930 | quot, rem = divmod(cshift, _log10_digits(q)) |
| 5931 | |
| 5932 | # reduce remainder back to original precision |
| 5933 | rem = _div_nearest(rem, 10**extra) |
| 5934 | |
| 5935 | # error in result of _iexp < 120; error after division < 0.62 |
| 5936 | return _div_nearest(_iexp(rem, 10**p), 1000), quot - p + 3 |
| 5937 | |
| 5938 | def _dpower(xc, xe, yc, ye, p): |
| 5939 | """Given integers xc, xe, yc and ye representing Decimals x = xc*10**xe and |