MCPcopy Index your code
hub / github.com/RustPython/RustPython / _ln_exp_bound

Method _ln_exp_bound

Lib/_pydecimal.py:3129–3151  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 1

lnMethod · 0.95

Calls 3

lenFunction · 0.85
strFunction · 0.85
_WorkRepClass · 0.85

Tested by

no test coverage detected