MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / log10

Method log10

tools/python-3.11.9-amd64/Lib/_pydecimal.py:3282–3331  ·  view source on GitHub ↗

Returns the base 10 logarithm of self.

(self, context=None)

Source from the content-addressed store, hash-verified

3280 return len(num) + e - (num < "231") - 1
3281
3282 def log10(self, context=None):
3283 """Returns the base 10 logarithm of self."""
3284
3285 if context is None:
3286 context = getcontext()
3287
3288 # log10(NaN) = NaN
3289 ans = self._check_nans(context=context)
3290 if ans:
3291 return ans
3292
3293 # log10(0.0) == -Infinity
3294 if not self:
3295 return _NegativeInfinity
3296
3297 # log10(Infinity) = Infinity
3298 if self._isinfinity() == 1:
3299 return _Infinity
3300
3301 # log10(negative or -Infinity) raises InvalidOperation
3302 if self._sign == 1:
3303 return context._raise_error(InvalidOperation,
3304 'log10 of a negative value')
3305
3306 # log10(10**n) = n
3307 if self._int[0] == '1' and self._int[1:] == '0'*(len(self._int) - 1):
3308 # answer may need rounding
3309 ans = Decimal(self._exp + len(self._int) - 1)
3310 else:
3311 # result is irrational, so necessarily inexact
3312 op = _WorkRep(self)
3313 c, e = op.int, op.exp
3314 p = context.prec
3315
3316 # correctly rounded result: repeatedly increase precision
3317 # until result is unambiguously roundable
3318 places = p-self._log10_exp_bound()+2
3319 while True:
3320 coeff = _dlog10(c, e, places)
3321 # assert len(str(abs(coeff)))-p >= 1
3322 if coeff % (5*10**(len(str(abs(coeff)))-p-1)):
3323 break
3324 places += 3
3325 ans = _dec_from_triple(int(coeff<0), str(abs(coeff)), -places)
3326
3327 context = context._shallow_copy()
3328 rounding = context._set_rounding(ROUND_HALF_EVEN)
3329 ans = ans._fix(context)
3330 context.rounding = rounding
3331 return ans
3332
3333 def logb(self, context=None):
3334 """ Returns the exponent of the magnitude of self&#x27;s MSD.

Callers 1

log10Method · 0.45

Calls 14

_check_nansMethod · 0.95
_isinfinityMethod · 0.95
_log10_exp_boundMethod · 0.95
_fixMethod · 0.95
getcontextFunction · 0.85
DecimalClass · 0.85
_WorkRepClass · 0.85
_dlog10Function · 0.85
strFunction · 0.85
_dec_from_tripleFunction · 0.85
_raise_errorMethod · 0.80
_shallow_copyMethod · 0.80

Tested by

no test coverage detected