3 ^9Pc@sddlZddlZddlZddlZddlZeedddkrBejdejdej ej Bj Z dd d Z d ZGd ddejZedkrejdS)NZfloat_repr_styleZshortzHcorrectly-rounded string->float conversions not available on this systemam # A numeric string consists of: (?P[-+])? # an optional sign, followed by (?=\d|\.\d) # a number with at least one digit (?P\d*) # having a (possibly empty) integer part (?:\.(?P\d*))? # followed by an optional fractional part (?:E(?P[-+]?\d+))? # and an optional exponent \Z 5icCst|}|dkrtd|jdp$d}t|jd|}t|jdpFdt|}|jdd k}|d t|d d td | } } | s|rd Sd S| j| j} | | d kr| | ?n| | >| k7} t| ||} | t| d >| t| d >} } t| | \} }d|| ks(d|| krR| d@rR| d7} | j|dkrR| d} | d7} | | j|krr|rndSdS| s|rd Sd Sd|dd}d|dd}| |>| |} } dj|rd nd| d|| d||| d|S)zConvert a finite decimal string to a hex string representing an IEEE 754 binary64 float. Return 'inf' or '-inf' on overflow. This function makes no use of floating-point arithmetic at any stage.Nzinvalid numeric stringZfracrintexp0Zsign- rz -0x0.0p+0z0x0.0p+0-infinfz{}0x{:x}.{:0{}x}p{:+d}) strtod_parser ValueErrorZgrouprZlenZmaxZ bit_lengthdivmodformat)sZmant_digZmin_expZmax_expmZfractionZintpartrZnegativeZaZbZdeZqZrZhexdigsZshiftr(/usr/lib64/python3.6/test/test_strtod.pystrtodsB$ " &   rrc@sveZdZddZddZddZddZd d Zd d Zd dZ e j j e j j ddddddZddZddZdS) StrtodTestscCsxy t|}Wn>tk r4|ddkr,dnd}Yn tk rJd}Yn X|j}t|}|j||dj|||dS)zCompare the result of Python's builtin correctly rounded string->float conversion (using float) to a pure Python correctly rounded string->float implementation. Fail if the two methods give different results.rrr r z memory errorzEIncorrectly rounded str->float conversion for {}: expected {}, got {}N)floatZ OverflowErrorZ MemoryErrorZhexr assertEqualr)selfrZfsZgotZexpectedrrr check_strtodWs  zStrtodTests.check_strtodc CsPxHd D]>}dd| }dd| }|ddkr>|d 7}xttD]}tj||d|}}x"|ddkr|d|d }}qfW||}}xL|dkrd j||} |j| d j|dd |d } |j| |d9}qW||}}xX|dkrBd j||} |j| d j|dd |d } |j| |d9}|d 8}qWqJWqWdS)Nrrr i6rr {}e{}()rrrr r!llll Fx:^Vr$range TEST_SIZErandom randrangerr) rZkZupperZlowerinrdigitsexponentrrrrtest_short_halfway_casesjs0            z$StrtodTests.test_short_halfway_casescCsxtdtD]}tjd }t|d \}}|r@|d |d}}|d8}d|d|d}}|dkrt||>}d}n|d| }|}d j||}|j|qWdS)Nidir i4r i2rrr"lr/r/)r&r'r(r)rrr)rr*Zbitsrrr,r-rrrrtest_halfway_casess  zStrtodTests.test_halfway_casesc Csddddg}xn|D]f\}}}xZtd D]N}|tjd|d |}|}d j||}|j||d9}|d9}|d8}q&WqWdS)N 9VV%o$CK!jT&iGMrrr"rr )r1r:r3)r4r5r6)r7r;r8r;)rr;r8i)r&r(r)rr) rZ boundariesr+rZujr,r-rrrrtest_boundariess  zStrtodTests.test_boundariescCsbx\tdd D]N}d| dd}x6ttD]*}|tjd d}dj||}|j|q,Wq WdS) Ni@rr i3r9r"piir%)rr-Zbaser<r,rrrrtest_underflow_boundarys  z#StrtodTests.test_underflow_boundaryc Cs\xVdD]N}d|}x@tdtD]0}tj|}tjdd }dj||}|j|q WqWdS)Nrrr rr2r!r#)2r>r") rrrAr rrBrCr2r!r#rDrEr?r%)rZndigsZdig10r*r,r-rrrr test_bigcomps    zStrtodTests.test_bigcompc sHdd}x8tdD]*}x"ttD]}tj|}tjd}|djfddt|D7}tjd d gr|d 7}tjd}|djfd dt|D7}nd }tjd d gr|tjddg7}|tj|7}tjdd}|djfddt|D7}||r|j|q&y t|Wq&tk r:Yq&Xq&WqWdS)NZ000000123456789+rrr9rc3|]}tjVqdSNr(choiceZ.0Z_r,rr sz+StrtodTests.test_parsing..TFZ.c3rHrIrJrLrMrrrNrrZEr r c3rHrIrJrLrMrrrNrO)rGrr) r&r'r(rKr)Zjoinrrr)rZsignsr*r<rZ intpart_lenZ fracpart_lenZ exponent_lenrrMr test_parsings4        zStrtodTests.test_parsingrrF)ZsizeZmemuseZdry_runcCs`dd|}|jtt|WdQRX~dd|d}|jtt|WdQRX~dS)Nz1.Z1z0.r)Z assertRaisesrr)rZmaxsizerrrrtest_oversized_digit_stringss   z(StrtodTests.test_oversized_digit_stringscCsdd}dd}|jt|dd|jt|dd|jt|dd|jt|dd|jt|dd|jt|dddS) NcSsdjd|d|S)z* Long string with value 1.0 and exponent nz 0.{}1e+{}rr rr+rrr positive_exp z6StrtodTests.test_large_exponents..positive_expcSsdjd||S)z+ Long string with value 1.0 and exponent -nz1{}e-{}rrRrSrrr negative_exprUz6StrtodTests.test_large_exponents..negative_expi'g?i Ni0u)rr)rrTrVrrrtest_large_exponentssz StrtodTests.test_large_exponentsc,Csxddddddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,g,}x|D]}|j|qbWdS)-Nz02183167012312112312312.23538020374420446192e-370z712579816049008305546974391768996369464963024663104e-357z717489628565202117263145367596028389348922981857013e-357z718487398785991994634182916638542680759613590482273e-357z732002864200581033134358724675198044527469366773928e-358z794393431193180696942841837085033647913224148539854e-358z773608278998966969345824653500136787876436005957953e-358z764774478836417299491718435234611299336288082136054e-358z713704940134126574534878641876947980878824688451169e-357z746697445774047060960624497964425416610480524760471e-358z728639097178261763178489759107321392745108491825303e-311z1.00000000000000001e44z-1.0000000000000000100000000000000000000001e44z399999999999999994487665465554760717039532578546e-47Zo9654371763336549317990355136719971183455700459144696213413350821416312194420007991306908470147322020121018368e0a104308485241983990666713401708072175773165034278685682646111762292409330928739751702404658197872319129036519947435319418387839758990478549477777586673075945844895981012024387992135617064532141489278815239849108105951619997829153633535314849999674266169258928940692239684771590065027025835804863585454872499320500023126142553932654370362024104462255244034053203998964360882487378334860197725139151265590832887433736189468858614521708567646743455601905935595381852723723645799866672558576993978025033590728687206296379801363024094048327273913079612469982585674824156000783167963081616214710691759864332339239688734656548790656486646106983450809073750535624894296242072010195710276073042036425579852459556183541199012652571123898996574563824424330960027873516082763671875e-1075z247032822920623295e-341z799037485700245683102805043437346965248029601286431e-373z799617639833743863161109961162881027406769510558457e-373z798852915025769345295749278351563179840130565591462e-372z799059944827693569659153042769690930905148015876788e-373z798914979205069368270421829889078356254059760327101e-372z,1000000000000000000000000000000000000000e-16z-10000000000000000000000000000000000000000e-17z=991633793189150720000000000000000000000000000000000000000e-33z;4106250198039490000000000000000000000000000000000000000e-38z*10.900000000000000012345678912345678912345a11651287494059419563861790709256988151903479322938522856916519154189084656466977171489691608488398792047332126810029685763620092606534076968286334920536334924763766067178320990794927368304039797998410780646182269333271282839761794603623958163297658510063352026077076106072540390412314438457161207373275477458821194440646557259102208197382844892733860255628785183174541939743301249188486945446244053689504749943655197464973191717009938776287102040358299419343976193341216682148401588363162253931420379903449798213003874174172790742957567330246138038659650118748200625752770984217933648838167281879845022933912352785884444833681591202045229462491699354638895656152216187535257259042082360747878839946016222830869374205287663441403533948204085390898399055004119873046875e-1075a^5254406533529552661096610603582028195612589849649138922565278497589560452182570597137658742514361936194432482059988700016338656575174473559922258529459120166686600002102838072098506622244175047522649953606315120077538558010753730576321577387528008403025962370502479105305382500086822727836607781816280407336531214924364088126680234780012085291903592543223403975751852488447885154107229587846409265285440430901153525136408849880173424692750069991045196209464308187671479664954854065777039726878381767789934729895619590000470366389383963331466851379030183764964083197053338684769252973171365139701890736933147103189912528110505014483268752328506004517760913030437151571912928276140468769502257147431182910347804663250851413437345649151934269945872064326973371182115272789687312946393533547747886024677951678751174816604738791256853675690543663283782215866825e-1180Z32602129298404963083833853479113577253105939995688e2Z5260212929840496308383385347911357725310593999568896e0z826021292984049630838338534791135772531059399956889601e-2Z5260212929840496308383385347911357725310593999568895e0Z5260212929840496308383385347911357725310593999568897e0Z5260212929840496308383385347911357725310593999568996e0Z5260212929840496308383385347911357725310593999568866e0z9007199254740992.00A5179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497792a9179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497791.999a9179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497792.001z:999999999999999944488848768742172978818416595458984375e-54zA9999999999999999444888487687421729788184165954589843749999999e-54zA9999999999999999444888487687421729788184165954589843750000001e-54z0.000000000000000000000000000000000000000010000000000000000057612911342378542997169042119121403423543508714776317814976295686899169228986994124665807319451982237978882039897143840789794921875)r)rZ test_stringsrrrrtest_particulars\ zStrtodTests.test_particularN)__name__Z __module__Z __qualname__rr.r0r=r@rFrPtestZsupportZ bigmemtestZ_2GrQrWrXrrrrrVs+  $" rZ__main__)rr[r)r(ZunittestZreZsysZ test.supportrZZgetattrZSkipTestZcompileZVERBOSEZ IGNORECASEZmatchrrr'ZTestCaserrYZmainrrrrZs  9\