Qf ddlmZddlZddlZddlZddlZddlZddlZdgZejjZ ejjZ ejddZej dej"ej$zZd dZd Zej d ej,ej"zj.ZGd dej2Zy) DecimalNFractioni@)maxsizec t|dt}ttt||z}|dk\r|n| }|dk(rdS|S#t$r t }Y$wxYw)Nr)pow_PyHASH_MODULUShashabs ValueError _PyHASH_INF) numerator denominatordinvhash_results 0/opt/alt/python312/lib64/python3.12/fractions.py_hash_algorithmrse2;O4(T#i.)D011nU5&F22)6)+ sAAAa \A\s* # optional whitespace at the start, (?P[-+]?) # an optional sign, then (?=\d|\.\d) # lookahead for digit or .digit (?P\d*|\d+(_\d+)*) # numerator (possibly empty) (?: # followed by (?:\s*/\s*(?P\d+(_\d+)*))? # an optional denominator | # or (?:\.(?P\d*|\d+(_\d+)*))? # an optional fractional part (?:E(?P[-+]?\d+(_\d+)*))? # and optional exponent ) \s*\Z # and optional whitespace to finish c |dk\r |d|zz}n |d| zz}t||dz z|\}}|dk(r |dzdk(r|dz}|r|dkn|dk}|t|fS)Nr r )divmodr )ndexponent no_neg_zeroqrsigns r_round_to_exponentr"Js 1} R\ R(] !qAv, "DAqAv!a%1* R1q5QUD Q<c |dk(rddd|z fStt|t|}}t|t|z ||kz}||z }t|||\}}tt||dzk(r |dz}|dz }|||fS)NrFrr)strr lenr") rrfiguresstr_nstr_dmrr! significands r_round_to_figuresr,gs  AvaW$$s1v;A5E E SZ5E>2A7{H*1a:D+ 3{ ! + A  h &&r#a (?: (?P.)? (?P[<>=^]) )? (?P[-+ ]?) (?Pz)? (?P\#)? # A '0' that's *not* followed by another digit is parsed as a minimum width # rather than a zeropad flag. (?P0(?=[0-9]))? (?P0|[1-9][0-9]*)? (?P[,_])? (?:\.(?P0|[1-9][0-9]*))? (?P[eEfFgG%]) ceZdZ dZd+fd ZedZedZefdZdZ dZ d,dZ e d Z e d Zd Zd Zd ZdZdZeeej*\ZZdZeeej2\ZZdZeeej:\ZZdZ ee ejB\Z"Z#dZ$ee$ejJ\Z&Z'dZ(ee(e)\Z*Z+dZ,ee,ejZ\Z.Z/dZ0dZ1dZ2dZ3dZ4ejjfdZ6dZ7dZ8dZ9d-dZ:d Z;d!Zd$Z?d%Z@d&ZAd'ZBd(ZCd)ZDd*ZExZFS).r _numerator _denominatorcD tt| |}|t|tur||_d|_|St|tjr$|j|_|j|_|St|ttfr|j\|_|_|St|trt j#|}|t%d|zt |j'dxsd}|j'd}|r t |}nd}|j'd}|r6|j)dd}d t+|z}||zt |z}||z}|j'd }|r"t |}|d k\r |d |zz}n |d | zz}|j'd d k(r| }nt-dt|tcxur t|urnnnrt|tjrMt|tjr3|j|jz|j|jz}}n t-d|d k(rt/d|zt1j2||} |d kr| } || z}|| z}||_||_|S)Nrz Invalid literal for Fraction: %rnum0denomdecimal_rexprr!-z2argument should be a string or a Rational instancez+both arguments should be Rational instancesFraction(%s, 0))superr__new__typeintr/r0 isinstancenumbersRationalrrfloatras_integer_ratior%_RATIONAL_FORMATmatchrgroupreplacer& TypeErrorZeroDivisionErrormathgcd) clsrrselfr*r4r5scaler8g __class__s rr<zFraction.__new__s <Xs+C0  I#%"+$%! Iw'7'78"+"5"5$-$9$9! Iw'785>5O5O5Q2!2 Is+$**959$%G%.&/00 5#6 ("%e*K"#Kggi0G")//#r": "CL 0$-$5G $D #u, ''%.C!#h!8%S0I'2t83K776?c)!* I !9::)_ 8tK'8 8 G$4$45 {G$4$4 5##k&=&==%% (=(==#I 12 2 ! #$5 $AB B HHY , ?Aa  #' r#c  t|tjr||St|ts1t |j d|dt |j d|j|jS)Nz%.from_float() only takes floats, not  ()) r?r@IntegralrBrH__name__r=_from_coprime_intsrC)rLfs r from_floatzFraction.from_float#sr a)) *q6MAu% \\1d1g.>.>@A A%s%%q'9'9';<rHrUr=rVrC)rLdecrs r from_decimalzFraction.from_decimal1suO# c7++ ,#c(#CC)sDI$6$689 9&s%%s';';'=>>r#cL tt| |}||_||_|SN)r;rr<r/r0)rLrrobjrPs rrVzFraction._from_coprime_ints=s/ Hc*3/"& r#c" |jdk(SNrr0rMs r is_integerzFraction.is_integerIs8  A%%r#c4 |j|jfSr]r.rbs rrCzFraction.as_integer_ratioMs !2!233r#c |dkr td|j|kr t|Sd\}}}}|j|j}} ||z}|||zz} | |kDrn|||||zz| f\}}}}||||zz }}/||z |z} d|z|| |zzz|jkrtj ||Stj || |zz|| |zzS)Nrz$max_denominator should be at least 1)rrrr)rr0rr/rV) rMmax_denominatorp0q0p1q1rraq2ks rlimit_denominatorzFraction.limit_denominatorTs > Q CD D    /D> !#BB 1 111AAbDBO#R"Wb0NBBa!eqA R " $ Q31R4=D-- -..r26 6..r!B$w1R4@ @r#c|jSr])r/rls rrzFraction.numerators ||r#c|jSr]rarqs rrzFraction.denominators ~~r#cj |jjd|jd|jdS)N(z, rS)rPrUr/r0rbs r__repr__zFraction.__repr__s-#~~66#0A0AC Cr#c |jdk(rt|jS|jd|jS)Nr/)r0r%r/rbs r__str__zFraction.__str__s7    !t' '"oot/@/@A Ar#c  ! |s t|St|}|$td|dt|j|d*|d%td|dt|jd|dxsd}|dxsd}|d d k(rd n|d }t |d }t |d }t |d}t |dxsd} |d!t |dxsd} |d} | dvxr| } | } | dvrdnd}| dvr7| }| dk(r|dz}t|j|j||\}}d}| }nY| dvr t| dn| dz}t|j|j|\}}}| dvxs|dkDxs||zdk}|r|dz n| }| dk(rd}n|r |||zd }nd }|d|dzd!}|rd n|}|dt||z  |t||z d}| r|jd}| r|sd nd"}||z|z}|r8| t|z t|z } j!r d#|zd$zdzn| !rIdt dz d#zz} d|d j !fd%t!|t d#Dz |z}|| t|z t|z z}|dk(r||z|zS|d&k(r||z|zS|d'k(rt|dz}|d||z|z||dzS||z|zS)(NzInvalid format specifier z for object of type alignzeropadz0; can't use explicit alignment when zero-paddingfill >r!r9r7ralt minimumwidthr3 thousands_sep precision6presentation_typegGEFGEezfF%%rfFreErz+03dr.c34K|]}||dzzyw)rN).0posleadingrs r z&Fraction.__format__..s)4r"r/r0maxr,r&rstripzfilljoinrange)"rM format_specrEr|rzpos_signralternate_formr{rrr trim_zeros trim_pointexponent_indicatorrnegativer+ scientific point_posr'suffixdigitsr! frac_part separatortrailing min_leading first_posbodypaddinghalfrrs" @@r __format__zFraction.__format__sOt9 4K@ =+K?;&&*4j&9&9%<> 7^ 'E),<,H+K?;&&*4j&9&9%<=AA  V}#g%#v#-25=5/0 eEl+uY'(507C8 o. k*1c2 !"56&$.E~3E '' $5$>SC  %!zH C'A $6!2!2Hk%K !HkJ!I%,Iq!]  /@!2!2G/= +Hk8"T),a<,g%+  (2! yI  #F *+Hy,@+FGFF )a-12 sH23v;233v;245 !((-I$YBC y(61 &T2S]BKmm,9K1$q({G S\A-22Ijy)BGG4 CL!<4-G!,T2SY>? C<T>D( ( c\$;( ( c\w<1$D5D>D(4/'$%.@ @'>D( (r#c fd}djzdz|_j|_fd}djzdz|_j|_||fS)Nct|tr ||St|tr|t|St|trt||St|trt ||St Sr])r?rr>rBcomplexNotImplemented)rlbfallback_operatormonomorphic_operators rforwardz-Fraction._operator_fallbacks..forwardesq!X&+Aq11As#+Ax{;;Au%(q155Aw'(Q77%%r#__c<t|tjrt||St|tjrt |t |St|tj rt|t|StSr]) r?r@rArRealrBComplexrr)rrlrrs rreversez-Fraction._operator_fallbacks..reversessp!W--.+HQK;;Aw||,(q58<<Aw/(WQZ@@%%r#__r)rU__doc__)rrrrs`` r_operator_fallbackszFraction._operator_fallbackssoN ^ & "3"<"<? UHUBG,,,r#c |j|j}}t|j|z|j|zz||zSr])rrr)rlrrrs r_modz Fraction._mods> Br)akkB.>?bIIr#c t|tjr|jdk(r|j}|dk\r0t j |j|z|j|zS|jdkDr2t j |j| z|j| zS|jdk(rtd|j| zzt j |j | z|j | zSt|t|zSt|ttfrt||zStS)Nrrr:) r?r@rArrrrVr/r0rIrBrr)rlrpowers r__pow__zFraction.__pow__!s=  a)) *}}! A:#66q||u7L78~~7NPP\\A%#66q~~%7O78||v7MOO\\Q&+,=,-NNuf,D-EFF$66UF7R9: 5&7PRR Qx58++ E7+ ,8q= ! !r#c0 |jdk(r|jdk\r||jzSt|tjr#t |j |j|zS|jdk(r||jzS|t|zS)Nrr) r0r/r?r@rArrrrB)rrls r__rpow__zFraction.__rpow__As~ >>Q 1<<1#4 $ $ a)) *AKK71< < >>Q  $ $E!H}r#cX tj|j|jSr]rrVr/r0rqs r__pos__zFraction.__pos__Os 9**1<<HHr#cZ tj|j |jSr]rrqs r__neg__zFraction.__neg__Ss"**ALL=!..IIr#cj tjt|j|jSr])rrVr r/r0rqs r__abs__zFraction.__abs__Ws%**3q||+>1 1r#c6 |j|jzSr]r.rqs r __floor__zFraction.__floor__is||q~~--r#c: |j |jz Sr]r.rqs r__ceil__zFraction.__ceil__ms,,!..011r#c( |K|j}t|j|\}}|dz|kr|S|dz|kDr|dzS|dzdk(r|S|dzSdt|z}|dkDrt t ||z|St t ||z |zS)Nrfrrr)r0rr/r rround)rMndigitsrfloor remaindershifts r __round__zFraction.__round__rs  ?!!A%dooq9 E91}q  Q"qy a qy CL  Q;E$,/7 7E$,/%78 8r#cD t|j|jSr])rr/r0rbs r__hash__zFraction.__hash__st0A0ABBr#c t|tur |j|k(xr|jdk(St |t j r4|j|jk(xr|j|jk(St |t jr|jdk(r |j}t |trCtj|stj|rd|k(S||j!|k(St"S)Nrr)r=r>r/r0r?r@rArrrimagrealrBrJisnanisinfrXrrs r__eq__zFraction.__eq__s 7c><<1$<1)< < a)) *LLAKK/4NNamm3 5 a )affkA a zz!} 1 axALLO++" !r#ch t|tjr7||j|jz|j |j zSt|trKtj|stj|r |d|S|||j|StS)Nr) r?r@rAr/rr0rrBrJrrrXr)rMotherops r_richcmpzFraction._richcmps  eW-- .doo(9(99''%//9; ; eU #zz% DJJu$5#u~%$ 677! !r#cD |j|tjSr])roperatorltrs r__lt__zFraction.__lt__zz!X[[))r#cD |j|tjSr])rr gtrs r__gt__zFraction.__gt__r r#cD |j|tjSr])rr lers r__le__zFraction.__le__zz!X[[))r#cD |j|tjSr])rr gers r__ge__zFraction.__ge__rr#c. t|jSr])rr/rqs r__bool__zFraction.__bool__sALL!!r#cJ|j|j|jffSr])rPr/r0rbs r __reduce__zFraction.__reduce__s $2C2C DEEr#cvt|tk(r|S|j|j|jSr]r=rrPr/r0rbs r__copy__zFraction.__copy__. : !K~~doot/@/@AAr#cvt|tk(r|S|j|j|jSr]r)rMmemos r __deepcopy__zFraction.__deepcopy__rr#)rN)i@Br])GrU __module__ __qualname__ __slots__r< classmethodrXr[rVrcrCropropertyrrrurxrrrr add__add____radd__rsub__sub____rsub__rmul__mul____rmul__rtruediv __truediv__ __rtruediv__rfloordiv __floordiv__ __rfloordiv__rr __divmod__ __rdivmod__rmod__mod____rmod__rrrrrindexrrrrrrrrr rrrrrrr! __classcell__)rPs@rrrs(/IgR = = ? ?  &47ArC Br)hk b D,D(,,?GX D,D(,,?GX =,D(,,?GX1(!4D(:J:J KKN#6iARAR"SL-- 2'6BJ J ,D(,,?GX"@ IJN#..:2.2 94C"*",****"FB Br#)F)r5r functoolsrJr@r resys__all__ hash_infomodulusr infr lru_cachercompileVERBOSE IGNORECASErDr"r,DOTALL fullmatchrrArrr#rrJs6  , --''mm w'*(*@2:: ZZ"-- !":$'R'1bjj2YY''Y$$| Bw| Br#