mirror of
https://github.com/python/cpython.git
synced 2025-11-01 22:21:35 +00:00
[3.14] gh-102431: Clarify constraints on operands of Decimal logical operations (GH-102836) (#140105)
* [3.14] gh-102431: Clarify constraints on operands of Decimal logical operations (GH-102836)
Sync C/Python implementation of the decimal: logical_ops for contexts.
(cherry picked from commit 6ecf77dbde)
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
This commit is contained in:
parent
2142f4efcf
commit
1c55b9163b
3 changed files with 98 additions and 12 deletions
|
|
@ -3340,7 +3340,10 @@ def _fill_logical(self, context, opa, opb):
|
|||
return opa, opb
|
||||
|
||||
def logical_and(self, other, context=None):
|
||||
"""Applies an 'and' operation between self and other's digits."""
|
||||
"""Applies an 'and' operation between self and other's digits.
|
||||
|
||||
Both self and other must be logical numbers.
|
||||
"""
|
||||
if context is None:
|
||||
context = getcontext()
|
||||
|
||||
|
|
@ -3357,14 +3360,20 @@ def logical_and(self, other, context=None):
|
|||
return _dec_from_triple(0, result.lstrip('0') or '0', 0)
|
||||
|
||||
def logical_invert(self, context=None):
|
||||
"""Invert all its digits."""
|
||||
"""Invert all its digits.
|
||||
|
||||
The self must be logical number.
|
||||
"""
|
||||
if context is None:
|
||||
context = getcontext()
|
||||
return self.logical_xor(_dec_from_triple(0,'1'*context.prec,0),
|
||||
context)
|
||||
|
||||
def logical_or(self, other, context=None):
|
||||
"""Applies an 'or' operation between self and other's digits."""
|
||||
"""Applies an 'or' operation between self and other's digits.
|
||||
|
||||
Both self and other must be logical numbers.
|
||||
"""
|
||||
if context is None:
|
||||
context = getcontext()
|
||||
|
||||
|
|
@ -3381,7 +3390,10 @@ def logical_or(self, other, context=None):
|
|||
return _dec_from_triple(0, result.lstrip('0') or '0', 0)
|
||||
|
||||
def logical_xor(self, other, context=None):
|
||||
"""Applies an 'xor' operation between self and other's digits."""
|
||||
"""Applies an 'xor' operation between self and other's digits.
|
||||
|
||||
Both self and other must be logical numbers.
|
||||
"""
|
||||
if context is None:
|
||||
context = getcontext()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue