Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python3....
File: fractions.py
"""abs(a)"""
[500] Fix | Delete
return Fraction(abs(a._numerator), a._denominator, _normalize=False)
[501] Fix | Delete
[502] Fix | Delete
def __trunc__(a):
[503] Fix | Delete
"""trunc(a)"""
[504] Fix | Delete
if a._numerator < 0:
[505] Fix | Delete
return -(-a._numerator // a._denominator)
[506] Fix | Delete
else:
[507] Fix | Delete
return a._numerator // a._denominator
[508] Fix | Delete
[509] Fix | Delete
def __floor__(a):
[510] Fix | Delete
"""Will be math.floor(a) in 3.0."""
[511] Fix | Delete
return a.numerator // a.denominator
[512] Fix | Delete
[513] Fix | Delete
def __ceil__(a):
[514] Fix | Delete
"""Will be math.ceil(a) in 3.0."""
[515] Fix | Delete
# The negations cleverly convince floordiv to return the ceiling.
[516] Fix | Delete
return -(-a.numerator // a.denominator)
[517] Fix | Delete
[518] Fix | Delete
def __round__(self, ndigits=None):
[519] Fix | Delete
"""Will be round(self, ndigits) in 3.0.
[520] Fix | Delete
[521] Fix | Delete
Rounds half toward even.
[522] Fix | Delete
"""
[523] Fix | Delete
if ndigits is None:
[524] Fix | Delete
floor, remainder = divmod(self.numerator, self.denominator)
[525] Fix | Delete
if remainder * 2 < self.denominator:
[526] Fix | Delete
return floor
[527] Fix | Delete
elif remainder * 2 > self.denominator:
[528] Fix | Delete
return floor + 1
[529] Fix | Delete
# Deal with the half case:
[530] Fix | Delete
elif floor % 2 == 0:
[531] Fix | Delete
return floor
[532] Fix | Delete
else:
[533] Fix | Delete
return floor + 1
[534] Fix | Delete
shift = 10**abs(ndigits)
[535] Fix | Delete
# See _operator_fallbacks.forward to check that the results of
[536] Fix | Delete
# these operations will always be Fraction and therefore have
[537] Fix | Delete
# round().
[538] Fix | Delete
if ndigits > 0:
[539] Fix | Delete
return Fraction(round(self * shift), shift)
[540] Fix | Delete
else:
[541] Fix | Delete
return Fraction(round(self / shift) * shift)
[542] Fix | Delete
[543] Fix | Delete
def __hash__(self):
[544] Fix | Delete
"""hash(self)"""
[545] Fix | Delete
[546] Fix | Delete
# XXX since this method is expensive, consider caching the result
[547] Fix | Delete
[548] Fix | Delete
# In order to make sure that the hash of a Fraction agrees
[549] Fix | Delete
# with the hash of a numerically equal integer, float or
[550] Fix | Delete
# Decimal instance, we follow the rules for numeric hashes
[551] Fix | Delete
# outlined in the documentation. (See library docs, 'Built-in
[552] Fix | Delete
# Types').
[553] Fix | Delete
[554] Fix | Delete
# dinv is the inverse of self._denominator modulo the prime
[555] Fix | Delete
# _PyHASH_MODULUS, or 0 if self._denominator is divisible by
[556] Fix | Delete
# _PyHASH_MODULUS.
[557] Fix | Delete
dinv = pow(self._denominator, _PyHASH_MODULUS - 2, _PyHASH_MODULUS)
[558] Fix | Delete
if not dinv:
[559] Fix | Delete
hash_ = _PyHASH_INF
[560] Fix | Delete
else:
[561] Fix | Delete
hash_ = abs(self._numerator) * dinv % _PyHASH_MODULUS
[562] Fix | Delete
result = hash_ if self >= 0 else -hash_
[563] Fix | Delete
return -2 if result == -1 else result
[564] Fix | Delete
[565] Fix | Delete
def __eq__(a, b):
[566] Fix | Delete
"""a == b"""
[567] Fix | Delete
if type(b) is int:
[568] Fix | Delete
return a._numerator == b and a._denominator == 1
[569] Fix | Delete
if isinstance(b, numbers.Rational):
[570] Fix | Delete
return (a._numerator == b.numerator and
[571] Fix | Delete
a._denominator == b.denominator)
[572] Fix | Delete
if isinstance(b, numbers.Complex) and b.imag == 0:
[573] Fix | Delete
b = b.real
[574] Fix | Delete
if isinstance(b, float):
[575] Fix | Delete
if math.isnan(b) or math.isinf(b):
[576] Fix | Delete
# comparisons with an infinity or nan should behave in
[577] Fix | Delete
# the same way for any finite a, so treat a as zero.
[578] Fix | Delete
return 0.0 == b
[579] Fix | Delete
else:
[580] Fix | Delete
return a == a.from_float(b)
[581] Fix | Delete
else:
[582] Fix | Delete
# Since a doesn't know how to compare with b, let's give b
[583] Fix | Delete
# a chance to compare itself with a.
[584] Fix | Delete
return NotImplemented
[585] Fix | Delete
[586] Fix | Delete
def _richcmp(self, other, op):
[587] Fix | Delete
"""Helper for comparison operators, for internal use only.
[588] Fix | Delete
[589] Fix | Delete
Implement comparison between a Rational instance `self`, and
[590] Fix | Delete
either another Rational instance or a float `other`. If
[591] Fix | Delete
`other` is not a Rational instance or a float, return
[592] Fix | Delete
NotImplemented. `op` should be one of the six standard
[593] Fix | Delete
comparison operators.
[594] Fix | Delete
[595] Fix | Delete
"""
[596] Fix | Delete
# convert other to a Rational instance where reasonable.
[597] Fix | Delete
if isinstance(other, numbers.Rational):
[598] Fix | Delete
return op(self._numerator * other.denominator,
[599] Fix | Delete
self._denominator * other.numerator)
[600] Fix | Delete
if isinstance(other, float):
[601] Fix | Delete
if math.isnan(other) or math.isinf(other):
[602] Fix | Delete
return op(0.0, other)
[603] Fix | Delete
else:
[604] Fix | Delete
return op(self, self.from_float(other))
[605] Fix | Delete
else:
[606] Fix | Delete
return NotImplemented
[607] Fix | Delete
[608] Fix | Delete
def __lt__(a, b):
[609] Fix | Delete
"""a < b"""
[610] Fix | Delete
return a._richcmp(b, operator.lt)
[611] Fix | Delete
[612] Fix | Delete
def __gt__(a, b):
[613] Fix | Delete
"""a > b"""
[614] Fix | Delete
return a._richcmp(b, operator.gt)
[615] Fix | Delete
[616] Fix | Delete
def __le__(a, b):
[617] Fix | Delete
"""a <= b"""
[618] Fix | Delete
return a._richcmp(b, operator.le)
[619] Fix | Delete
[620] Fix | Delete
def __ge__(a, b):
[621] Fix | Delete
"""a >= b"""
[622] Fix | Delete
return a._richcmp(b, operator.ge)
[623] Fix | Delete
[624] Fix | Delete
def __bool__(a):
[625] Fix | Delete
"""a != 0"""
[626] Fix | Delete
return a._numerator != 0
[627] Fix | Delete
[628] Fix | Delete
# support for pickling, copy, and deepcopy
[629] Fix | Delete
[630] Fix | Delete
def __reduce__(self):
[631] Fix | Delete
return (self.__class__, (str(self),))
[632] Fix | Delete
[633] Fix | Delete
def __copy__(self):
[634] Fix | Delete
if type(self) == Fraction:
[635] Fix | Delete
return self # I'm immutable; therefore I am my own clone
[636] Fix | Delete
return self.__class__(self._numerator, self._denominator)
[637] Fix | Delete
[638] Fix | Delete
def __deepcopy__(self, memo):
[639] Fix | Delete
if type(self) == Fraction:
[640] Fix | Delete
return self # My components are also immutable
[641] Fix | Delete
return self.__class__(self._numerator, self._denominator)
[642] Fix | Delete
[643] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function