tzh
2024-08-22 c7d0944258c7d0943aa7b2211498fd612971ce27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
L\¬Qc@ sªdZddlmZddlmZddlZddlZddlZddlZddgZ    ej
Z
d„Z ej dej ejBƒZde
fd    „ƒYZdS(
s+Rational, infinite-precision, real numbers.iÿÿÿÿ(tdivision(tDecimalNtFractiontgcdcC s"x|r|||}}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((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyRs    sC
    \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
       (?:/(?P<denom>\d+))?    # an optional denominator
    |                          # or
       (?:\.(?P<decimal>\d*))? # an optional fractional part
       (?:E(?P<exp>[-+]?\d+))? # and optional exponent
    )
    \s*\Z                      # and optional whitespace to finish
cB sßeZdZd'Zdd(d„Zed„ƒZed„ƒZdd„Z    e
d    „ƒZ e
d
„ƒZ d „Z d „Zd „Zd„Zeeejƒ\ZZd„Zeeejƒ\ZZd„Zeeejƒ\ZZd„Zeeejƒ\ZZ eeej!ƒ\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„Z0d„Z1d „Z2d!„Z3d"„Z4d#„Z5d$„Z6d%„Z7d&„Z8RS()s]This class implements rational numbers.
 
    In the two-argument form of the constructor, Fraction(8, 6) will
    produce a rational number equivalent to 4/3. Both arguments must
    be Rational. 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:
 
      - numeric strings similar to those accepted by the
        float constructor (for example, '-2.3' or '1e10')
 
      - strings of the form '123/456'
 
      - float and Decimal instances
 
      - other Rational instances (including integers)
 
    t
_numeratort _denominatoric C s¦tt|ƒj|ƒ}|dkr t|tƒrO|j|_|j|_    |St|t
ƒr‰tj |ƒ}|j|_|j    |_    |St|t ƒrÃtj |ƒ}|j|_|j    |_    |St|tƒrýtj|ƒ}|dkrtd|ƒ‚nt|jdƒpdƒ}|jdƒ}|r?t|ƒ}nœd}|jdƒ}|r‹dt|ƒ}||t|ƒ}||9}n|jdƒ}    |    rÛt|    ƒ}    |    d    krÉ|d|    9}qÛ|d|     9}n|jd
ƒd kr    | }q    qZtd ƒ‚nNt|tƒrNt|tƒrN|j|j|j|j}}n td ƒ‚|d    krytd|ƒ‚nt||ƒ}
||
|_||
|_    |S(s£Constructs a Fraction.
 
        Takes a string like '3/2' or '1.5', another Rational instance, a
        numerator/denominator pair, or a float.
 
        Examples
        --------
 
        >>> Fraction(10, -8)
        Fraction(-5, 4)
        >>> Fraction(Fraction(1, 7), 5)
        Fraction(1, 35)
        >>> Fraction(Fraction(1, 7), Fraction(2, 3))
        Fraction(3, 14)
        >>> Fraction('314')
        Fraction(314, 1)
        >>> Fraction('-35/4')
        Fraction(-35, 4)
        >>> Fraction('3.1415') # conversion from numeric string
        Fraction(6283, 2000)
        >>> Fraction('-47e-2') # string may include a decimal exponent
        Fraction(-47, 100)
        >>> Fraction(1.47)  # direct construction from float (exact conversion)
        Fraction(6620291452234629, 4503599627370496)
        >>> Fraction(2.25)
        Fraction(9, 4)
        >>> Fraction(Decimal('1.47'))
        Fraction(147, 100)
 
        s Invalid literal for Fraction: %rtnumt0tdenomitdecimali
texpitsignt-s2argument should be a string or a Rational instances+both arguments should be Rational instancessFraction(%s, 0)N(tsuperRt__new__tNonet
isinstancetRationalt    numeratorRt denominatorRtfloatt
from_floatRt from_decimalt
basestringt_RATIONAL_FORMATtmatcht
ValueErrortinttgrouptlent    TypeErrortZeroDivisionErrorR( tclsRRtselftvaluetmR
R tscaleR tg((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyRDsf                  cC st|tjƒr||ƒSt|tƒsStd|j|t|ƒjfƒ‚ntj|ƒsqtj    |ƒrtd||jfƒ‚n||j
ƒŒ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.( RtnumberstIntegralRR t__name__ttypetmathtisnantisinftas_integer_ratio(R"tf((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyR¨s
"cC s ddlm}t|tjƒr7|t|ƒƒ}n7t||ƒsntd|j|t|ƒjfƒ‚n|j    ƒs–td||jfƒ‚n|j
ƒ\}}}tdj t t |ƒƒƒ}|rÙ| }n|dkr÷||d|ƒS||d| ƒSdS(    sAConverts a finite Decimal instance to a rational number, exactly.iÿÿÿÿ(Rs2%s.from_decimal() only takes Decimals, not %r (%s)sCannot convert %s to %s.tii
N(R RRR(R)RR R*R+t    is_finitetas_tupletjointmaptstr(R"tdecRR tdigitsR ((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyR¸s " 
 i@Bc C s1|dkrtdƒ‚n|j|kr4t|ƒSd\}}}}|j|j}}xmtrÈ||}|||}    |    |krŠPn||||||    f\}}}}||||}}q\W|||}
