Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325
Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325
Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325
Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325
Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325
Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325
Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325
3
\W\ ã @ sŠ d Z ddlmZ ddlZddlZddlZddlZddlZddgZdd„ Z dd„ Z
ejjZ
ejjZejd ejejB ƒZG d
d„ dejƒZdS )z+Fraction, infinite-precision, real numbers.é )ÚDecimalNÚFractionÚgcdc C sf ddl }|jdtdƒ t| ƒt ko0t|ƒkn r\|p<| dk rPtj| |ƒ S tj| |ƒS t| |ƒS )z¶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).
r Nz6fractions.gcd() is deprecated. Use math.gcd() instead.é )ÚwarningsÚwarnÚDeprecationWarningÚtypeÚintÚmathr Ú_gcd)ÚaÚbr © r ú!/usr/lib64/python3.6/fractions.pyr s c C s x|r|| | } }qW | S )Nr )r
r r r r r s r aC
\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
(?:/(?P\d+))? # an optional denominator
| # or
(?:\.(?P\d*))? # an optional fractional part
(?:E(?P[-+]?\d+))? # and optional exponent
)
\s*\Z # and optional whitespace to finish
c s e Zd ZdZdSZdTddœ‡ fdd „Zed
d„ ƒZedd
„ ƒZdUdd„Z e
dd„ ƒZe
dd„ ƒZdd„ Z
dd„ Zdd„ Zdd„ Zeeejƒ\ZZdd„ Zeeejƒ\ZZdd „ Zeeejƒ\ZZd!d"„ Zeeejƒ\ZZ d#d$„ Z!d%d&„ Z"d'd(„ Z#d)d*„ Z$d+d,„ Z%d-d.„ Z&d/d0„ Z'd1d2„ Z(d3d4„ Z)d5d6„ Z*d7d8„ Z+d9d:„ Z,dVd;d<„Z-d=d>„ Z.d?d@„ Z/dAdB„ Z0dCdD„ Z1dEdF„ Z2dGdH„ Z3dIdJ„ Z4dKdL„ Z5dMdN„ Z6dOdP„ Z7dQdR„ Z8‡ Z9S )Wr a] 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)
Ú
_numeratorÚ_denominatorr NT)Ú
_normalizec sR t t| ƒj| ƒ}|dk�rdt|ƒtkr6||_d|_|S t|tj ƒrV|j
|_|j|_|S t|tt
fƒrx|jƒ \|_|_|S t|tƒ�rZtj|ƒ}|dkr¢td| ƒ‚t|jdƒp°dƒ}|jdƒ}|rÌt|ƒ}nvd}|jdƒ}|�rdt|ƒ }|| t|ƒ }||9 }|jd ƒ} | �rBt| ƒ} | d
k�r4|d| 9 }n|d| 9 }|jdƒdk�rb| }ntd
ƒ‚nft|ƒt k�o€t|ƒkn �rŠn@t|tj ƒ�rÂt|tj ƒ�rÂ|j
|j |j
|j }}ntdƒ‚|d
k�ràtd| ƒ‚|�rBt|ƒt k�ot|ƒkn �r(tj||ƒ}
|d
k �r2|
}
n
t||ƒ}
||
}||
}||_||_|S )a£ Constructs a Rational.
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)
Né z Invalid literal for Fraction: %rZnumÚ0ÚdenomÚdecimalé
Úexpr Zsignú-z2argument should be a string or a Rational instancez+both arguments should be Rational instanceszFraction(%s, 0))Úsuperr Ú__new__r r
r r Ú
isinstanceÚnumbersÚRationalÚ numeratorÚdenominatorÚfloatr Úas_integer_ratioÚstrÚ_RATIONAL_FORMATÚmatchÚ
ValueErrorÚgroupÚlenÚ TypeErrorÚZeroDivisionErrorr r r )Úclsr r! r ÚselfÚmr r Zscaler Úg)Ú __class__r r r T sr
$
$
zFraction.__new__c C sD t |tjƒr| |ƒS t |tƒs8td| j|t|ƒjf ƒ‚| |jƒ Ž S )z‚Converts a finite float to a rational number, exactly.
Beware that Fraction.from_float(0.3) != Fraction(3, 10).
z.%s.from_float() only takes floats, not %r (%s))r r ÚIntegralr" r* Ú__name__r r# )r, Úfr r r Ú
from_floatÁ s
zFraction.from_floatc C sV ddl m} t|tjƒr&|t|ƒƒ}n$t||ƒsJtd| j|t|ƒjf ƒ‚| |j ƒ Ž S )zAConverts a finite Decimal instance to a rational number, exactly.r )r z2%s.from_decimal() only takes Decimals, not %r (%s))
r r r r r1 r
r* r2 r r# )r, Zdecr r r r Úfrom_decimalÏ s
zFraction.from_decimalé@B c
C sâ |dk rt dƒ‚| j|kr"t| ƒS d\}}}}| j| j }}xP|| }||| } | |kr\P ||||| | f\}}}}|||| }}q>W || | }
t||
| ||
| ƒ}t||ƒ}t|| ƒt|| ƒkrÚ|S |S dS )aW Closest 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)
r z$max_denominator should be at least 1r N)r r r r )r' r r r Úabs)
r- Zmax_denominatorZp0Zq0Zp1Zq1ÚnÚdr
Zq2ÚkZbound1Zbound2r r r Úlimit_denominatorÛ s&