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