b374k
m1n1 1.01
Apache/2.2.15 (CentOS)
Linux obd60-6c49958d75-2q7cw 5.4.0-174-generic #193-Ubuntu SMP Thu Mar 7 14:29:28 UTC 2024 x86_64
uid=48(apache) gid=48(apache) groups=48(apache)
server ip : 104.21.65.202 | your ip : 10.244.126.0
safemode OFF
 >  / usr / lib64 / python2.6 /
Filename/usr/lib64/python2.6/fractions.pyo
Size17.69 kb
Permissionrw-r--r--
Ownerapache
Create time23-Dec-2025 17:41
Last modified20-Jun-2019 19:45
Last accessed22-Apr-2026 05:28
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
Ñò
§ÚêLc@ s�dZddklZddkZddkZddkZddkZddgZeiZd�Z ei
dei �Z defd��YZ
dS( s+Rational, infinite-precision, real numbers.iÿÿÿÿ(tdivisionNtFractiontgcdcC s$x|o|||}}qW|S(s¶Calculate the Greatest Common Divisor of a and b.

Unless b==0, the result will have the same sign as b (so that when
b is divided by it, the result comes out positive).
((tatb((s!/usr/lib64/python2.6/fractions.pyRss
\A\s* # optional whitespace at the start, then
(?P<sign>[-+]?) # an optional sign, then
(?=\d|\.\d) # lookahead for digit or .digit
(?P<num>\d*) # numerator (possibly empty)
(?: # followed by an optional
/(?P<denom>\d+) # / and denominator
| # or
\.(?P<decimal>\d*) # decimal point and fractional part
)?
\s*\Z # and optional whitespace to finish
cB sßeZdZd(Zddd�Zed��Zed��Zdd �Ze d
��Z
e d ��Z d �Z d
�Z
d�Zd�Zeeei�\ZZd�Zeeei�\ZZd�Zeeei�\ZZd�Zeeei�\ZZeeei �\Z!Z"d�Z#d�Z$d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*d�Z+d�Z,d�Z-d�Z.d�Z/d �Z0d!�Z1d"�Z2d#�Z3d$�Z4d%�Z5d&�Z6d'�Z7RS()s�This class implements rational numbers.

Fraction(8, 6) will produce a rational number equivalent to
4/3. Both arguments must be Integral. The numerator defaults to 0
and the denominator defaults to 1 so that Fraction(3) == 3 and
Fraction() == 0.

Fractions can also be constructed from strings of the form
'[-+]?[0-9]+((/|.)[0-9]+)?', optionally surrounded by spaces.

t
_numeratort _denominatoriic C s¶tt|�i|�}t|�ttfjo|djo t|t�oÌ|}ti |�}|d jot d|��n|i d�}|i d�}|o$t||�}dt
|�}n)t|�}t|i d�pd�}|i d�djo | }qFqJt|t�o|}|i}|i}qJn|d jotd
|��nti|�}ti|�}t||�}|||_|||_|S( s�Constructs a Fraction.

Takes a string like '3/2' or '1.5', another Fraction, or a
numerator/denominator pair.

is Invalid literal for Fraction: %rtnumtdecimali
tdenomtsignt-isFraction(%s, 0)N(tsuperRt__new__ttypetinttlongt
isinstancet
basestringt_RATIONAL_FORMATtmatchtNonet
ValueErrortgrouptlentRationalt numeratort denominatortZeroDivisionErrortoperatortindexRRR( tclsRRtselftinputtmRtother_rationaltg((s!/usr/lib64/python2.6/fractions.pyR
:s8&
  


cC s¤t|ti�o ||�St|t�p)td|i|t|�if��nti|�pti |�otd||if��n||i
��S(s�Converts a finite float to a rational number, exactly.

Beware that Fraction.from_float(0.3) != Fraction(3, 10).

s.%s.from_float() only takes floats, not %r (%s)sCannot convert %r to %s.( RtnumberstIntegraltfloatt TypeErrort__name__Rtmathtisnantisinftas_integer_ratio(Rtf((s!/usr/lib64/python2.6/fractions.pyt
from_floatjs # cC sddkl}t|ti�o|t|��}n:t||�p)td|i|t|�if��n|i �ptd||if��n|i
�\}}}tdi t t
|���}|o | }n|djo||d|�S||d| �SdS( sAConverts a finite Decimal instance to a rational number, exactly.iÿÿÿÿ(tDecimals2%s.from_decimal() only takes Decimals, not %r (%s)sCannot convert %s to %s.tii
N(RR0RR%R&RR(R)Rt is_finitetas_tupletjointmaptstr(RtdecR0R
tdigitstexp((s!/usr/lib64/python2.6/fractions.pyt from_decimalzs #
 
i@Bc
C s;|djotd��n|i|jo t|�Sd\}}}}|i|i}}xqtoi||}|||} | |joPn|||||| f\}}}}||||}}q`W|||}
t||
|||
|�} t||�} t| |�t| |�jo| S| SdS(sWClosest Fraction to self with denominator at most max_denominator.

>>> Fraction('3.141592653589793').limit_denominator(10)
Fraction(22, 7)
>>> Fraction('3.141592653589793').limit_denominator(100)
Fraction(311, 99)
>>> Fraction(4321, 8765).limit_denominator(10000)
Fraction(4321, 8765)

is$max_denominator should be at least 1iN(iiii(RRRRtTruetabs(
R tmax_denominatortp0tq0tp1tq1tntdRtq2tktbound1tbound2((s!/usr/lib64/python2.6/fractions.pytlimit_denominator�s(
 

&!cC s|iS(N(R(R((s!/usr/lib64/python2.6/fractions.pyRÇscC s|iS(N(R(R((s!/usr/lib64/python2.6/fractions.pyRËscC sd|i|ifS(s
repr(self)sFraction(%s, %s)(RR(R ((s!/usr/lib64/python2.6/fractions.pyt__repr__ÏscC s6|idjot|i�Sd|i|ifSdS(s str(self)is%s/%sN(RR6R(R ((s!/usr/lib64/python2.6/fractions.pyt__str__Ósc sn��fd�}d�id|_�i|_��fd�}d�id|_�i|_||fS(sÓGenerates forward and reverse operators given a purely-rational
operator and a function from the operator module.

Use this like:
__op__, __rop__ = _operator_fallbacks(just_rational_op, operator.op)

In general, we want to implement the arithmetic operations so
that mixed-mode operations either call an implementation whose
author knew about the types of both arguments, or convert both
to the nearest built in type and do the operation there. In
Fraction, that means that we define __add__ and __radd__ as:

def __add__(self, other):
# Both types have numerators/denominator attributes,
# so do the operation directly
if isinstance(other, (int, long, Fraction)):
return Fraction(self.numerator * other.denominator +
other.numerator * self.denominator,
self.denominator * other.denominator)
# float and complex don't have those operations, but we
# know about those types, so special case them.
elif isinstance(other, float):
return float(self) + other
elif isinstance(other, complex):
return complex(self) + other
# Let the other type take over.
return NotImplemented

def __radd__(self, other):
# radd handles more types than add because there's
# nothing left to fall back to.
if isinstance(other, Rational):
return Fraction(self.numerator * other.denominator +
other.numerator * self.denominator,
self.denominator * other.denominator)
elif isinstance(other, Real):
return float(other) + float(self)
elif isinstance(other, Complex):
return complex(other) + complex(self)
return NotImplemented


There are 5 different cases for a mixed-type addition on
Fraction. I'll refer to all of the above code that doesn't
refer to Fraction, float, or complex as "boilerplate". 'r'
will be an instance of Fraction, which is a subtype of
Rational (r : Fraction <: Rational), and b : B <:
Complex. The first three involve 'r + b':

1. If B <: Fraction, int, float, or complex, we handle
that specially, and all is well.
2. If Fraction falls back to the boilerplate code, and it
were to return a value from __add__, we'd miss the
possibility that B defines a more intelligent __radd__,
so the boilerplate should return NotImplemented from
__add__. In particular, we don't handle Rational
here, even though we could get an exact answer, in case
the other type wants to do something special.
3. If B <: Fraction, Python tries B.__radd__ before
Fraction.__add__. This is ok, because it was
implemented with knowledge of Fraction, so it can
handle those instances before delegating to Real or
Complex.

The next two situations describe 'b + r'. We assume that b
didn't know about Fraction in its implementation, and that it
uses similar boilerplate code:

4. If B <: Rational, then __radd_ converts both to the
builtin rational type (hey look, that's us) and
proceeds.
5. Otherwise, __radd__ tries to find the nearest common
base ABC, and fall back to its builtin type. Since this
class doesn't subclass a concrete type, there's no
implementation to fall back to, so we need to try as
hard as possible to return an actual value, or the user
will get a TypeError.

c swt|tttf�o�||�St|t�o�t|�|�St|t�o�t|�|�StSdS(N(RRRRR'tcomplextNotImplemented(RR(tfallback_operatortmonomorphic_operator(s!/usr/lib64/python2.6/fractions.pytforward*st__c s�t|t�o�||�St|ti�o�t|�t|��St|ti�o�t|�t|��StSdS(N(RRR%tRealR'tComplexRKRL(RR(RMRN(s!/usr/lib64/python2.6/fractions.pytreverse6st__r(R)t__doc__(RNRMRORS((RMRNs!/usr/lib64/python2.6/fractions.pyt_operator_fallbacksÚsP  
 cC s/t|i|i|i|i|i|i�S(sa + b(RRR(RR((s!/usr/lib64/python2.6/fractions.pyt_addEscC s/t|i|i|i|i|i|i�S(sa - b(RRR(RR((s!/usr/lib64/python2.6/fractions.pyt_subMscC s!t|i|i|i|i�S(sa * b(RRR(RR((s!/usr/lib64/python2.6/fractions.pyt_mulUscC s!t|i|i|i|i�S(sa / b(RRR(RR((s!/usr/lib64/python2.6/fractions.pyt_div[scC s:||}t|t�o|i|iSti|�SdS(sa // bN(RRRRR*tfloor(RRtdiv((s!/usr/lib64/python2.6/fractions.pyt __floordiv__cs
cC s:||}t|t�o|i|iSti|�SdS(sa // bN(RRRRR*R[(RRR\((s!/usr/lib64/python2.6/fractions.pyt
__rfloordiv__os
cC s||}|||S(sa % b((RRR\((s!/usr/lib64/python2.6/fractions.pyt__mod__{s
cC s||}|||S(sa % b((RRR\((s!/usr/lib64/python2.6/fractions.pyt__rmod__�s
cC s�t|t�o{|idjoS|i}|djot|i||i|�St|i| |i| �Sq�t|�t|�Snt|�|SdS(s¾a ** b

If b is not an integer, the result will be a float or complex
since roots are generally irrational. If b is an integer, the
result will be rational.

iiN(RRRRRRRR'(RRtpower((s!/usr/lib64/python2.6/fractions.pyt__pow__�s 

cC s~|idjo|idjo ||iSt|t�ot|i|i�|S|idjo ||iS|t|�S(sa ** bii(RRRRRRRR'(RR((s!/usr/lib64/python2.6/fractions.pyt__rpow__�s   cC st|i|i�S(s++a: Coerces a subclass instance to Fraction(RRR(R((s!/usr/lib64/python2.6/fractions.pyt__pos__«scC st|i |i�S(s-a(RRR(R((s!/usr/lib64/python2.6/fractions.pyt__neg__¯scC stt|i�|i�S(sabs(a)(RR<RR(R((s!/usr/lib64/python2.6/fractions.pyt__abs__³scC s3|idjo|i |i S|i|iSdS(strunc(a)iN(RR(R((s!/usr/lib64/python2.6/fractions.pyt __trunc__·scC s\|idjot|i�S|t|�jott|��St|i|if�SdS(s�hash(self)

Tricky because values that are exactly representable as a
float must have the same hash as that float.

iN(RthashRR'(R ((s!/usr/lib64/python2.6/fractions.pyt__hash__¾s
cC s�t|t�o$|i|ijo|i|ijSt|ti�o|idjo
|i }nt|t
�o||i |�jSt
|�|jSdS(sa == biN( RRRRRRR%RRtimagtrealR'R/(RR((s!/usr/lib64/python2.6/fractions.pyt__eq__Ñs#
cC s¦t|ti�o|idjo
|i}nt|t�o|i|�}ny||}Wntj
otSXt|t �o||i
d�S||d�S(sHelper function for comparison operators.

Subtracts b from a, exactly if possible, and compares the
result with 0 using op, in such a way that the comparison
won't recurse. If the difference raises a TypeError, returns
NotImplemented instead.

i( RR%RRRjRkR'R/R(RLRR(RRtoptdiff((s!/usr/lib64/python2.6/fractions.pyt_subtractAndCompareToZeroàs #
cC s|i|ti�S(sa < b(RoRtlt(RR((s!/usr/lib64/python2.6/fractions.pyt__lt__úscC s|i|ti�S(sa > b(RoRtgt(RR((s!/usr/lib64/python2.6/fractions.pyt__gt__þscC s|i|ti�S(sa <= b(RoRtle(RR((s!/usr/lib64/python2.6/fractions.pyt__le__scC s|i|ti�S(sa >= b(RoRtge(RR((s!/usr/lib64/python2.6/fractions.pyt__ge__scC s
|idjS(sa != 0i(R(R((s!/usr/lib64/python2.6/fractions.pyt __nonzero__
scC s|it|�ffS(N(t __class__R6(R ((s!/usr/lib64/python2.6/fractions.pyt
__reduce__scC s.t|�tjo|S|i|i|i�S(N(RRRyRR(R ((s!/usr/lib64/python2.6/fractions.pyt__copy__scC s.t|�tjo|S|i|i|i�S(N(RRRyRR(R tmemo((s!/usr/lib64/python2.6/fractions.pyt __deepcopy__s(s
_numerators _denominator(8R)t
__module__RUt __slots__R
t classmethodR/R:RHtpropertyRRRIRJRVRWRtaddt__add__t__radd__RXtsubt__sub__t__rsub__RYtmult__mul__t__rmul__RZttruedivt __truediv__t __rtruediv__R\t__div__t__rdiv__R]R^R_R`RbRcRdReRfRgRiRlRoRqRsRuRwRxRzR{R}(((s!/usr/lib64/python2.6/fractions.pyR*sR 0 7   k                      (RUt
__future__RR*R%Rtret__all__RRtcompiletVERBOSERR(((s!/usr/lib64/python2.6/fractions.pyt<module>s