Skip to content

Commit 2439939

Browse files
committed
remove logical operations on decimal numbers
1 parent f41860f commit 2439939

File tree

1 file changed

+0
-157
lines changed

1 file changed

+0
-157
lines changed

jepler_udecimal/__init__.py

Lines changed: 0 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -3168,63 +3168,6 @@ def _fill_logical(self, context, opa, opb):
31683168
opb = opb[-context.prec :]
31693169
return opa, opb
31703170

3171-
def logical_and(self, other, context=None):
3172-
"""Applies an 'and' operation between self and other's digits."""
3173-
if context is None:
3174-
context = getcontext()
3175-
3176-
other = _convert_other(other, raiseit=True)
3177-
3178-
if not self._islogical() or not other._islogical():
3179-
return context._raise_error(InvalidOperation)
3180-
3181-
# fill to context.prec
3182-
(opa, opb) = self._fill_logical(context, self._int, other._int)
3183-
3184-
# make the operation, and clean starting zeroes
3185-
result = "".join([str(int(a) & int(b)) for a, b in zip(opa, opb)])
3186-
return _dec_from_triple(0, result.lstrip("0") or "0", 0)
3187-
3188-
def logical_invert(self, context=None):
3189-
"""Invert all its digits."""
3190-
if context is None:
3191-
context = getcontext()
3192-
return self.logical_xor(_dec_from_triple(0, "1" * context.prec, 0), context)
3193-
3194-
def logical_or(self, other, context=None):
3195-
"""Applies an 'or' operation between self and other's digits."""
3196-
if context is None:
3197-
context = getcontext()
3198-
3199-
other = _convert_other(other, raiseit=True)
3200-
3201-
if not self._islogical() or not other._islogical():
3202-
return context._raise_error(InvalidOperation)
3203-
3204-
# fill to context.prec
3205-
(opa, opb) = self._fill_logical(context, self._int, other._int)
3206-
3207-
# make the operation, and clean starting zeroes
3208-
result = "".join([str(int(a) | int(b)) for a, b in zip(opa, opb)])
3209-
return _dec_from_triple(0, result.lstrip("0") or "0", 0)
3210-
3211-
def logical_xor(self, other, context=None):
3212-
"""Applies an 'xor' operation between self and other's digits."""
3213-
if context is None:
3214-
context = getcontext()
3215-
3216-
other = _convert_other(other, raiseit=True)
3217-
3218-
if not self._islogical() or not other._islogical():
3219-
return context._raise_error(InvalidOperation)
3220-
3221-
# fill to context.prec
3222-
(opa, opb) = self._fill_logical(context, self._int, other._int)
3223-
3224-
# make the operation, and clean starting zeroes
3225-
result = "".join([str(int(a) ^ int(b)) for a, b in zip(opa, opb)])
3226-
return _dec_from_triple(0, result.lstrip("0") or "0", 0)
3227-
32283171
def max_mag(self, other, context=None):
32293172
"""Compares the values numerically with their sign ignored."""
32303173
other = _convert_other(other, raiseit=True)
@@ -4284,106 +4227,6 @@ def logb(self, a):
42844227
a = _convert_other(a, raiseit=True)
42854228
return a.logb(context=self)
42864229

