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

Method _log10_exp_bound

Lib/_pydecimal.py:3204–3232  ·  view source on GitHub ↗

Compute a lower bound for the adjusted exponent of self.log10(). In other words, find r such that self.log10() >= 10**r. Assumes that self is finite and positive and that self != 1.

(self)

Source from the content-addressed store, hash-verified

3202 return ans
3203
3204 def _log10_exp_bound(self):
3205 """Compute a lower bound for the adjusted exponent of self.log10().
3206 In other words, find r such that self.log10() >= 10**r.
3207 Assumes that self is finite and positive and that self != 1.
3208 """
3209
3210 # For x >= 10 or x < 0.1 we only need a bound on the integer
3211 # part of log10(self), and this comes directly from the
3212 # exponent of x. For 0.1 <= x <= 10 we use the inequalities
3213 # 1-1/x <= log(x) <= x-1. If x > 1 we have |log10(x)| >
3214 # (1-1/x)/2.31 > 0. If x < 1 then |log10(x)| > (1-x)/2.31 > 0
3215
3216 adj = self._exp + len(self._int) - 1
3217 if adj >= 1:
3218 # self >= 10
3219 return len(str(adj))-1
3220 if adj <= -2:
3221 # self < 0.1
3222 return len(str(-1-adj))-1
3223 op = _WorkRep(self)
3224 c, e = op.int, op.exp
3225 if adj == 0:
3226 # 1 < self < 10
3227 num = str(c-10**-e)
3228 den = str(231*c)
3229 return len(num) - len(den) - (num < den) + 2
3230 # adj == -1, 0.1 <= self < 1
3231 num = str(10**-e-c)
3232 return len(num) + e - (num < "231") - 1
3233
3234 def log10(self, context=None):
3235 """Returns the base 10 logarithm of self."""

Callers 2

__pow__Method · 0.95
log10Method · 0.95

Calls 3

lenFunction · 0.85
strFunction · 0.85
_WorkRepClass · 0.85

Tested by

no test coverage detected