desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'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 the resulting exponent).'
def logb(self, context=None):
ans = self._check_nans(context=context) if ans: return ans if (context is None): context = getcontext() if self._isinfinity(): return _Infinity if (not self): return context._raise_error(DivisionByZero, 'logb(0)', 1) ans = Decimal(self.adjusted()) return ans._...
'Return True if self is a logical operand. For being logical, it must be a finite number with a sign of 0, an exponent of 0, and a coefficient whose digits must all be either 0 or 1.'
def _islogical(self):
if ((self._sign != 0) or (self._exp != 0)): return False for dig in self._int: if (dig not in '01'): return False return True
'Applies an \'and\' operation between self and other\'s digits.'
def logical_and(self, other, context=None):
if (context is None): context = getcontext() other = _convert_other(other, raiseit=True) if ((not self._islogical()) or (not other._islogical())): return context._raise_error(InvalidOperation) (opa, opb) = self._fill_logical(context, self._int, other._int) result = ''.join([str((int(...
'Invert all its digits.'
def logical_invert(self, context=None):
if (context is None): context = getcontext() return self.logical_xor(_dec_from_triple(0, ('1' * context.prec), 0), context)
'Applies an \'or\' operation between self and other\'s digits.'
def logical_or(self, other, context=None):
if (context is None): context = getcontext() other = _convert_other(other, raiseit=True) if ((not self._islogical()) or (not other._islogical())): return context._raise_error(InvalidOperation) (opa, opb) = self._fill_logical(context, self._int, other._int) result = ''.join([str((int(...
'Applies an \'xor\' operation between self and other\'s digits.'
def logical_xor(self, other, context=None):
if (context is None): context = getcontext() other = _convert_other(other, raiseit=True) if ((not self._islogical()) or (not other._islogical())): return context._raise_error(InvalidOperation) (opa, opb) = self._fill_logical(context, self._int, other._int) result = ''.join([str((int(...
'Compares the values numerically with their sign ignored.'
def max_mag(self, other, context=None):
other = _convert_other(other, raiseit=True) if (context is None): context = getcontext() if (self._is_special or other._is_special): sn = self._isnan() on = other._isnan() if (sn or on): if ((on == 1) and (sn == 0)): return self._fix(context) ...
'Compares the values numerically with their sign ignored.'
def min_mag(self, other, context=None):
other = _convert_other(other, raiseit=True) if (context is None): context = getcontext() if (self._is_special or other._is_special): sn = self._isnan() on = other._isnan() if (sn or on): if ((on == 1) and (sn == 0)): return self._fix(context) ...
'Returns the largest representable number smaller than itself.'
def next_minus(self, context=None):
if (context is None): context = getcontext() ans = self._check_nans(context=context) if ans: return ans if (self._isinfinity() == (-1)): return _NegativeInfinity if (self._isinfinity() == 1): return _dec_from_triple(0, ('9' * context.prec), context.Etop()) context...
'Returns the smallest representable number larger than itself.'
def next_plus(self, context=None):
if (context is None): context = getcontext() ans = self._check_nans(context=context) if ans: return ans if (self._isinfinity() == 1): return _Infinity if (self._isinfinity() == (-1)): return _dec_from_triple(1, ('9' * context.prec), context.Etop()) context = conte...
'Returns the number closest to self, in the direction towards other. The result is the closest representable number to self (excluding self) that is in the direction towards other, unless both have the same value. If the two operands are numerically equal, then the result is a copy of self with the sign set to be the ...
def next_toward(self, other, context=None):
other = _convert_other(other, raiseit=True) if (context is None): context = getcontext() ans = self._check_nans(other, context) if ans: return ans comparison = self._cmp(other) if (comparison == 0): return self.copy_sign(other) if (comparison == (-1)): ans = s...
'Returns an indication of the class of self. The class is one of the following strings: sNaN NaN -Infinity -Normal -Subnormal -Zero +Zero +Subnormal +Normal +Infinity'
def number_class(self, context=None):
if self.is_snan(): return 'sNaN' if self.is_qnan(): return 'NaN' inf = self._isinfinity() if (inf == 1): return '+Infinity' if (inf == (-1)): return '-Infinity' if self.is_zero(): if self._sign: return '-Zero' else: return '...
'Just returns 10, as this is Decimal, :)'
def radix(self):
return Decimal(10)
'Returns a rotated copy of self, value-of-other times.'
def rotate(self, other, context=None):
if (context is None): context = getcontext() other = _convert_other(other, raiseit=True) ans = self._check_nans(other, context) if ans: return ans if (other._exp != 0): return context._raise_error(InvalidOperation) if (not ((- context.prec) <= int(other) <= context.prec))...
'Returns self operand after adding the second value to its exp.'
def scaleb(self, other, context=None):
if (context is None): context = getcontext() other = _convert_other(other, raiseit=True) ans = self._check_nans(other, context) if ans: return ans if (other._exp != 0): return context._raise_error(InvalidOperation) liminf = ((-2) * (context.Emax + context.prec)) limsu...
'Returns a shifted copy of self, value-of-other times.'
def shift(self, other, context=None):
if (context is None): context = getcontext() other = _convert_other(other, raiseit=True) ans = self._check_nans(other, context) if ans: return ans if (other._exp != 0): return context._raise_error(InvalidOperation) if (not ((- context.prec) <= int(other) <= context.prec))...
'Format a Decimal instance according to the given specifier. The specifier should be a standard format specifier, with the form described in PEP 3101. Formatting types \'e\', \'E\', \'f\', \'F\', \'g\', \'G\', \'n\' and \'%\' are supported. If the formatting type is omitted it defaults to \'g\' or \'G\', depending on...
def __format__(self, specifier, context=None, _localeconv=None):
if (context is None): context = getcontext() spec = _parse_format_specifier(specifier, _localeconv=_localeconv) if self._is_special: sign = _format_sign(self._sign, spec) body = str(self.copy_abs()) if (spec['type'] == '%'): body += '%' return _format_alig...
'Show the current context.'
def __repr__(self):
s = [] s.append(('Context(prec=%(prec)d, rounding=%(rounding)s, Emin=%(Emin)d, Emax=%(Emax)d, capitals=%(capitals)d, clamp=%(clamp)d' % vars(self))) names = [f.__name__ for (f, v) in self.flags.items() if v] s.append((('flags=[' + ', '.join(names)) + ']')) names = [t.__name__ for (...
'Reset all flags to zero'
def clear_flags(self):
for flag in self.flags: self.flags[flag] = 0
'Reset all traps to zero'
def clear_traps(self):
for flag in self.traps: self.traps[flag] = 0
'Returns a shallow copy from self.'
def _shallow_copy(self):
nc = Context(self.prec, self.rounding, self.Emin, self.Emax, self.capitals, self.clamp, self.flags, self.traps, self._ignored_flags) return nc
'Returns a deep copy from self.'
def copy(self):
nc = Context(self.prec, self.rounding, self.Emin, self.Emax, self.capitals, self.clamp, self.flags.copy(), self.traps.copy(), self._ignored_flags) return nc
'Handles an error If the flag is in _ignored_flags, returns the default response. Otherwise, it sets the flag, then, if the corresponding trap_enabler is set, it reraises the exception. Otherwise, it returns the default value after setting the flag.'
def _raise_error(self, condition, explanation=None, *args):
error = _condition_map.get(condition, condition) if (error in self._ignored_flags): return error().handle(self, *args) self.flags[error] = 1 if (not self.traps[error]): return condition().handle(self, *args) raise error(explanation)
'Ignore all flags, if they are raised'
def _ignore_all_flags(self):
return self._ignore_flags(*_signals)
'Ignore the flags, if they are raised'
def _ignore_flags(self, *flags):
self._ignored_flags = (self._ignored_flags + list(flags)) return list(flags)
'Stop ignoring the flags, if they are raised'
def _regard_flags(self, *flags):
if (flags and isinstance(flags[0], (tuple, list))): flags = flags[0] for flag in flags: self._ignored_flags.remove(flag)
'Returns Etiny (= Emin - prec + 1)'
def Etiny(self):
return int(((self.Emin - self.prec) + 1))
'Returns maximum exponent (= Emax - prec + 1)'
def Etop(self):
return int(((self.Emax - self.prec) + 1))
'Sets the rounding type. Sets the rounding type, and returns the current (previous) rounding type. Often used like: context = context.copy() # so you don\'t change the calling context # if an error occurs in the middle. rounding = context._set_rounding(ROUND_UP) val = self.__sub__(other, context=context) context._set_...
def _set_rounding(self, type):
rounding = self.rounding self.rounding = type return rounding
'Creates a new Decimal instance but using self as context. This method implements the to-number operation of the IBM Decimal specification.'
def create_decimal(self, num='0'):
if (isinstance(num, str) and (num != num.strip())): return self._raise_error(ConversionSyntax, 'no trailing or leading whitespace is permitted.') d = Decimal(num, context=self) if (d._isnan() and (len(d._int) > (self.prec - self.clamp))): return self._raise_error(Conversion...
'Creates a new Decimal instance from a float but rounding using self as the context. >>> context = Context(prec=5, rounding=ROUND_DOWN) >>> context.create_decimal_from_float(3.1415926535897932) Decimal(\'3.1415\') >>> context = Context(prec=5, traps=[Inexact]) >>> context.create_decimal_from_float(3.1415926535897932) T...
def create_decimal_from_float(self, f):
d = Decimal.from_float(f) return d._fix(self)
'Returns the absolute value of the operand. If the operand is negative, the result is the same as using the minus operation on the operand. Otherwise, the result is the same as using the plus operation on the operand. >>> ExtendedContext.abs(Decimal(\'2.1\')) Decimal(\'2.1\') >>> ExtendedContext.abs(Decimal(\'-100\'))...
def abs(self, a):
a = _convert_other(a, raiseit=True) return a.__abs__(context=self)
'Return the sum of the two operands. >>> ExtendedContext.add(Decimal(\'12\'), Decimal(\'7.00\')) Decimal(\'19.00\') >>> ExtendedContext.add(Decimal(\'1E+2\'), Decimal(\'1.01E+4\')) Decimal(\'1.02E+4\') >>> ExtendedContext.add(1, Decimal(2)) Decimal(\'3\') >>> ExtendedContext.add(Decimal(8), 5) Decimal(\'13\') >>> Exten...
def add(self, a, b):
a = _convert_other(a, raiseit=True) r = a.__add__(b, context=self) if (r is NotImplemented): raise TypeError(('Unable to convert %s to Decimal' % b)) else: return r
'Returns the same Decimal object. As we do not have different encodings for the same number, the received object already is in its canonical form. >>> ExtendedContext.canonical(Decimal(\'2.50\')) Decimal(\'2.50\')'
def canonical(self, a):
if (not isinstance(a, Decimal)): raise TypeError('canonical requires a Decimal as an argument.') return a.canonical()
'Compares values numerically. If the signs of the operands differ, a value representing each operand (\'-1\' if the operand is less than zero, \'0\' if the operand is zero or negative zero, or \'1\' if the operand is greater than zero) is used in place of that operand for the comparison instead of the actual operand. T...
def compare(self, a, b):
a = _convert_other(a, raiseit=True) return a.compare(b, context=self)
'Compares the values of the two operands numerically. It\'s pretty much like compare(), but all NaNs signal, with signaling NaNs taking precedence over quiet NaNs. >>> c = ExtendedContext >>> c.compare_signal(Decimal(\'2.1\'), Decimal(\'3\')) Decimal(\'-1\') >>> c.compare_signal(Decimal(\'2.1\'), Decimal(\'2.1\')) Deci...
def compare_signal(self, a, b):
a = _convert_other(a, raiseit=True) return a.compare_signal(b, context=self)
'Compares two operands using their abstract representation. This is not like the standard compare, which use their numerical value. Note that a total ordering is defined for all possible abstract representations. >>> ExtendedContext.compare_total(Decimal(\'12.73\'), Decimal(\'127.9\')) Decimal(\'-1\') >>> ExtendedConte...
def compare_total(self, a, b):
a = _convert_other(a, raiseit=True) return a.compare_total(b)
'Compares two operands using their abstract representation ignoring sign. Like compare_total, but with operand\'s sign ignored and assumed to be 0.'
def compare_total_mag(self, a, b):
a = _convert_other(a, raiseit=True) return a.compare_total_mag(b)
'Returns a copy of the operand with the sign set to 0. >>> ExtendedContext.copy_abs(Decimal(\'2.1\')) Decimal(\'2.1\') >>> ExtendedContext.copy_abs(Decimal(\'-100\')) Decimal(\'100\') >>> ExtendedContext.copy_abs(-1) Decimal(\'1\')'
def copy_abs(self, a):
a = _convert_other(a, raiseit=True) return a.copy_abs()
'Returns a copy of the decimal object. >>> ExtendedContext.copy_decimal(Decimal(\'2.1\')) Decimal(\'2.1\') >>> ExtendedContext.copy_decimal(Decimal(\'-1.00\')) Decimal(\'-1.00\') >>> ExtendedContext.copy_decimal(1) Decimal(\'1\')'
def copy_decimal(self, a):
a = _convert_other(a, raiseit=True) return Decimal(a)
'Returns a copy of the operand with the sign inverted. >>> ExtendedContext.copy_negate(Decimal(\'101.5\')) Decimal(\'-101.5\') >>> ExtendedContext.copy_negate(Decimal(\'-101.5\')) Decimal(\'101.5\') >>> ExtendedContext.copy_negate(1) Decimal(\'-1\')'
def copy_negate(self, a):
a = _convert_other(a, raiseit=True) return a.copy_negate()
'Copies the second operand\'s sign to the first one. In detail, it returns a copy of the first operand with the sign equal to the sign of the second operand. >>> ExtendedContext.copy_sign(Decimal( \'1.50\'), Decimal(\'7.33\')) Decimal(\'1.50\') >>> ExtendedContext.copy_sign(Decimal(\'-1.50\'), Decimal(\'7.33\')) Decima...
def copy_sign(self, a, b):
a = _convert_other(a, raiseit=True) return a.copy_sign(b)
'Decimal division in a specified context. >>> ExtendedContext.divide(Decimal(\'1\'), Decimal(\'3\')) Decimal(\'0.333333333\') >>> ExtendedContext.divide(Decimal(\'2\'), Decimal(\'3\')) Decimal(\'0.666666667\') >>> ExtendedContext.divide(Decimal(\'5\'), Decimal(\'2\')) Decimal(\'2.5\') >>> ExtendedContext.divide(Decimal...
def divide(self, a, b):
a = _convert_other(a, raiseit=True) r = a.__truediv__(b, context=self) if (r is NotImplemented): raise TypeError(('Unable to convert %s to Decimal' % b)) else: return r
'Divides two numbers and returns the integer part of the result. >>> ExtendedContext.divide_int(Decimal(\'2\'), Decimal(\'3\')) Decimal(\'0\') >>> ExtendedContext.divide_int(Decimal(\'10\'), Decimal(\'3\')) Decimal(\'3\') >>> ExtendedContext.divide_int(Decimal(\'1\'), Decimal(\'0.3\')) Decimal(\'3\') >>> ExtendedContex...
def divide_int(self, a, b):
a = _convert_other(a, raiseit=True) r = a.__floordiv__(b, context=self) if (r is NotImplemented): raise TypeError(('Unable to convert %s to Decimal' % b)) else: return r
'Return (a // b, a % b). >>> ExtendedContext.divmod(Decimal(8), Decimal(3)) (Decimal(\'2\'), Decimal(\'2\')) >>> ExtendedContext.divmod(Decimal(8), Decimal(4)) (Decimal(\'2\'), Decimal(\'0\')) >>> ExtendedContext.divmod(8, 4) (Decimal(\'2\'), Decimal(\'0\')) >>> ExtendedContext.divmod(Decimal(8), 4) (Decimal(\'2\'), De...
def divmod(self, a, b):
a = _convert_other(a, raiseit=True) r = a.__divmod__(b, context=self) if (r is NotImplemented): raise TypeError(('Unable to convert %s to Decimal' % b)) else: return r
'Returns e ** a. >>> c = ExtendedContext.copy() >>> c.Emin = -999 >>> c.Emax = 999 >>> c.exp(Decimal(\'-Infinity\')) Decimal(\'0\') >>> c.exp(Decimal(\'-1\')) Decimal(\'0.367879441\') >>> c.exp(Decimal(\'0\')) Decimal(\'1\') >>> c.exp(Decimal(\'1\')) Decimal(\'2.71828183\') >>> c.exp(Decimal(\'0.693147181\')) Decimal(\...
def exp(self, a):
a = _convert_other(a, raiseit=True) return a.exp(context=self)
'Returns a multiplied by b, plus c. The first two operands are multiplied together, using multiply, the third operand is then added to the result of that multiplication, using add, all with only one final rounding. >>> ExtendedContext.fma(Decimal(\'3\'), Decimal(\'5\'), Decimal(\'7\')) Decimal(\'22\') >>> ExtendedConte...
def fma(self, a, b, c):
a = _convert_other(a, raiseit=True) return a.fma(b, c, context=self)
'Return True if the operand is canonical; otherwise return False. Currently, the encoding of a Decimal instance is always canonical, so this method returns True for any Decimal. >>> ExtendedContext.is_canonical(Decimal(\'2.50\')) True'
def is_canonical(self, a):
if (not isinstance(a, Decimal)): raise TypeError('is_canonical requires a Decimal as an argument.') return a.is_canonical()
'Return True if the operand is finite; otherwise return False. A Decimal instance is considered finite if it is neither infinite nor a NaN. >>> ExtendedContext.is_finite(Decimal(\'2.50\')) True >>> ExtendedContext.is_finite(Decimal(\'-0.3\')) True >>> ExtendedContext.is_finite(Decimal(\'0\')) True >>> ExtendedContext.i...
def is_finite(self, a):
a = _convert_other(a, raiseit=True) return a.is_finite()
'Return True if the operand is infinite; otherwise return False. >>> ExtendedContext.is_infinite(Decimal(\'2.50\')) False >>> ExtendedContext.is_infinite(Decimal(\'-Inf\')) True >>> ExtendedContext.is_infinite(Decimal(\'NaN\')) False >>> ExtendedContext.is_infinite(1) False'
def is_infinite(self, a):
a = _convert_other(a, raiseit=True) return a.is_infinite()
'Return True if the operand is a qNaN or sNaN; otherwise return False. >>> ExtendedContext.is_nan(Decimal(\'2.50\')) False >>> ExtendedContext.is_nan(Decimal(\'NaN\')) True >>> ExtendedContext.is_nan(Decimal(\'-sNaN\')) True >>> ExtendedContext.is_nan(1) False'
def is_nan(self, a):
a = _convert_other(a, raiseit=True) return a.is_nan()
'Return True if the operand is a normal number; otherwise return False. >>> c = ExtendedContext.copy() >>> c.Emin = -999 >>> c.Emax = 999 >>> c.is_normal(Decimal(\'2.50\')) True >>> c.is_normal(Decimal(\'0.1E-999\')) False >>> c.is_normal(Decimal(\'0.00\')) False >>> c.is_normal(Decimal(\'-Inf\')) False >>> c.is_normal...
def is_normal(self, a):
a = _convert_other(a, raiseit=True) return a.is_normal(context=self)
'Return True if the operand is a quiet NaN; otherwise return False. >>> ExtendedContext.is_qnan(Decimal(\'2.50\')) False >>> ExtendedContext.is_qnan(Decimal(\'NaN\')) True >>> ExtendedContext.is_qnan(Decimal(\'sNaN\')) False >>> ExtendedContext.is_qnan(1) False'
def is_qnan(self, a):
a = _convert_other(a, raiseit=True) return a.is_qnan()
'Return True if the operand is negative; otherwise return False. >>> ExtendedContext.is_signed(Decimal(\'2.50\')) False >>> ExtendedContext.is_signed(Decimal(\'-12\')) True >>> ExtendedContext.is_signed(Decimal(\'-0\')) True >>> ExtendedContext.is_signed(8) False >>> ExtendedContext.is_signed(-8) True'
def is_signed(self, a):
a = _convert_other(a, raiseit=True) return a.is_signed()
'Return True if the operand is a signaling NaN; otherwise return False. >>> ExtendedContext.is_snan(Decimal(\'2.50\')) False >>> ExtendedContext.is_snan(Decimal(\'NaN\')) False >>> ExtendedContext.is_snan(Decimal(\'sNaN\')) True >>> ExtendedContext.is_snan(1) False'
def is_snan(self, a):
a = _convert_other(a, raiseit=True) return a.is_snan()
'Return True if the operand is subnormal; otherwise return False. >>> c = ExtendedContext.copy() >>> c.Emin = -999 >>> c.Emax = 999 >>> c.is_subnormal(Decimal(\'2.50\')) False >>> c.is_subnormal(Decimal(\'0.1E-999\')) True >>> c.is_subnormal(Decimal(\'0.00\')) False >>> c.is_subnormal(Decimal(\'-Inf\')) False >>> c.is_...
def is_subnormal(self, a):
a = _convert_other(a, raiseit=True) return a.is_subnormal(context=self)
'Return True if the operand is a zero; otherwise return False. >>> ExtendedContext.is_zero(Decimal(\'0\')) True >>> ExtendedContext.is_zero(Decimal(\'2.50\')) False >>> ExtendedContext.is_zero(Decimal(\'-0E+2\')) True >>> ExtendedContext.is_zero(1) False >>> ExtendedContext.is_zero(0) True'
def is_zero(self, a):
a = _convert_other(a, raiseit=True) return a.is_zero()
'Returns the natural (base e) logarithm of the operand. >>> c = ExtendedContext.copy() >>> c.Emin = -999 >>> c.Emax = 999 >>> c.ln(Decimal(\'0\')) Decimal(\'-Infinity\') >>> c.ln(Decimal(\'1.000\')) Decimal(\'0\') >>> c.ln(Decimal(\'2.71828183\')) Decimal(\'1.00000000\') >>> c.ln(Decimal(\'10\')) Decimal(\'2.30258509\'...
def ln(self, a):
a = _convert_other(a, raiseit=True) return a.ln(context=self)
'Returns the base 10 logarithm of the operand. >>> c = ExtendedContext.copy() >>> c.Emin = -999 >>> c.Emax = 999 >>> c.log10(Decimal(\'0\')) Decimal(\'-Infinity\') >>> c.log10(Decimal(\'0.001\')) Decimal(\'-3\') >>> c.log10(Decimal(\'1.000\')) Decimal(\'0\') >>> c.log10(Decimal(\'2\')) Decimal(\'0.301029996\') >>> c.lo...
def log10(self, a):
a = _convert_other(a, raiseit=True) return a.log10(context=self)
'Returns the exponent of the magnitude of the operand\'s MSD. The result is the integer which is the exponent of the magnitude of the most significant digit of the operand (as though the operand were truncated to a single digit while maintaining the value of that digit and without limiting the resulting exponent). >>> ...
def logb(self, a):
a = _convert_other(a, raiseit=True) return a.logb(context=self)
'Applies the logical operation \'and\' between each operand\'s digits. The operands must be both logical numbers. >>> ExtendedContext.logical_and(Decimal(\'0\'), Decimal(\'0\')) Decimal(\'0\') >>> ExtendedContext.logical_and(Decimal(\'0\'), Decimal(\'1\')) Decimal(\'0\') >>> ExtendedContext.logical_and(Decimal(\'1\'), ...
def logical_and(self, a, b):
a = _convert_other(a, raiseit=True) return a.logical_and(b, context=self)
'Invert all the digits in the operand. The operand must be a logical number. >>> ExtendedContext.logical_invert(Decimal(\'0\')) Decimal(\'111111111\') >>> ExtendedContext.logical_invert(Decimal(\'1\')) Decimal(\'111111110\') >>> ExtendedContext.logical_invert(Decimal(\'111111111\')) Decimal(\'0\') >>> ExtendedContext.l...
def logical_invert(self, a):
a = _convert_other(a, raiseit=True) return a.logical_invert(context=self)
'Applies the logical operation \'or\' between each operand\'s digits. The operands must be both logical numbers. >>> ExtendedContext.logical_or(Decimal(\'0\'), Decimal(\'0\')) Decimal(\'0\') >>> ExtendedContext.logical_or(Decimal(\'0\'), Decimal(\'1\')) Decimal(\'1\') >>> ExtendedContext.logical_or(Decimal(\'1\'), Deci...
def logical_or(self, a, b):
a = _convert_other(a, raiseit=True) return a.logical_or(b, context=self)
'Applies the logical operation \'xor\' between each operand\'s digits. The operands must be both logical numbers. >>> ExtendedContext.logical_xor(Decimal(\'0\'), Decimal(\'0\')) Decimal(\'0\') >>> ExtendedContext.logical_xor(Decimal(\'0\'), Decimal(\'1\')) Decimal(\'1\') >>> ExtendedContext.logical_xor(Decimal(\'1\'), ...
def logical_xor(self, a, b):
a = _convert_other(a, raiseit=True) return a.logical_xor(b, context=self)
'max compares two values numerically and returns the maximum. If either operand is a NaN then the general rules apply. Otherwise, the operands are compared as though by the compare operation. If they are numerically equal then the left-hand operand is chosen as the result. Otherwise the maximum (closer to positive in...
def max(self, a, b):
a = _convert_other(a, raiseit=True) return a.max(b, context=self)
'Compares the values numerically with their sign ignored. >>> ExtendedContext.max_mag(Decimal(\'7\'), Decimal(\'NaN\')) Decimal(\'7\') >>> ExtendedContext.max_mag(Decimal(\'7\'), Decimal(\'-10\')) Decimal(\'-10\') >>> ExtendedContext.max_mag(1, -2) Decimal(\'-2\') >>> ExtendedContext.max_mag(Decimal(1), -2) Decimal(\'-...
def max_mag(self, a, b):
a = _convert_other(a, raiseit=True) return a.max_mag(b, context=self)
'min compares two values numerically and returns the minimum. If either operand is a NaN then the general rules apply. Otherwise, the operands are compared as though by the compare operation. If they are numerically equal then the left-hand operand is chosen as the result. Otherwise the minimum (closer to negative in...
def min(self, a, b):
a = _convert_other(a, raiseit=True) return a.min(b, context=self)
'Compares the values numerically with their sign ignored. >>> ExtendedContext.min_mag(Decimal(\'3\'), Decimal(\'-2\')) Decimal(\'-2\') >>> ExtendedContext.min_mag(Decimal(\'-3\'), Decimal(\'NaN\')) Decimal(\'-3\') >>> ExtendedContext.min_mag(1, -2) Decimal(\'1\') >>> ExtendedContext.min_mag(Decimal(1), -2) Decimal(\'1\...
def min_mag(self, a, b):
a = _convert_other(a, raiseit=True) return a.min_mag(b, context=self)
'Minus corresponds to unary prefix minus in Python. The operation is evaluated using the same rules as subtract; the operation minus(a) is calculated as subtract(\'0\', a) where the \'0\' has the same exponent as the operand. >>> ExtendedContext.minus(Decimal(\'1.3\')) Decimal(\'-1.3\') >>> ExtendedContext.minus(Decima...
def minus(self, a):
a = _convert_other(a, raiseit=True) return a.__neg__(context=self)
'multiply multiplies two operands. If either operand is a special value then the general rules apply. Otherwise, the operands are multiplied together (\'long multiplication\'), resulting in a number which may be as long as the sum of the lengths of the two operands. >>> ExtendedContext.multiply(Decimal(\'1.20\'), Decim...
def multiply(self, a, b):
a = _convert_other(a, raiseit=True) r = a.__mul__(b, context=self) if (r is NotImplemented): raise TypeError(('Unable to convert %s to Decimal' % b)) else: return r
'Returns the largest representable number smaller than a. >>> c = ExtendedContext.copy() >>> c.Emin = -999 >>> c.Emax = 999 >>> ExtendedContext.next_minus(Decimal(\'1\')) Decimal(\'0.999999999\') >>> c.next_minus(Decimal(\'1E-1007\')) Decimal(\'0E-1007\') >>> ExtendedContext.next_minus(Decimal(\'-1.00000003\')) Decimal...
def next_minus(self, a):
a = _convert_other(a, raiseit=True) return a.next_minus(context=self)
'Returns the smallest representable number larger than a. >>> c = ExtendedContext.copy() >>> c.Emin = -999 >>> c.Emax = 999 >>> ExtendedContext.next_plus(Decimal(\'1\')) Decimal(\'1.00000001\') >>> c.next_plus(Decimal(\'-1E-1007\')) Decimal(\'-0E-1007\') >>> ExtendedContext.next_plus(Decimal(\'-1.00000003\')) Decimal(\...
def next_plus(self, a):
a = _convert_other(a, raiseit=True) return a.next_plus(context=self)
'Returns the number closest to a, in direction towards b. The result is the closest representable number from the first operand (but not the first operand) that is in the direction towards the second operand, unless the operands have the same value. >>> c = ExtendedContext.copy() >>> c.Emin = -999 >>> c.Emax = 999 >>> ...
def next_toward(self, a, b):
a = _convert_other(a, raiseit=True) return a.next_toward(b, context=self)
'normalize reduces an operand to its simplest form. Essentially a plus operation with all trailing zeros removed from the result. >>> ExtendedContext.normalize(Decimal(\'2.1\')) Decimal(\'2.1\') >>> ExtendedContext.normalize(Decimal(\'-2.0\')) Decimal(\'-2\') >>> ExtendedContext.normalize(Decimal(\'1.200\')) Decimal(\'...
def normalize(self, a):
a = _convert_other(a, raiseit=True) return a.normalize(context=self)
'Returns an indication of the class of the operand. The class is one of the following strings: -sNaN -NaN -Infinity -Normal -Subnormal -Zero +Zero +Subnormal +Normal +Infinity >>> c = ExtendedContext.copy() >>> c.Emin = -999 >>> c.Emax = 999 >>> c.number_class(Decimal(\'Infinity\')) \'+Infinity\' >>> c.number_class(Dec...
def number_class(self, a):
a = _convert_other(a, raiseit=True) return a.number_class(context=self)
'Plus corresponds to unary prefix plus in Python. The operation is evaluated using the same rules as add; the operation plus(a) is calculated as add(\'0\', a) where the \'0\' has the same exponent as the operand. >>> ExtendedContext.plus(Decimal(\'1.3\')) Decimal(\'1.3\') >>> ExtendedContext.plus(Decimal(\'-1.3\')) Dec...
def plus(self, a):
a = _convert_other(a, raiseit=True) return a.__pos__(context=self)
'Raises a to the power of b, to modulo if given. With two arguments, compute a**b. If a is negative then b must be integral. The result will be inexact unless b is integral and the result is finite and can be expressed exactly in \'precision\' digits. With three arguments, compute (a**b) % modulo. For the three argu...
def power(self, a, b, modulo=None):
a = _convert_other(a, raiseit=True) r = a.__pow__(b, modulo, context=self) if (r is NotImplemented): raise TypeError(('Unable to convert %s to Decimal' % b)) else: return r
'Returns a value equal to \'a\' (rounded), having the exponent of \'b\'. The coefficient of the result is derived from that of the left-hand operand. It may be rounded using the current rounding setting (if the exponent is being increased), multiplied by a positive power of ten (if the exponent is being decreased), or...
def quantize(self, a, b):
a = _convert_other(a, raiseit=True) return a.quantize(b, context=self)
'Just returns 10, as this is Decimal, :) >>> ExtendedContext.radix() Decimal(\'10\')'
def radix(self):
return Decimal(10)
'Returns the remainder from integer division. The result is the residue of the dividend after the operation of calculating integer division as described for divide-integer, rounded to precision digits if necessary. The sign of the result, if non-zero, is the same as that of the original dividend. This operation will f...
def remainder(self, a, b):
a = _convert_other(a, raiseit=True) r = a.__mod__(b, context=self) if (r is NotImplemented): raise TypeError(('Unable to convert %s to Decimal' % b)) else: return r
'Returns to be "a - b * n", where n is the integer nearest the exact value of "x / b" (if two integers are equally near then the even one is chosen). If the result is equal to 0 then its sign will be the sign of a. This operation will fail under the same conditions as integer division (that is, if integer division on ...
def remainder_near(self, a, b):
a = _convert_other(a, raiseit=True) return a.remainder_near(b, context=self)
'Returns a rotated copy of a, b times. The coefficient of the result is a rotated copy of the digits in the coefficient of the first operand. The number of places of rotation is taken from the absolute value of the second operand, with the rotation being to the left if the second operand is positive or to the right ot...
def rotate(self, a, b):
a = _convert_other(a, raiseit=True) return a.rotate(b, context=self)
'Returns True if the two operands have the same exponent. The result is never affected by either the sign or the coefficient of either operand. >>> ExtendedContext.same_quantum(Decimal(\'2.17\'), Decimal(\'0.001\')) False >>> ExtendedContext.same_quantum(Decimal(\'2.17\'), Decimal(\'0.01\')) True >>> ExtendedContext.sa...
def same_quantum(self, a, b):
a = _convert_other(a, raiseit=True) return a.same_quantum(b)
'Returns the first operand after adding the second value its exp. >>> ExtendedContext.scaleb(Decimal(\'7.50\'), Decimal(\'-2\')) Decimal(\'0.0750\') >>> ExtendedContext.scaleb(Decimal(\'7.50\'), Decimal(\'0\')) Decimal(\'7.50\') >>> ExtendedContext.scaleb(Decimal(\'7.50\'), Decimal(\'3\')) Decimal(\'7.50E+3\') >>> Exte...
def scaleb(self, a, b):
a = _convert_other(a, raiseit=True) return a.scaleb(b, context=self)
'Returns a shifted copy of a, b times. The coefficient of the result is a shifted copy of the digits in the coefficient of the first operand. The number of places to shift is taken from the absolute value of the second operand, with the shift being to the left if the second operand is positive or to the right otherwis...
def shift(self, a, b):
a = _convert_other(a, raiseit=True) return a.shift(b, context=self)
'Square root of a non-negative number to context precision. If the result must be inexact, it is rounded using the round-half-even algorithm. >>> ExtendedContext.sqrt(Decimal(\'0\')) Decimal(\'0\') >>> ExtendedContext.sqrt(Decimal(\'-0\')) Decimal(\'-0\') >>> ExtendedContext.sqrt(Decimal(\'0.39\')) Decimal(\'0.62449980...
def sqrt(self, a):
a = _convert_other(a, raiseit=True) return a.sqrt(context=self)
'Return the difference between the two operands. >>> ExtendedContext.subtract(Decimal(\'1.3\'), Decimal(\'1.07\')) Decimal(\'0.23\') >>> ExtendedContext.subtract(Decimal(\'1.3\'), Decimal(\'1.30\')) Decimal(\'0.00\') >>> ExtendedContext.subtract(Decimal(\'1.3\'), Decimal(\'2.07\')) Decimal(\'-0.77\') >>> ExtendedContex...
def subtract(self, a, b):
a = _convert_other(a, raiseit=True) r = a.__sub__(b, context=self) if (r is NotImplemented): raise TypeError(('Unable to convert %s to Decimal' % b)) else: return r
'Converts a number to a string, using scientific notation. The operation is not affected by the context.'
def to_eng_string(self, a):
a = _convert_other(a, raiseit=True) return a.to_eng_string(context=self)
'Converts a number to a string, using scientific notation. The operation is not affected by the context.'
def to_sci_string(self, a):
a = _convert_other(a, raiseit=True) return a.__str__(context=self)
'Rounds to an integer. When the operand has a negative exponent, the result is the same as using the quantize() operation using the given operand as the left-hand-operand, 1E+0 as the right-hand-operand, and the precision of the operand as the precision setting; Inexact and Rounded flags are allowed in this operation. ...
def to_integral_exact(self, a):
a = _convert_other(a, raiseit=True) return a.to_integral_exact(context=self)
'Rounds to an integer. When the operand has a negative exponent, the result is the same as using the quantize() operation using the given operand as the left-hand-operand, 1E+0 as the right-hand-operand, and the precision of the operand as the precision setting, except that no flags will be set. The rounding mode is t...
def to_integral_value(self, a):
a = _convert_other(a, raiseit=True) return a.to_integral_value(context=self)
'Given an integer p >= 0, return floor(10**p)*log(10). For example, self.getdigits(3) returns 2302.'
def getdigits(self, p):
if (p < 0): raise ValueError('p should be nonnegative') if (p >= len(self.digits)): extra = 3 while True: M = (10 ** ((p + extra) + 2)) digits = str(_div_nearest(_ilog((10 * M), M), 100)) if (digits[(- extra):] != ('0' * extra)): ...
'Join the two paths represented by the respective (drive, root, parts) tuples. Return a new (drive, root, parts) tuple.'
def join_parsed_parts(self, drv, root, parts, drv2, root2, parts2):
if root2: if ((not drv2) and drv): return (drv, root2, ([(drv + root2)] + parts2[1:])) elif drv2: if ((drv2 == drv) or (self.casefold(drv2) == self.casefold(drv))): return (drv, root, (parts + parts2[1:])) else: return (drv, root, (parts + parts2)) return ...
'Iterate over all child paths of `parent_path` matched by this selector. This can contain parent_path itself.'
def select_from(self, parent_path):
path_cls = type(parent_path) is_dir = path_cls.is_dir exists = path_cls.exists listdir = parent_path._accessor.listdir return self._select_from(parent_path, is_dir, exists, listdir)
'Construct a PurePath from one or several strings and or existing PurePath objects. The strings and path objects are combined so as to yield a canonicalized path, which is incorporated into the new PurePath object.'
def __new__(cls, *args):
if (cls is PurePath): cls = (PureWindowsPath if (os.name == 'nt') else PurePosixPath) return cls._from_parts(args)
'Return the string representation of the path, suitable for passing to system calls.'
def __str__(self):
try: return self._str except AttributeError: self._str = (self._format_parsed_parts(self._drv, self._root, self._parts) or '.') return self._str
'Return the string representation of the path with forward (/) slashes.'
def as_posix(self):
f = self._flavour return str(self).replace(f.sep, '/')
'Return the bytes representation of the path. This is only recommended to use under Unix.'
def __bytes__(self):
return os.fsencode(str(self))
'Return the path as a \'file\' URI.'
def as_uri(self):
if (not self.is_absolute()): raise ValueError("relative path can't be expressed as a file URI") return self._flavour.make_uri(self)
'The concatenation of the drive and root, or \'\'.'
@property def anchor(self):
anchor = (self._drv + self._root) return anchor