{G_Tc@sddlZddlZddlZddlZddlZddlmZeedddkrvejdnej dej ej Bj Z dd d d Zd Zd ejfdYZdZedkrendS(iN(t test_supporttfloat_repr_stylettshortsHcorrectly-rounded string->float conversions not available on this systemsm # 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 i5iicCsrt|}|dkr'tdn|jdp9d}t|jd|}t|jdpjdt|}|jddk}|d t|d d td | } } | s|rd Sd S| j| j} | | d kr| | ?n| | >| k7} t| ||} | t| d >| t| d >} } t| | \} }d || ksd || kr| d@r| d7} | j|dkr| d } | d7} qn| | j|kr|rdSdS| s|rd Sd Sd|d d}d|d d}| |>| |} } dj |rGdnd| d|| d||| d|S(sConvert 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.sinvalid numeric stringtfracRtinttexpt0tsignt-i is -0x0.0p+0s0x0.0p+0iis-inftinfiis{}0x{:x}.{:0{}x}p{:+d}iN( t strtod_parsertNonet ValueErrortgroupRtlentmaxt bit_lengthtdivmodtformat(tstmant_digtmin_exptmax_exptmtfractiontintpartRtnegativetatbtdtetqtrthexdigstshift((s,/usr/local/lib/python2.7/test/test_strtod.pytstrtodsB  %,+(*    i t StrtodTestscBseZdZdZdZdZdZdZdZe j de j dd d e d Z d Zd ZRS(cCsyt|}WnCtk r?|ddkr6dnd}n#tk rUd}n X|j}t|}|j||dj|||dS(sCompare 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.iR s-infR s memory errorsEIncorrectly rounded str->float conversion for {}: expected {}, got {}N(tfloatt OverflowErrort MemoryErrorthexR$t assertEqualR(tselfRtfstgottexpected((s,/usr/local/lib/python2.7/test/test_strtod.pyt check_strtodXs      c Csxd D]}dd| }dd| }|ddkrH|d 7}nxFttD]8}tj||d|}}x)|ddkr|d|d }}qzW||}}x`|dkrd j||} |j| d j|d|d } |j| |d9}qW||}}xj|dkrd j||} |j| d j|d|d } |j| |d9}|d 8}q#WqUWqWdS(Niii iiii6i5is{}e{}i((iii iiI@II Il Fx:^Vl Ozpcl Fx:^Vl Ozpc(txranget TEST_SIZEtrandomt randrangeRR/( R+tktuppertlowertitnRtdigitstexponentR((s,/usr/local/lib/python2.7/test/test_strtod.pyttest_short_halfway_casesks0         cCsxtdtD]}tjdd }t|d \}}|r]|d |d}}n|d8}d|d|d}}|dkr||>}d}n|d| }|}d j||}|j|qWdS( Nidiii4ii2iis{}e{}III(R0R1R2R3RRR/(R+R7tbitsRRR9R:R((s,/usr/local/lib/python2.7/test/test_strtod.pyttest_halfway_casess    c Csddddg}x|D]\}}}xutd D]g}|tjd |d |}|}dj||}|j||d9}|d9}|d8}q5WqWdS(Nl 9ViiVl%o$CKi!iljT&iiMiiiis{}e{}i i(l 9ViiV(l%o$CKi!i(ljT&iiM(iiiM(R0R2R3RR/( R+t boundariesR8RtutjR9R:R((s,/usr/local/lib/python2.7/test/test_strtod.pyttest_boundariess    cCsyxrtddD]a}d| d }xIttD];}|tjdd}dj||}|j|q2WqWdS( Nipii ii3iis{}e{}lH(R0R1R2R3RR/(R+R:tbaseR@R9R((s,/usr/local/lib/python2.7/test/test_strtod.pyttest_underflow_boundarys c CszxsdD]k}d|}xXtdtD]F}tj|}tjd d}dj||}|j|q(WqWdS(Nii iiiiiiii(i)i2ipis{}e{}( ii iiiiiiii(i)i2(R0R1R2R3RR/(R+tndigstdig10R7R9R:R((s,/usr/local/lib/python2.7/test/test_strtod.pyt test_bigcomps  csdd}xtdD]}xvttD]h}tj|}tjd}|djfdt|D7}tjttgr|d7}tjd}|djfd t|D7}nd }tjttgrX|tjd d g7}|tj|7}tjd d}|djfdt|D7}n||rr|j|q,yt |Wq,t k rq,Xq,WqWdS(Nt000000123456789t+R Riic3s|]}tjVqdS(N(R2tchoice(t.0t_(R9(s,/usr/local/lib/python2.7/test/test_strtod.pys st.c3s|]}tjVqdS(N(R2RI(RJRK(R9(s,/usr/local/lib/python2.7/test/test_strtod.pys siRtEiic3s|]}tjVqdS(N(R2RI(RJRK(R9(s,/usr/local/lib/python2.7/test/test_strtod.pys s(RHR R( R0R1R2RIR3tjointTruetFalseR/R&R (R+tsignsR7R@Rt intpart_lent fracpart_lent exponent_len((R9s,/usr/local/lib/python2.7/test/test_strtod.pyt test_parsings4)   tsizetmemuseitdry_runcCsvddtd}|jtt|WdQX~ddtdd}|jtt|WdQX~dS(Ns1.t1g*dAs0.R(Rt assertRaisesR R&(R+tmaxsizeR((s,/usr/local/lib/python2.7/test/test_strtod.pyttest_oversized_digit_stringsscCsd}d}|jt|dd|jt|dd|jt|dd|jt|dd|jt|dd|jt|dddS(NcSsdjd|d|S(s* Long string with value 1.0 and exponent ns 0.{}1e+{}Ri(R(R8((s,/usr/local/lib/python2.7/test/test_strtod.pyt positive_exp scSsdjd||S(s+ Long string with value 1.0 and exponent -ns1{}e-{}R(R(R8((s,/usr/local/lib/python2.7/test/test_strtod.pyt negative_expsi'g?i Ni0u(R*R&(R+R]R^((s,/usr/local/lib/python2.7/test/test_strtod.pyttest_large_exponents s  c+Csddddddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+g+}x|D]}|j|qWdS(,Ns02183167012312112312312.23538020374420446192e-370s712579816049008305546974391768996369464963024663104e-357s717489628565202117263145367596028389348922981857013e-357s718487398785991994634182916638542680759613590482273e-357s732002864200581033134358724675198044527469366773928e-358s794393431193180696942841837085033647913224148539854e-358s773608278998966969345824653500136787876436005957953e-358s764774478836417299491718435234611299336288082136054e-358s713704940134126574534878641876947980878824688451169e-357s746697445774047060960624497964425416610480524760471e-358s728639097178261763178489759107321392745108491825303e-311s1.00000000000000001e44s-1.0000000000000000100000000000000000000001e44s399999999999999994487665465554760717039532578546e-47to9654371763336549317990355136719971183455700459144696213413350821416312194420007991306908470147322020121018368e0s104308485241983990666713401708072175773165034278685682646111762292409330928739751702404658197872319129036519947435319418387839758990478549477777586673075945844895981012024387992135617064532141489278815239849108105951619997829153633535314849999674266169258928940692239684771590065027025835804863585454872499320500023126142553932654370362024104462255244034053203998964360882487378334860197725139151265590832887433736189468858614521708567646743455601905935595381852723723645799866672558576993978025033590728687206296379801363024094048327273913079612469982585674824156000783167963081616214710691759864332339239688734656548790656486646106983450809073750535624894296242072010195710276073042036425579852459556183541199012652571123898996574563824424330960027873516082763671875e-1075s247032822920623295e-341s799037485700245683102805043437346965248029601286431e-373s799617639833743863161109961162881027406769510558457e-373s798852915025769345295749278351563179840130565591462e-372s799059944827693569659153042769690930905148015876788e-373s798914979205069368270421829889078356254059760327101e-372s,1000000000000000000000000000000000000000e-16s-10000000000000000000000000000000000000000e-17s=991633793189150720000000000000000000000000000000000000000e-33s;4106250198039490000000000000000000000000000000000000000e-38s*10.900000000000000012345678912345678912345s11651287494059419563861790709256988151903479322938522856916519154189084656466977171489691608488398792047332126810029685763620092606534076968286334920536334924763766067178320990794927368304039797998410780646182269333271282839761794603623958163297658510063352026077076106072540390412314438457161207373275477458821194440646557259102208197382844892733860255628785183174541939743301249188486945446244053689504749943655197464973191717009938776287102040358299419343976193341216682148401588363162253931420379903449798213003874174172790742957567330246138038659650118748200625752770984217933648838167281879845022933912352785884444833681591202045229462491699354638895656152216187535257259042082360747878839946016222830869374205287663441403533948204085390898399055004119873046875e-1075s^5254406533529552661096610603582028195612589849649138922565278497589560452182570597137658742514361936194432482059988700016338656575174473559922258529459120166686600002102838072098506622244175047522649953606315120077538558010753730576321577387528008403025962370502479105305382500086822727836607781816280407336531214924364088126680234780012085291903592543223403975751852488447885154107229587846409265285440430901153525136408849880173424692750069991045196209464308187671479664954854065777039726878381767789934729895619590000470366389383963331466851379030183764964083197053338684769252973171365139701890736933147103189912528110505014483268752328506004517760913030437151571912928276140468769502257147431182910347804663250851413437345649151934269945872064326973371182115272789687312946393533547747886024677951678751174816604738791256853675690543663283782215866825e-1180t32602129298404963083833853479113577253105939995688e2t5260212929840496308383385347911357725310593999568896e0s826021292984049630838338534791135772531059399956889601e-2t5260212929840496308383385347911357725310593999568895e0t5260212929840496308383385347911357725310593999568897e0t5260212929840496308383385347911357725310593999568996e0t5260212929840496308383385347911357725310593999568866e0s9007199254740992.00t5179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497792s9179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497791.999s9179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497792.001s:999999999999999944488848768742172978818416595458984375e-54sA9999999999999999444888487687421729788184165954589843749999999e-54sA9999999999999999444888487687421729788184165954589843750000001e-54(R/(R+t test_stringsR((s,/usr/local/lib/python2.7/test/test_strtod.pyttest_particularsZ  (t__name__t __module__R/R;R=RARCRFRURtprecisionbigmemtestt_2GRPR\R_Ri(((s,/usr/local/lib/python2.7/test/test_strtod.pyR%Ws  +   $ cCstjtdS(N(Rt run_unittestR%(((s,/usr/local/lib/python2.7/test/test_strtod.pyt test_mainst__main__(R2tstructtunittesttretsysttestRtgetattrtSkipTesttcompiletVERBOSEt IGNORECASEtmatchR R$R1tTestCaseR%RoRj(((s,/usr/local/lib/python2.7/test/test_strtod.pyts     9U