MCPcopy Index your code
hub / github.com/python/cpython / logb

Method logb

Lib/_pydecimal.py:3288–3316  ·  view source on GitHub ↗

Returns the exponent of the magnitude of self's MSD. The result is the integer which is the exponent of the magnitude of the most significant digit of self (as though it were truncated to a single digit while maintaining the value of that digit and without limiting

(self, context=None)

Source from the content-addressed store, hash-verified

3286 return ans
3287
3288 def logb(self, context=None):
3289 """ Returns the exponent of the magnitude of self's MSD.
3290
3291 The result is the integer which is the exponent of the magnitude
3292 of the most significant digit of self (as though it were truncated
3293 to a single digit while maintaining the value of that digit and
3294 without limiting the resulting exponent).
3295 """
3296 # logb(NaN) = NaN
3297 ans = self._check_nans(context=context)
3298 if ans:
3299 return ans
3300
3301 if context is None:
3302 context = getcontext()
3303
3304 # logb(+/-Inf) = +Inf
3305 if self._isinfinity():
3306 return _Infinity
3307
3308 # logb(0) = -Inf, DivisionByZero
3309 if not self:
3310 return context._raise_error(DivisionByZero, 'logb(0)', 1)
3311
3312 # otherwise, simply return the adjusted exponent of self, as a
3313 # Decimal. Note that no attempt is made to fit the result
3314 # into the current context.
3315 ans = Decimal(self.adjusted())
3316 return ans._fix(context)
3317
3318 def _islogical(self):
3319 """Return True if self is a logical operand.

Callers 4

test_none_argsMethod · 0.95
logbMethod · 0.45
test_named_parametersMethod · 0.45
test_implicit_contextMethod · 0.45

Calls 7

_check_nansMethod · 0.95
_isinfinityMethod · 0.95
adjustedMethod · 0.95
_fixMethod · 0.95
getcontextFunction · 0.85
DecimalClass · 0.85
_raise_errorMethod · 0.80

Tested by 3

test_none_argsMethod · 0.76
test_named_parametersMethod · 0.36
test_implicit_contextMethod · 0.36