t||
|||
|ƒ} t||ƒ} t| |ƒt| |ƒkr)| 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((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pytlimit_denominatorÎs&  
    
 & cC s|jS(N(R(R((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyRscC s|jS(N(R(R((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyR    scC sd|j|jfS(s
repr(self)sFraction(%s, %s)(RR(R#((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt__repr__ scC s4|jdkrt|jƒSd|j|jfSdS(s    str(self)is%s/%sN(RR6R(R#((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt__str__s c sn‡‡fd†}dˆjd|_ˆj|_‡‡fd†}dˆjd|_ˆj|_||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 sqt|tttfƒr%ˆ||ƒSt|tƒrGˆt|ƒ|ƒSt|tƒriˆt|ƒ|ƒStSdS(N(RRtlongRRtcomplextNotImplemented(RR(tfallback_operatortmonomorphic_operator(sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pytforwardhs t__c szt|tƒrˆ||ƒSt|tjƒrGˆt|ƒt|ƒƒSt|tjƒrrˆt|ƒt|ƒƒStSdS(N(RRR(tRealRtComplexRJRK(RR(RLRM(sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pytreversets t__r(R*t__doc__(RMRLRNRR((RLRMsQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt_operator_fallbackssP     
 cC s/t|j|j|j|j|j|jƒS(sa + b(RRR(RR((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt_addƒscC s/t|j|j|j|j|j|jƒS(sa - b(RRR(RR((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt_sub‹scC s!t|j|j|j|jƒS(sa * b(RRR(RR((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt_mul“scC s!t|j|j|j|jƒS(sa / b(RRR(RR((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt_div™scC s8||}t|tƒr'|j|jStj|ƒSdS(sa // bN(RRRRR,tfloor(RRtdiv((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt __floordiv__¡s
cC s8||}t|tƒr'|j|jStj|ƒSdS(sa // bN(RRRRR,RZ(RRR[((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt __rfloordiv__­s
cC s||}|||S(sa % b((RRR[((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt__mod__¹s
cC s||}|||S(sa % b((RRR[((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt__rmod__¾s
cC s—t|tƒr…|jdkrn|j}|dkrNt|j||j|ƒSt|j| |j| ƒ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((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt__pow__Ãs      cC sw|jdkr)|jdkr)||jSt|tƒrOt|j|jƒ|S|jdkri||jS|t|ƒS(sa ** bii(RRRRRRRR(RR((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt__rpow__Ûs  cC st|j|jƒS(s++a: Coerces a subclass instance to Fraction(RRR(R((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt__pos__éscC st|j |jƒS(s-a(RRR(R((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt__neg__íscC stt|jƒ|jƒS(sabs(a)(RR:RR(R((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt__abs__ñscC s1|jdkr|j |j S|j|jSdS(strunc(a)iN(RR(R((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt    __trunc__õscC sX|jdkrt|jƒS|t|ƒkr>tt|ƒƒSt|j|jfƒ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#((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt__hash__üs
 cC s³t|tƒr1|j|jko0|j|jkSt|tjƒr^|jdkr^|j    }nt|t
ƒr«t j |ƒs‹t j |ƒr•d|kS||j|ƒkSntSdS(sa == bigN(RRRRRRR(RQtimagtrealRR,R-R.RRK(RR((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt__eq__s! 
cC s©t|tƒr0||j|j|j|jƒSt|tƒrNtdƒ‚nt|tƒr¡t    j
|ƒs{t    j |ƒrˆ|d|ƒS|||j |ƒƒSnt SdS(scHelper for comparison operators, for internal use only.
 
        Implement comparison between a Rational instance `self`, and
        either another Rational instance or a float `other`.  If
        `other` is not a Rational instance or a float, return
        NotImplemented. `op` should be one of the six standard
        comparison operators.
 
        s3no ordering relation is defined for complex numbersgN(RRRRRRRJR RR,R-R.RRK(R#tothertop((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt_richcmp"s  cC s|j|tjƒS(sa < b(Rntoperatortlt(RR((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt__lt__<scC s|j|tjƒS(sa > b(RnRotgt(RR((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt__gt__@scC s|j|tjƒS(sa <= b(RnRotle(RR((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt__le__DscC s|j|tjƒS(sa >= b(RnRotge(RR((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt__ge__HscC s |jdkS(sa != 0i(R(R((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt __nonzero__LscC s|jt|ƒffS(N(t    __class__R6(R#((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt
__reduce__RscC s,t|ƒtkr|S|j|j|jƒS(N(R+RRyRR(R#((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt__copy__UscC s,t|ƒtkr|S|j|j|jƒS(N(R+RRyRR(R#tmemo((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt __deepcopy__Zs(s
_numerators _denominatorN(9R*t
__module__RTt    __slots__RRt classmethodRRRFtpropertyRRRGRHRURVRotaddt__add__t__radd__RWtsubt__sub__t__rsub__RXtmult__mul__t__rmul__RYttruedivt __truediv__t __rtruediv__R[t__div__t__rdiv__R\R]R^R_RaRbRcRdReRfRhRkRnRqRsRuRwRxRzR{R}(((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyR,sRd 7            k                                                                                                (RTt
__future__RR RR,R(Rotret__all__RRtcompiletVERBOSEt
IGNORECASERR(((sQ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/fractions.pyt<module>s