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

Method logical_and

Lib/_pydecimal.py:3345–3363  ·  view source on GitHub ↗

Applies an 'and' operation between self and other's digits. Both self and other must be logical numbers.

(self, other, context=None)

Source from the content-addressed store, hash-verified

3343 return opa, opb
3344
3345 def logical_and(self, other, context=None):
3346 """Applies an 'and' operation between self and other's digits.
3347
3348 Both self and other must be logical numbers.
3349 """
3350 if context is None:
3351 context = getcontext()
3352
3353 other = _convert_other(other, raiseit=True)
3354
3355 if not self._islogical() or not other._islogical():
3356 return context._raise_error(InvalidOperation)
3357
3358 # fill to context.prec
3359 (opa, opb) = self._fill_logical(context, self._int, other._int)
3360
3361 # make the operation, and clean starting zeroes
3362 result = "".join([str(int(a)&int(b)) for a,b in zip(opa,opb)])
3363 return _dec_from_triple(0, result.lstrip('0') or '0', 0)
3364
3365 def logical_invert(self, context=None):
3366 """Invert all its digits.

Callers 4

test_none_argsMethod · 0.95
logical_andMethod · 0.45
test_named_parametersMethod · 0.45

Calls 9

_islogicalMethod · 0.95
_fill_logicalMethod · 0.95
getcontextFunction · 0.85
_convert_otherFunction · 0.85
strFunction · 0.85
_dec_from_tripleFunction · 0.85
_raise_errorMethod · 0.80
joinMethod · 0.45
lstripMethod · 0.45

Tested by 3

test_none_argsMethod · 0.76
test_named_parametersMethod · 0.36