Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4
WMc@ sdZddklZddkZddkZddkZddkZddgZeiZdZ ei dei Z defdYZ dS( s+Rational, infinite-precision, real numbers.i(tdivisionNtFractiontgcdcC s$x|o|||}}qW|S(sCalculate 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/lib/python2.6/fractions.pyRss \A\s* # optional whitespace at the start, then (?P[-+]?) # an optional sign, then (?=\d|\.\d) # lookahead for digit or .digit (?P\d*) # numerator (possibly empty) (?: # followed by an optional /(?P\d+) # / and denominator | # or \.(?P\d*) # decimal point and fractional part )? \s*\Z # and optional whitespace to finish cB seZdZd(ZdddZedZedZdd Ze d Z e d Z d Z d Z dZdZeeei\ZZdZeeei\ZZdZeeei\ZZdZeeei\ZZeeei \Z!Z"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/d Z0d!Z1d"Z2d#Z3d$Z4d%Z5d&Z6d'Z7RS()sThis 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 stt|i|}t|ttfjo|djo t|to|}ti |}|d jot d|n|i d}|i d}|o$t||}dt |}n)t|}t|i dpd}|i ddjo | }qFqJt|to|}|i}|i}qJn|d jotd |nti|}ti|}t||}|||_|||_|S( sConstructs 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/lib/python2.6/fractions.pyR :s8&      cC st|tio ||St|tp)td|i|t|ifnti|pti |otd||ifn||i S(sConverts 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/lib/python2.6/fractions.pyt from_floatjs # cC sddkl}t|tio|t|}n:t||p)td|i|t|ifn|i ptd||ifn|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/lib/python2.6/fractions.pyt from_decimalzs #   i@Bc C s;|djotdn|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/lib/python2.6/fractions.pytlimit_denominators(    &!cC s|iS(N(R(R((s/usr/lib/python2.6/fractions.pyRscC s|iS(N(R(R((s/usr/lib/python2.6/fractions.pyRscC sd|i|ifS(s repr(self)sFraction(%s, %s)(RR(R ((s/usr/lib/python2.6/fractions.pyt__repr__scC s6|idjot|iSd|i|ifSdS(s str(self)is%s/%sN(RR6R(R ((s/usr/lib/python2.6/fractions.pyt__str__sc snfd}did|_i|_fd}did|_i|_||fS(sGenerates 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|tttfo||St|tot||St|tot||StSdS(N(RRRRR'tcomplextNotImplemented(RR(tfallback_operatortmonomorphic_operator(s/usr/lib/python2.6/fractions.pytforward*st__c st|to||St|tiot|t|St|tiot|t|StSdS(N(RRR%tRealR'tComplexRKRL(RR(RMRN(s/usr/lib/python2.6/fractions.pytreverse6st__r(R)t__doc__(RNRMRORS((RMRNs/usr/lib/python2.6/fractions.pyt_operator_fallbackssP    cC s/t|i|i|i|i|i|iS(sa + b(RRR(RR((s/usr/lib/python2.6/fractions.pyt_addEscC s/t|i|i|i|i|i|iS(sa - b(RRR(RR((s/usr/lib/python2.6/fractions.pyt_subMscC s!t|i|i|i|iS(sa * b(RRR(RR((s/usr/lib/python2.6/fractions.pyt_mulUscC s!t|i|i|i|iS(sa / b(RRR(RR((s/usr/lib/python2.6/fractions.pyt_div[scC s:||}t|to|i|iSti|SdS(sa // bN(RRRRR*tfloor(RRtdiv((s/usr/lib/python2.6/fractions.pyt __floordiv__cs cC s:||}t|to|i|iSti|SdS(sa // bN(RRRRR*R[(RRR\((s/usr/lib/python2.6/fractions.pyt __rfloordiv__os cC s||}|||S(sa % b((RRR\((s/usr/lib/python2.6/fractions.pyt__mod__{s cC s||}|||S(sa % b((RRR\((s/usr/lib/python2.6/fractions.pyt__rmod__s cC st|to{|idjoS|i}|djot|i||i|St|i| |i| Sqt|t|Snt||SdS(sa ** 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/lib/python2.6/fractions.pyt__pow__s   cC s~|idjo|idjo ||iSt|tot|i|i|S|idjo ||iS|t|S(sa ** bii(RRRRRRRR'(RR((s/usr/lib/python2.6/fractions.pyt__rpow__s   cC st|i|iS(s++a: Coerces a subclass instance to Fraction(RRR(R((s/usr/lib/python2.6/fractions.pyt__pos__scC st|i |iS(s-a(RRR(R((s/usr/lib/python2.6/fractions.pyt__neg__scC stt|i|iS(sabs(a)(RR<RR(R((s/usr/lib/python2.6/fractions.pyt__abs__scC s3|idjo|i |i S|i|iSdS(strunc(a)iN(RR(R((s/usr/lib/python2.6/fractions.pyt __trunc__scC s\|idjot|iS|t|jott|St|i|ifSdS(shash(self) Tricky because values that are exactly representable as a float must have the same hash as that float. iN(RthashRR'(R ((s/usr/lib/python2.6/fractions.pyt__hash__s cC st|to$|i|ijo|i|ijSt|tio|idjo |i }nt|t o||i |jSt ||jSdS(sa == biN( RRRRRRR%RRtimagtrealR'R/(RR((s/usr/lib/python2.6/fractions.pyt__eq__s# cC st|tio|idjo |i}nt|to|i|}ny||}Wntj otSXt|t o||i dS||dS(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/lib/python2.6/fractions.pyt_subtractAndCompareToZeros # cC s|i|tiS(sa < b(RoRtlt(RR((s/usr/lib/python2.6/fractions.pyt__lt__scC s|i|tiS(sa > b(RoRtgt(RR((s/usr/lib/python2.6/fractions.pyt__gt__scC s|i|tiS(sa <= b(RoRtle(RR((s/usr/lib/python2.6/fractions.pyt__le__scC s|i|tiS(sa >= b(RoRtge(RR((s/usr/lib/python2.6/fractions.pyt__ge__scC s |idjS(sa != 0i(R(R((s/usr/lib/python2.6/fractions.pyt __nonzero__ scC s|it|ffS(N(t __class__R6(R ((s/usr/lib/python2.6/fractions.pyt __reduce__scC s.t|tjo|S|i|i|iS(N(RRRyRR(R ((s/usr/lib/python2.6/fractions.pyt__copy__scC s.t|tjo|S|i|i|iS(N(RRRyRR(R tmemo((s/usr/lib/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/lib/python2.6/fractions.pyR*sR 0 7   k                      (RUt __future__RR*R%Rtret__all__RRtcompiletVERBOSERR(((s/usr/lib/python2.6/fractions.pyts