Compute a lower bound for the adjusted exponent of self.ln(). In other words, compute r such that self.ln() >= 10**r. Assumes that self is finite and positive and that self != 1.
(self)
| 3130 | return not self._is_special and self._int == '0' |
| 3131 | |
| 3132 | def _ln_exp_bound(self): |
| 3133 | """Compute a lower bound for the adjusted exponent of self.ln(). |
| 3134 | In other words, compute r such that self.ln() >= 10**r. Assumes |
| 3135 | that self is finite and positive and that self != 1. |
| 3136 | """ |
| 3137 | |
| 3138 | # for 0.1 <= x <= 10 we use the inequalities 1-1/x <= ln(x) <= x-1 |
| 3139 | adj = self._exp + len(self._int) - 1 |
| 3140 | if adj >= 1: |
| 3141 | # argument >= 10; we use 23/10 = 2.3 as a lower bound for ln(10) |
| 3142 | return len(str(adj*23//10)) - 1 |
| 3143 | if adj <= -2: |
| 3144 | # argument <= 0.1 |
| 3145 | return len(str((-1-adj)*23//10)) - 1 |
| 3146 | op = _WorkRep(self) |
| 3147 | c, e = op.int, op.exp |
| 3148 | if adj == 0: |
| 3149 | # 1 < self < 10 |
| 3150 | num = str(c-10**-e) |
| 3151 | den = str(c) |
| 3152 | return len(num) - len(den) - (num < den) |
| 3153 | # adj == -1, 0.1 <= self < 1 |
| 3154 | return e + len(str(10**-e - c)) - 1 |
| 3155 | |
| 3156 | |
| 3157 | def ln(self, context=None): |