desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'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
'The final path component, if any.'
@property def name(self):
parts = self._parts if (len(parts) == (1 if (self._drv or self._root) else 0)): return '' return parts[(-1)]
'The final component\'s last suffix, if any.'
@property def suffix(self):
name = self.name i = name.rfind('.') if (0 < i < (len(name) - 1)): return name[i:] else: return ''
'A list of the final component\'s suffixes, if any.'
@property def suffixes(self):
name = self.name if name.endswith('.'): return [] name = name.lstrip('.') return [('.' + suffix) for suffix in name.split('.')[1:]]
'The final path component, minus its last suffix.'
@property def stem(self):
name = self.name i = name.rfind('.') if (0 < i < (len(name) - 1)): return name[:i] else: return name
'Return a new path with the file name changed.'
def with_name(self, name):
if (not self.name): raise ValueError(('%r has an empty name' % (self,))) (drv, root, parts) = self._flavour.parse_parts((name,)) if ((not name) or (name[(-1)] in [self._flavour.sep, self._flavour.altsep]) or drv or root or (len(parts) != 1)): raise ValueError(('Invalid name ...
'Return a new path with the file suffix changed (or added, if none).'
def with_suffix(self, suffix):
f = self._flavour if ((f.sep in suffix) or (f.altsep and (f.altsep in suffix))): raise ValueError(('Invalid suffix %r' % suffix)) if ((suffix and (not suffix.startswith('.'))) or (suffix == '.')): raise ValueError(('Invalid suffix %r' % suffix)) name = self.name if (not n...
'Return the relative path to another path identified by the passed arguments. If the operation is not possible (because this is not a subpath of the other path), raise ValueError.'
def relative_to(self, *other):
if (not other): raise TypeError('need at least one argument') parts = self._parts drv = self._drv root = self._root if root: abs_parts = ([drv, root] + parts[1:]) else: abs_parts = parts (to_drv, to_root, to_parts) = self._parse_args(other) if to_root:...
'An object providing sequence-like access to the components in the filesystem path.'
@property def parts(self):
try: return self._pparts except AttributeError: self._pparts = tuple(self._parts) return self._pparts
'Combine this path with one or several arguments, and return a new path representing either a subpath (if all arguments are relative paths) or a totally different path (if one of the arguments is anchored).'
def joinpath(self, *args):
return self._make_child(args)
'The logical parent of the path.'
@property def parent(self):
drv = self._drv root = self._root parts = self._parts if ((len(parts) == 1) and (drv or root)): return self return self._from_parsed_parts(drv, root, parts[:(-1)])
'A sequence of this path\'s logical parents.'
@property def parents(self):
return _PathParents(self)
'True if the path is absolute (has both a root and, if applicable, a drive).'
def is_absolute(self):
if (not self._root): return False return ((not self._flavour.has_drv) or bool(self._drv))
'Return True if the path contains one of the special names reserved by the system, if any.'
def is_reserved(self):
return self._flavour.is_reserved(self._parts)
'Return True if this path matches the given pattern.'
def match(self, path_pattern):
cf = self._flavour.casefold path_pattern = cf(path_pattern) (drv, root, pat_parts) = self._flavour.parse_parts((path_pattern,)) if (not pat_parts): raise ValueError('empty pattern') if (drv and (drv != cf(self._drv))): return False if (root and (root != cf(self._root))): ...
'Open the file pointed by this path and return a file descriptor, as os.open() does.'
def _raw_open(self, flags, mode=511):
if self._closed: self._raise_closed() return self._accessor.open(self, flags, mode)
'Return a new path pointing to the current working directory (as returned by os.getcwd()).'
@classmethod def cwd(cls):
return cls(os.getcwd())
'Iterate over the files in this directory. Does not yield any result for the special paths \'.\' and \'..\'.'
def iterdir(self):
if self._closed: self._raise_closed() for name in self._accessor.listdir(self): if (name in {'.', '..'}): continue (yield self._make_child_relpath(name)) if self._closed: self._raise_closed()
'Iterate over this subtree and yield all existing files (of any kind, including directories) matching the given pattern.'
def glob(self, pattern):
pattern = self._flavour.casefold(pattern) (drv, root, pattern_parts) = self._flavour.parse_parts((pattern,)) if (drv or root): raise NotImplementedError('Non-relative patterns are unsupported') selector = _make_selector(tuple(pattern_parts)) for p in selector.select_from(self): ...
'Recursively yield all existing files (of any kind, including directories) matching the given pattern, anywhere in this subtree.'
def rglob(self, pattern):
pattern = self._flavour.casefold(pattern) (drv, root, pattern_parts) = self._flavour.parse_parts((pattern,)) if (drv or root): raise NotImplementedError('Non-relative patterns are unsupported') selector = _make_selector((('**',) + tuple(pattern_parts))) for p in selector.select_from...
'Return an absolute version of this path. This function works even if the path doesn\'t point to anything. No normalization is done, i.e. all \'.\' and \'..\' will be kept along. Use resolve() to get the canonical path to a file.'
def absolute(self):
if self._closed: self._raise_closed() if self.is_absolute(): return self obj = self._from_parts(([os.getcwd()] + self._parts), init=False) obj._init(template=self) return obj
'Make the path absolute, resolving all symlinks on the way and also normalizing it (for example turning slashes into backslashes under Windows).'
def resolve(self):
if self._closed: self._raise_closed() s = self._flavour.resolve(self) if (s is None): self.stat() s = str(self.absolute()) normed = self._flavour.pathmod.normpath(s) obj = self._from_parts((normed,), init=False) obj._init(template=self) return obj
'Return the result of the stat() system call on this path, like os.stat() does.'
def stat(self):
return self._accessor.stat(self)
'Return the login name of the file owner.'
def owner(self):
import pwd return pwd.getpwuid(self.stat().st_uid).pw_name
'Return the group name of the file gid.'
def group(self):
import grp return grp.getgrgid(self.stat().st_gid).gr_name
'Open the file pointed by this path and return a file object, as the built-in open() function does.'
def open(self, mode='r', buffering=(-1), encoding=None, errors=None, newline=None):
if self._closed: self._raise_closed() return io.open(str(self), mode, buffering, encoding, errors, newline, opener=self._opener)
'Create this file with the given access mode, if it doesn\'t exist.'
def touch(self, mode=438, exist_ok=True):
if self._closed: self._raise_closed() if exist_ok: try: self._accessor.utime(self, None) except OSError: pass else: return flags = (os.O_CREAT | os.O_WRONLY) if (not exist_ok): flags |= os.O_EXCL fd = self._raw_open(flags, m...
'Change the permissions of the path, like os.chmod().'
def chmod(self, mode):
if self._closed: self._raise_closed() self._accessor.chmod(self, mode)
'Like chmod(), except if the path points to a symlink, the symlink\'s permissions are changed, rather than its target\'s.'
def lchmod(self, mode):
if self._closed: self._raise_closed() self._accessor.lchmod(self, mode)
'Remove this file or link. If the path is a directory, use rmdir() instead.'
def unlink(self):
if self._closed: self._raise_closed() self._accessor.unlink(self)
'Remove this directory. The directory must be empty.'
def rmdir(self):
if self._closed: self._raise_closed() self._accessor.rmdir(self)
'Like stat(), except if the path points to a symlink, the symlink\'s status information is returned, rather than its target\'s.'
def lstat(self):
if self._closed: self._raise_closed() return self._accessor.lstat(self)
'Rename this path to the given path.'
def rename(self, target):
if self._closed: self._raise_closed() self._accessor.rename(self, target)