4287-
def logical_and(self, a, b):
4288-
"""Applies the logical operation 'and' between each operand's digits.
4289-
4290-
The operands must be both logical numbers.
4291-
4292-
>>> ExtendedContext.logical_and(Decimal('0'), Decimal('0'))
4293-
Decimal('0')
4294-
>>> ExtendedContext.logical_and(Decimal('0'), Decimal('1'))
4295-
Decimal('0')
4296-
>>> ExtendedContext.logical_and(Decimal('1'), Decimal('0'))
4297-
Decimal('0')
4298-
>>> ExtendedContext.logical_and(Decimal('1'), Decimal('1'))
4299-
Decimal('1')
4300-
>>> ExtendedContext.logical_and(Decimal('1100'), Decimal('1010'))
4301-
Decimal('1000')
4302-
>>> ExtendedContext.logical_and(Decimal('1111'), Decimal('10'))
4303-
Decimal('10')
4304-
>>> ExtendedContext.logical_and(110, 1101)
4305-
Decimal('100')
4306-
>>> ExtendedContext.logical_and(Decimal(110), 1101)
4307-
Decimal('100')
4308-
>>> ExtendedContext.logical_and(110, Decimal(1101))
4309-
Decimal('100')
4310-
"""
4311-
a = _convert_other(a, raiseit=True)
4312-
return a.logical_and(b, context=self)
4313-
4314-
def logical_invert(self, a):
4315-
"""Invert all the digits in the operand.
4316-
4317-
The operand must be a logical number.
4318-
4319-
>>> ExtendedContext.logical_invert(Decimal('0'))
4320-
Decimal('111111111')
4321-
>>> ExtendedContext.logical_invert(Decimal('1'))
4322-
Decimal('111111110')
4323-
>>> ExtendedContext.logical_invert(Decimal('111111111'))
4324-
Decimal('0')
4325-
>>> ExtendedContext.logical_invert(Decimal('101010101'))
4326-
Decimal('10101010')
4327-
>>> ExtendedContext.logical_invert(1101)
4328-
Decimal('111110010')
4329-
"""
4330-
a = _convert_other(a, raiseit=True)
4331-
return a.logical_invert(context=self)
4332-
4333-
def logical_or(self, a, b):
4334-
"""Applies the logical operation 'or' between each operand's digits.
4335-
4336-
The operands must be both logical numbers.
4337-
4338-
>>> ExtendedContext.logical_or(Decimal('0'), Decimal('0'))
4339-
Decimal('0')
4340-
>>> ExtendedContext.logical_or(Decimal('0'), Decimal('1'))
4341-
Decimal('1')
4342-
>>> ExtendedContext.logical_or(Decimal('1'), Decimal('0'))
4343-
Decimal('1')
4344-
>>> ExtendedContext.logical_or(Decimal('1'), Decimal('1'))
4345-
Decimal('1')
4346-
>>> ExtendedContext.logical_or(Decimal('1100'), Decimal('1010'))
4347-
Decimal('1110')
4348-
>>> ExtendedContext.logical_or(Decimal('1110'), Decimal('10'))
4349-
Decimal('1110')
4350-
>>> ExtendedContext.logical_or(110, 1101)
4351-
Decimal('1111')
4352-
>>> ExtendedContext.logical_or(Decimal(110), 1101)
4353-
Decimal('1111')
4354-
>>> ExtendedContext.logical_or(110, Decimal(1101))
4355-
Decimal('1111')
4356-
"""
4357-
a = _convert_other(a, raiseit=True)
4358-
return a.logical_or(b, context=self)
4359-
4360-
def logical_xor(self, a, b):
4361-
"""Applies the logical operation 'xor' between each operand's digits.
4362-
4363-
The operands must be both logical numbers.
4364-
4365-
>>> ExtendedContext.logical_xor(Decimal('0'), Decimal('0'))
4366-
Decimal('0')
4367-
>>> ExtendedContext.logical_xor(Decimal('0'), Decimal('1'))
4368-
Decimal('1')
4369-
>>> ExtendedContext.logical_xor(Decimal('1'), Decimal('0'))
4370-
Decimal('1')
4371-
>>> ExtendedContext.logical_xor(Decimal('1'), Decimal('1'))
4372-
Decimal('0')
4373-
>>> ExtendedContext.logical_xor(Decimal('1100'), Decimal('1010'))
4374-
Decimal('110')
4375-
>>> ExtendedContext.logical_xor(Decimal('1111'), Decimal('10'))
4376-
Decimal('1101')
4377-
>>> ExtendedContext.logical_xor(110, 1101)
4378-
Decimal('1011')
4379-
>>> ExtendedContext.logical_xor(Decimal(110), 1101)
4380-
Decimal('1011')
4381-
>>> ExtendedContext.logical_xor(110, Decimal(1101))
4382-
Decimal('1011')
4383-
"""
4384-
a = _convert_other(a, raiseit=True)
4385-
return a.logical_xor(b, context=self)
4386-
43874230
def max(self, a, b):
43884231
"""max compares two values numerically and returns the maximum.
43894232

0 commit comments

Comments
 (0)