
    dafT                        d dl Z d dlmZ d dlZd dlZd dlZd dlZej                  j                  Z	de	z  Z
e
dz
  ZdZdZd dde
e
dz	  ddgZd	Z ede	z        D ]  Zej%                  edz
         edz  Z [eeD  cg c]  } |   c} eD  cg c]  } |   c} z   z  Zej&                  j(                  Zej&                  j,                  Zej&                  j0                  Zej&                  j4                  Zdez  deez
  dz
  z  z
  Zd
 Zd Z G d de j>                        Z e!dk(  r e jD                          yyc c} w c c} w )    N)support      F      l   UU*UU* l   *UU*UU
    c                 H   t         j                  j                  dz   }t         j                  j                  |z
  }d|z  }g d}| dk(  ry| dk  rt	        |         S | j                         |z
  }|dk  r| | z  n| |z	  t        | d|z   z        z  }|||dz     z  }|||k(  z   |kD  rt        d      |d	z  dk(  r#|d	z  dt         j                  j                  z  k  sJ |d|z  z  t         j                  j                  k  sJ t        j                  t        |      |      S )
z9
    Correctly-rounded integer-to-float conversion.

    r   r   )r   r   r   r
   r   r   r           r
      z%integer too large to convert to floatr   )sys
float_infomant_digmax_expint_to_float
bit_lengthboolOverflowErrormaxmathldexpfloat)n	PRECISION	SHIFT_MAXQ_MAXROUND_HALF_TO_EVEN_CORRECTIONshiftqs          )/root/Python-3.12.4/Lib/test/test_long.pyr   r   '   s5    ''!+I&&2INE$?! 	Av	
QaR    LLNY&EqyeVqEzT!en:L5M&MA 	&q1u	--A U
i'CDD q5A:!q&A(?(?$@@@@q%x<3>>----- ::eAh&&    c                    | |z  dk  }t        |       t        |      }} |st        d      | t        |z  k\  rt        d      | j	                         |j	                         z
  }|dk\  r| d|z  |z  k\  s|dk  r| d| z  z  |k\  r|dz  }t        |t              t        z
  }| t        | d      z  |t        |d      z  }} t        | |      \  }}d|z  |kD  sd|z  |k(  r|dz  dk(  r|dz  }t        j                  ||      }|r| S |S )z-Correctly-rounded true division for integers.r   zdivision by zeroz)int/int too large to represent as a floatr   r   )absZeroDivisionErrorDBL_MIN_OVERFLOWr   r   r   DBL_MIN_EXPDBL_MANT_DIGdivmodr   r   )abnegativedexpr    rresults           r!   truedivr1   U   s#   sQwHq63q6qA  233q  GHH 	
'AAv!q!tax-1q5QQBY!^	Q a

,CSD!a3sA;.qA!Q<DAq 	sQw!A#(q1uz	QZZ3FF7*F*r"   c                      e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zej&                  d        Zd Zd Zd Zd Zd Zd Zd Zd Zd>dZej&                  d        Zd Zd Z ejB                  d        Z"ejB                   ejF                  e$jJ                  dz   dd !      d"               Z&d# Z'ejB                   ejF                  e$jJ                  d$z   d%d !      d&               Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.ejB                  d-        Z/ejB                  d.        Z0ejB                  d/        Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7ejB                  d6        Z8d7 Z9d8 Z:d9 Z;d: Z<d; Z=d< Z>y=)?LongTestc                 .   | j                  |d       |t        z  }|t        z
  dz   }d}d}t        t        j                         t        dz  z        dz  }||k  r|dz	  dz   }t	        |||z
        }| j                  d|cxk  xr	 t        k  nc        ||z   }||z  }|dz  r|d|z  dz
  z  }t        t        j                         t        dz  z        }||k  r| j                  ||cxk  xr |k  nc        t        j                         dk  r| }|S )Nr   r   r         ?)assertGreaterSHIFTintrandommin
assertTrue)selfndigitsnbits_hinbits_loanswernbitsr/   bitss           r!   getranzLongTest.getran{   s   7A&U?e#a'519-.2hFa<DtX-.DOOA../DLEt^F1uAI?3FMMOuqy12A h 	E5X56==?S WFr"   c                     d}t        |       D ]&  }|t        z  t        j                  dt              z  }( t        j                         dk  r| }|S )Nr   r5   )ranger7   r9   randintMASK)r=   r@   is      r!   getran2zLongTest.getran2   sO    w 	AAo4)@@F	A==?S WFr"   c                    | j                   }| j                  ||      5  t        ||      \  }}||z  ||z  }}||z  ||z  }	} |||	d        |||d        |||d        ||||z  |z   d       |dkD  r!| j                  d|cxk  xr |k  nc d       n | j                  ||cxk  xr dk  nc d       d d d        y # 1 sw Y   y xY w)Nxyzmultiplication does not commutez(divmod returns different quotient than /z#divmod returns different mod than %zx != q*y + r after divmodr   zbad mod from divmod)assertEqualsubTestr)   r;   )
r<   rL   rM   eqr    r/   q2r2pabpbas
             r!   check_divisionzLongTest.check_division   s    \\A\# 	C!Q<DAqT1Q3BsAaCCsC:;q"@Aq";<q!A#'671uQ

,ABA

,AB	C 	C 	Cs   BCC
c                    t        t        dt        dz               t        t        t        t        dz               z   }|j	                  t        dz         |D ]A  }| j                  |      }|D ])  }| j                  |      xs d}| j                  ||       + C | j                  dd       | j                  dd       | j                  dd	       | j                  d
d       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       y )Nr         l   !Us/w3al   ZW3al   +Q@{dB]OlNl   OOlNl   teo%gqCgx<l   &ghrsGl   Q5K4+o-bkl   C4+o-bkl   .#wflD&I-Xl   ZnSu9bl   cv<Il   rdFBu'pl   PhbIi|$l   1m{Wqi8l   s~5^Fiy+l   'H
<{Cl   `<{Cl   ED_5(Nl   oybal   =2zz6 l   9tm)listrE   	MAXDIGITSKARATSUBA_CUTOFFappendrC   rU   )r<   digitslenxrL   lenyrM   s         r!   test_divisionzLongTest.test_division   s|   eAy{+,tE:J6F6K5M 0N N&*+ 	*DD!A *KK%*##Aq)*	* 	8/	1@)	+@)	+A3	5 	@2	4@3	5 	NI6/;.	:.?.?,n=r"   c                    t        t        dd            t        t        t        t        dz               z   }|j                  t        dz  t        dz  g       |D cg c]  }|t        z   }}|D ]i  }d|z  dz
  }|D ]Z  }||k  r	| j                  ||      5  d|z  dz
  }||z  }d||z   z  d|z  z
  d|z  z
  dz   }	| j                  ||	       d d d        \ k y c c}w # 1 sw Y   nxY w)Nr      
   d   )abitsbbits)rY   rE   r[   extendr7   rO   rN   )
r<   r]   digitrB   re   r*   rf   r+   rL   rM   s
             r!   test_karatsubazLongTest.test_karatsuba   s'   eAqk"T%0@0@20E+G &H H'",.>.DEF+12%22  	+Eeq A 
+5=\\U\; +eq(AAA.u*&u*& A $$Q*+ +
+	+	 3+ +s   C7C""C+c                    | j                   }| j                  |      5   ||dz  d        ||dz  |        ||dz  |        ||dz  |        ||dz  d        ||dz  |         |||          |||z  |        |||z  |        |||z  d        ||| z  d        ||| z  d        ||| z  d        || d| z           || |dz
          d d d        t        dt        z        D ]x  }d|z  }| j                  |||      5   |||z  |z	  |        |||z  ||z	          |||z  ||z          ||| z  ||z	  |z          ||| z  ||dz
   z         d d d        z y # 1 sw Y   xY w# 1 sw Y   xY w)NrL   r   r
   r   r   )rL   r   p2)rN   rO   rE   r7   )r<   rL   rP   r   rl   s        r!   check_bitop_identities_1z!LongTest.check_bitop_identities_1   s   \\A\ 	q1uaLq1uaLq1uaLq2vqMq2vrNq2vrNqA2#Jq1uaLq1uaLq1uaLqA2vqMqA2vrNqA2vrNr1r6NrQqS6N	  qw 	+AaBQ2. +16Q;"17AF#1r616"1s7AFaK(1s7A"q&	M*+ +	+!	 	$+ +s   B<E1AE=1E:=F	c                    | j                   }| j                  ||      5   |||z  ||z          |||z  ||z          |||z  ||z          |||z  |z  |        |||z  | | z           |||z  | | z           |||z  ||z  ||z   z          |||z  || z  | |z  z          |||z  ||z  | | z  z         d d d        y # 1 sw Y   y xY w)NrK   rN   rO   )r<   rL   rM   rP   s       r!   check_bitop_identities_2z!LongTest.check_bitop_identities_2  s   \\A\# 		+q1ua!eq1ua!eq1ua!eq1uqy!q1uaRj!q1uaRj!q1uq1u!a%()q1uqA2v1"q&)*q1uq1u!qb)*		+ 		+ 		+s   B%CCc                 L   | j                   }| j                  |||      5   |||z  |z  |||z  z          |||z  |z  |||z  z          |||z  |z  |||z  z          ||||z  z  ||z  ||z  z          ||||z  z  ||z  ||z  z         d d d        y # 1 sw Y   y xY w)N)rL   rM   zro   )r<   rL   rM   rr   rP   s        r!   check_bitop_identities_3z!LongTest.check_bitop_identities_3  s    \\Aa\( 	/A{AQK(A{AQK(A{AQK(qAE{QUq1u-.qAE{QUq1u-.	/ 	/ 	/s   A0BB#c           
      X   t         D ]  }| j                  |        t        dt        dz         }|D ]v  }| j	                  |      }| j                  |       |D ]M  }| j	                  |      }| j                  ||       | j                  ||| j	                  ||z   dz               O x y )Nr   r   )specialrm   rE   rZ   rC   rp   rs   )r<   rL   r]   r^   r_   rM   s         r!   test_bitop_identitieszLongTest.test_bitop_identities  s     	-A))!,	-q)A+& 	SDD!A))!, SKK%--a3--aDKKq@P4QRS	Sr"   c                     g }d}|dk  rd| }}|r,t        ||      \  }}|j                  t        |             |r,|j                          |xs dg}dd | ddddd|   z   dj	                  d	 |D              z   S )
Nr   r   -0b0o 0x)r      rc      c              3   &   K   | ]	  }d |     yw)0123456789abcdefN ).0rH   s     r!   	<genexpr>z'LongTest.slow_format.<locals>.<genexpr>1  s     =)!,=s   )r)   r\   r8   reversejoin)r<   rL   baser]   signr/   s         r!   slow_formatzLongTest.slow_format%  s    q5!!D!T?DAqMM#a&!  	A35DzDbd3D9:ww=f==> 	>r"   c                    dt         fdt        fdt        fdt        fdt        ffD ]  \  }} ||      }| j                  ||j                        5  | j                  ||      }| j                  ||       d d d        | j                  |      5  | j                  t        |d      |       d d d         y # 1 sw Y   CxY w# 1 sw Y   xY w)Nr   r}   rc   r~   )rL   mapper)gotr   )
binoctstrreprhexrO   __name__r   rN   r8   )r<   rL   r   r   r   expecteds         r!   check_format_1zLongTest.check_format_13  s    Hq#hS	B:CyP 	1LD&)C&//: 0++At4  h/0 #& 1  S!a01 1	10 01 1s   %B8C8C	C	c                     t         D ]  }| j                  |        t        d      D ]<  }t        dt        dz         D ]$  }| j	                  |      }| j                  |       & > y )Nrc   r   )ru   r   rE   rZ   rC   )r<   rL   rH   r^   s       r!   test_formatzLongTest.test_format<  sh     	#A"	#r 	'Aa1- 'KK%##A&'	'r"   c                    ddddz  fg}|D ]I  \  }}dD ]?  }dD ]8  }||z   |z   }|}|dk(  r|t         ur| }	 | j                  t        |      |       : A K | j                  t         t        d       | j                  t         t        d	       | j                  t         t        d
       | j                  t         t        d       | j                  t         t        dd       | j                  t         t        dd       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        d d      d       | j                  t         t        d!d       | j                  t         t        d"d       d#d$d%d&d'd(d)d*d+d,dz  d,dz   g}|D ]  }	| j                  t         t        d-|	         | j                  t         t        d.       y # t         $ r Y w xY w)/N)100000000000000000000l      Fx:^V e10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000rc   rd   )r{   +rx   )r{    	z  		  rx   123L123l0Lz-37L0x32Lr~   1L      +   000r   0o123S   0x123i#  0b100r   z	 0O123   z 0X123  z 0B100 0z+0z-00008z-012395is        i   l                    l         l        r   42u   こんにちは)
ValueErrorrN   r8   assertRaises)
r<   LLsvr   prefixssvvinvalid_basesr   s
             r!   	test_longzLongTest.test_longD  s    'C(
  
	DAq$ 	7 F$*BBs{q
':R((R"5	
	 	*c62*c62*c40*c62*c7B7*c44T2+ 	UA*Wa"-Wa#.Wa!,[!,b1Z+S1Y*A.S!a(T1q)T1q)T1q)*c43*c9a8 !5&(!5&(S&1c6'
 " 	;Dj#tT:	;
 	*c+KLO & s   K	K$	#K$	c                      G d d      }| j                  t        t         |               G d d      }| j                  t              5  | j                  t         |             d       d d d        y # 1 sw Y   y xY w)Nc                       e Zd Zd Zy)*LongTest.test_conversion.<locals>.JustLongc                      yN*   r   r<   s    r!   __long__z3LongTest.test_conversion.<locals>.JustLong.__long__      r"   N)r   
__module____qualname__r   r   r"   r!   JustLongr     s    r"   r   c                       e Zd Zd Zd Zy)+LongTest.test_conversion.<locals>.LongTruncc                      yr   r   r   s    r!   r   z4LongTest.test_conversion.<locals>.LongTrunc.__long__  r   r"   c                      y)N  r   r   s    r!   	__trunc__z5LongTest.test_conversion.<locals>.LongTrunc.__trunc__  s    r"   N)r   r   r   r   r   r   r"   r!   	LongTruncr     s    r"   r   r   )r   	TypeErrorr8   assertWarnsDeprecationWarningrN   )r<   r   r   s      r!   test_conversionzLongTest.test_conversion}  si    	 	 	)S(*5	 	 01 	5S-t4	5 	5 	5s   
!A44A=c                     	 t        |      }	 t        |      }dj                  |||      }| j	                  |||       y # t        $ r d}Y @w xY w# t        $ r d}Y Ew xY w)NoverflowzAError in conversion of integer {} to float.  Got {}, expected {}.)r   r   r   formatrN   )r<   r   actualr   msgs        r!   check_float_conversionzLongTest.check_float_conversion  ss    	 1XF	"#AH&&,fQ&A 	3/  	 F	 
  	"!H	"s"   A  A  AAAAc                 (   g d}|D ]:  }| j                  t        |      |       | j                  t        |       |        < dD ]K  \  }}t        d      D ]8  }| j                  t        t        d|z  d|z   z              d|z  d|z   z         : M dD ]K  \  }}t        d      D ]8  }| j                  t        t        d|z  d|z   z              d|z  d|z   z         : M t        t              }dt
        z  }||z   dz  }| j                  t        |      t               | j                  t        |dz         t               | j                  t        |dz
        t               | j                  t        t        |       | j                  t        d|z
        t                | j                  t        t        |        | j                  t        t        |dz
         | j                  t        t        |       | j                  t        t        |dz          | j                  t        t        d|z  dz
         | j                  t        t        d|z         | j                  t        t        ||z         t        d	      D ]m  }d|z  d
z  dz   }d|z  dz  }| j                  t        t        |            |       d|z  d
z  }d|z  dz  }| j                  t        t        |            |       o |dz
  ||dz   |dz
  ||dz   |dz
  ||dz   d|z  dz
  d|z  ||z  g}|j                  |       t        dd      D ]-  }t        dd      D ]  }|j                  d|dz   z  |z           / |D ]%  }	| j                  |	       | j                  |	        ' y )N)r   r   r   l    l    l                       l   l             l         )r   r   )r   r   rX   r   r   r   rb   r   )   r   r   r}   r   r   r   ))r   r   r   )r   r   r   r   r   )r   r}   r   )r}   r}   )	   r}   )rc   r}   )      )r   r   )   r   )rW   r~   )r   r~   r   r   rd   l         r   r}      5   )rN   r   rE   r8   DBL_MAXDBL_MAX_EXPr   r   rg   r\   r   )
r<   exact_valuesrL   rM   pint_dbl_max	top_powerhalfwaytest_valuesvalues
             r!   test_float_conversionzLongTest.test_float_conversion  s   	"  	,AU1Xq)UA2Y+	,
 M 	MDAq2Y M  U1a4q>%:!;QT57^LM	M3 	MDAq 2Y M  U1a4q>%:!;QT57^LM	M 'l{N	*Q.{+W5{1}-w7wqy)73-8qy)G84-9-	!<-	:-	!<-)A>-)<-	)0CDs 	/A1	"Q&A1	"ASq]A.1	"A1uASq]A.	/ M;AAIw!aKIaKiKM1Y;	)(;	
 	<(r1 	2A4% 2""1qt9q=12	2 ! 	0E''.''/	0r"   c                    dD ]&  }| j                  t        t        |            |       ( d}ddz  }| }|||t        d}dD ]  }| j	                  t
        t        ||         | j                  t        |      t        |      d       y )N)g             r         ?       @X  123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345r   i0u  )hugemhugeshuger   )$float(huge)float(mhuge)zcomplex(huge)zcomplex(mhuge)zcomplex(huge, 1)zcomplex(mhuge, 1)zcomplex(1, huge)zcomplex(1, mhuge)z	1. + hugez	huge + 1.z
1. + mhugez
mhuge + 1.z	1. - hugez	huge - 1.z
1. - mhugez
mhuge - 1.z	1. * hugez	huge * 1.z
1. * mhugez
mhuge * 1.z
1. // hugez
huge // 1.z1. // mhugezmhuge // 1.z	1. / hugez	huge / 1.z
1. / mhugez
mhuge / 1.z
1. ** hugez
huge ** 1.z1. ** mhugezmhuge ** 1.zmath.sin(huge)zmath.sin(mhuge)zmath.sqrt(huge)zmath.sqrt(mhuge)z(float(shuge) should not equal int(shuge))rN   r   r8   r   r   r   evalassertNotEqual)r<   rL   r   r   r   	namespacetests          r!   test_float_overflowzLongTest.test_float_overflow  s    * 	/AU3q6]A.	/ Ez!EE4P	 	DD  mT4C!	D( 	E%L#e*6	8r"   c                    t        j                  t         j                        }t        t	        d            g dz   D ]Z  }d|z  }t        j                  |      }| j                  ||       ||z  }t        j                  |      }| j                  ||       \ ddz   ddfD ]L  }| j                  t        t         j                  |       | j                  t        t         j                  |       N y )Nrc   )rd     '  r   r  r   r   )	r   log10erY   rE   assertAlmostEquallogr   r   )r<   LOG10Er.   r   r  r   r	  bads           r!   	test_logszLongTest.test_logs  s    DFF#b	?%77 		2C#IEJJu%E""5#. V|H((5/C""31		2 %Z="a' 	;Cj$((C8j$**c:	;r"   c                 p  
 | j                   } G 
fdd      
g d}dD ]H  }|j                  |dz
  |dz
  ||dz   |dz   t        |dz
        t        |      t        |dz         g       J |j                  ddd	t        j                  t        t        j                        g       t        d
      }|j                  ddd	ddz  |dz
  ||dz   g       |j                  |D cg c]  }|  c}       |D ]  } 
|      }|D ]  } 
|      }||kD  ||k  z
  }| j                  |||      5  ||kD  ||k  z
  }	 |||	        |||k(  |dk(          |||k7  |dk7          |||k  |dk          |||k  |dk          |||kD  |dkD          |||k\  |dk\         d d d          y c c}w # 1 sw Y   xY w)Nc                   <    e Zd Zd Z fdZd Zd Zd Zd Zd Z	y)	)LongTest.test_mixed_compares.<locals>.Ratc                 $   t        |t              r|| _        d| _        y t        |t              rt        j                  t        |            \  }}|dk(  sd|cxk  rdk  sJ  J d}d}|rPt        j                  ||      }t        |      }||z	  dk(  sJ ||z  |z  }||z  }d|cxk  rdk  sJ  J ||z  }|rP|dk\  r||z  }d}n|}d| z  }|dk  r| }|| _        || _        t	        |      t	        |      z  |k(  sJ y t        d|z        )Nr   r   r5   r      r   zcan't deal with %r)

isinstancer8   r   r-   r   r   frexpr$   r   r   )	r<   r   fr  CHUNKtoprh   r   r-   s	            r!   __init__z2LongTest.test_mixed_compares.<locals>.Rat.__init__  s<   eS)"DFDFu-::c%j1DAq6SA^^33^33 EC JJq%0 #A$~222"e|u4U
"a~#~-~-~U
  Av1H!GqyBDFDF 8eAh.%777#$85$@AAr"   c                     t        |      s |      }| j                  |j                  z  | j                  |j                  z  }}||kD  ||k  z
  S )N)r  r   r-   )r<   otherrL   rM   Rats       r!   _cmp__z0LongTest.test_mixed_compares.<locals>.Rat._cmp__G  sL    !%-JEvv'%'')91A!a%((r"   c                 *    | j                  |      dk(  S Nr   r  r<   r  s     r!   __eq__z0LongTest.test_mixed_compares.<locals>.Rat.__eq__L      {{5)Q..r"   c                 *    | j                  |      dk\  S r  r  r  s     r!   __ge__z0LongTest.test_mixed_compares.<locals>.Rat.__ge__N  r!  r"   c                 *    | j                  |      dkD  S r  r  r  s     r!   __gt__z0LongTest.test_mixed_compares.<locals>.Rat.__gt__P      {{5)A--r"   c                 *    | j                  |      dk  S r  r  r  s     r!   __le__z0LongTest.test_mixed_compares.<locals>.Rat.__le__R  r!  r"   c                 *    | j                  |      dk  S r  r  r  s     r!   __lt__z0LongTest.test_mixed_compares.<locals>.Rat.__lt__T  r&  r"   N)
r   r   r   r  r  r   r#  r%  r(  r*  )r  s   r!   r  r    s(    &BP)
//./.r"   r  )r   gMbP?gGz?r   g      ?g@xDZbti)g      Bg      Cg      @Cr   g333333?r   r   r   r+  i N  )rL   rM   Rcmp)rN   rg   r8   r   maxsizer   rO   )r<   rP   casestrL   RxrM   Ryr,  xycmpr  s             @r!   test_mixed_compareszLongTest.test_mixed_compares  s   7	. 7	.r 8 + 	7ALL!c'1s7Aq3wCac(CFC!H6 7	7 	aAs{{E#++,>?@ JaAqEz1Q31Q378%(Qqb() 	*AQB *VRBG,\\A\6 *Uq1u-EtUOqAvtqy)qAvtqy)q1udQh'qAvtqy)q1udQh'qAvtqy)* **	* )* *s   !
F'+A/F,,F5c           
      F   | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd	      d
       | j                  t        dd	      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        d d      d       | j                  t        d d      d       | j                  t        t        d!d"      d      d!       | j                  t        t        d!d"      d      d#       | j                  t        t        d!d"       d      d$       | j                  t        t        d!d"       d      d%       | j                  t        t        d&d'       | j                  t        d&d(      d)       | j                  t        d&d*      d+       | j                  t        dd,      d       | j                  t        d d,      d       | j                  t        dd,      d-       | j                  t        dd,      d.       | j                  t        dd/      d-       | j                  t        dd/      d.       | j                  t        dd0      d1       | j                  t        dd0      d.       | j                  t        dd2      d3       | j                  t        dd2      d.       | j                  t        t        d&d4       | j                  t        d&d5      d6       | j                  t        dd7      d8       | j                  t        d d7      d9       | j                  t        dd7      d:       | j                  t        dd7      d;       | j                  t        dd<      d:       | j                  t        dd<      d;       | j                  t        dd=      d>       | j                  t        dd=      d;       | j                  t        dd?      d@       | j                  t        dd?      d;       | j                  t        t        d&dA       | j                  t        dBdC      dD       | j                  t        t        ddE       | j                  t        t        ddF       | j                  t        t        ddG       | j                  t        t        ddH       | j                  t        dIt        ddJ       | j                  t        dIt        ddK       | j                  t        dIt        ddL       | j                  t        dIt        ddM       | j                  t        dNt        ddO       | j                  t        dPt        ddQ       t        t        dR      t        dS      dz         D cg c]  }t        |       c}t        t        dT      t        dU      dz         D cg c]  }t        |       c}z   D ]  }|dVvs| j                  t        t        dW|       | j                  t        t        d|       | j                  t        t        d|       | j                  t        t        dXdYz  |       | j                  t        t        dXdYz   |        dZD ]8  }d[D ]1  }| j                  t        ||      t        t        |      |             3 : y c c}w c c}w )\Ni[r-   	123456789,z123,456,789_123_456_789r   rx   1r
   z-1z-3z  1z -1z+3z +1z 3r   z 1rX   rL   3Xi  4d2i.z-4d28xz     4d2z    -4d2ber~   BEz-bez-BEIz,x_x	4996_02d2_X	4996_02D2o2322z-2322z-oz oz 2322z+oz+2322z,o_o111_4540_1322r+   11z-1110011010010z-10011010010z-bz bz 10011010010z+bz+10011010010z,b90  _b11_0000_0011_1001z1.3_cz,cz+czCannot specify bothz_,z,_z_,dz,_dzCannot specify ',' with 's'z,szCannot specify '_' with 's'_sr*   rr   AZzbcdoxXeEfFgGn%r   r   rd   zeEfFgG%)r   r   r
   rd   rA  i.i)
rN   r   r8   r   r   assertRaisesRegexrE   ordchrr   )r<   rL   format_specr   s       r!   test__format__zLongTest.test__format__r  s   	3/=	3/=	3/?	3/? 	3-C$/4%0D)514%0D)514%0D)513.C$/ 	3-3-c*E2s+V4d+Z8t,j9c*E2s+V4C$/C$/D"s3T:D"s3T:T24e<T24e<*fj$?
D1;?
D1;? 	3-C$/c*F3s+W5d+V4t,g6d+W5t,g6d+W5t,g6*fj$?
D1?C 	3.C%0c*M:s+^<d+];t,n=d+^<t,n=d+^<t,n=*fj$?t,.AB 	*fa7*fa6*fa6*fa6 	z+@&!TRz+@&!TRz+@&!USz+@&!USz+H&RSUYZz+H&RSUYZ .33s8SXaZ-HISVI-23s8SXaZ-HISVIJ 	NK"22!!*faE!!*faE!!*fb+F!!*fafkJ!!*f3iM	N % 	DKG D  {!;!'ek!BDD	D JIs   0b'bc                     | j                  t        t        t        d             | j                  t        t        t        d             | j                  t        t        t        d             y )Ninfz-infnan)r   r   r8   r   r   r   s    r!   test_nan_infzLongTest.test_nan_inf  sD    -eEl;-eFm<*c5<8r"   c                    | j                  t              5  ddz  }d d d        | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       y # 1 sw Y   xY w)Nr   r   rX   r   r>  r   r%   rN   r<   r7  s     r!   test_mod_divisionzLongTest.test_mod_division  s    01 	AA	 	!$1%2&B'#!$!$1%	 	s   B55B>c                    ddz  }| }| j                  ||z  d       | j                  ||z  d       | j                  ||z  d       | j                  ||z  d       | j                  d|z  d       | j                  d|z  d       | j                  d|z  d       | j                  d|z  d       | j                  d|z  |dz	  z   |z  d       | j                  d|z  |dz	  z   |z  d       | j                  d|z  |dz	  z   |z  d       | j                  d|z  |dz	  z   |z  d       | j                  ||dz  z  d	       | j                  d
|z  |z  d
       ||d}dD ]  }| j                  t        t        ||         dD ]$  }t        ||      }| j                  |dd|z         & dD ]  }| j                  t        t        ||         y )Nr   i@  r   r   r   i  g     Ԅ@g     Ԅr5   i@B )r   r   )r   r   zhuge / 1zhuge / 2z	huge / -1z	huge / -2zmhuge / 100zmhuge / 200)z1 / hugez2 / hugez	-1 / hugez	-2 / hugez100 / mhugez200 / mhugezexpected underflow to 0 from %r)zhuge / 0z	mhuge / 0)rN   r   r   r   r%   )r<   r   r   r   r   	underflowr0   zeros           r!   test_true_divisionzLongTest.test_true_division  s   Ezc*,t,t,T3'T3'UC(UC(#*	2d:EB#+!4=uE#*	2e;VD#+!4<fE+S1'D.D0':!E2	7 	HH mT8YG	H
7 	LI)Y/FVS>JL	L . 	HD/tYG	Hr"   c                    | j                  t              5  ddz  }d d d        | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       y # 1 sw Y   xY w)Nr   r   r
   rX   r   r   r_  r`  s     r!   test_floordivzLongTest.test_floordiv  s    01 	QA	 	#"%"%1%A&2&2&!$A&2&2&!$!	 	s   C==Dc           
      b   |r)t        t        |      t        |            dt        z  k  ry	 t        t	        ||            }	 t        ||z        }| j                  ||dj                  ||||             y# t
        $ r d}Y Bt        $ r d}Y Nw xY w# t
        $ r d}Y Pt        $ r d}Y \w xY w)zVerify that the result of a/b is correctly rounded, by
        comparing it with a pure Python implementation of correctly
        rounded division.  b should be nonzero.r   Nr   zerodivisionz7Incorrectly rounded division {}/{}: expected {}, got {})	r   r$   r(   r   r1   r   r%   rN   r   )r<   r*   r+   
skip_smallr   r   s         r!   check_truedivzLongTest.check_truediv  s     #c!fc!f-<?	&GAqM*H	!q1u+C 	3 )//5vaHc/J	L  	"!H  	&%H	&
  	C  	! C	!s/   A7 B 7B
BBB.!
B.-B.c                    | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  ddt        z  z  d       | j                  dd	dt        t        z
  z  z         | j                  ddd
z  z  d       | j                  ddddz  z         dt        t        t        t        t        z
  f}|D ]  }t	        |dz
  |dz         D ]h  }| j                  ddt        |d      z  z  ddt        | d      z  z         | j                  ddt        |d      z  z  ddt        | d      z  z         j  ddddddd
z  dddddddz   fD ]L  }t	        dd      D ];  }| j                  |t        z  |z   |       | j                  |t        z  |z   |        = N t	        d      D ]7  }| j                  dt        z  dz   dz  ddz  z  d|z  z   dt        z  dz         9 | j                  dd       | j                  d d!       t	        d"      D ]8  }| j                  d|dz   z  d|z         | j                  d|z  d|dz   z         : ddd#dd$d%dd&ddd
z  dddddddz   fD ]2  }t	        dd      D ]!  }| j                  dt        z  |z  |z   |       # 4 t	        d'd(      D ]  }| j                  |dd)z          d*dd
z  dd"z  fD ]  }t	        d"      D ]  }t        j                  d|      }t        j                  |d|z  dz         }	| j                  ||	       | j                  | |	       | j                  ||	        | j                  | |	          t	        d+      D ]  }
t        j                  d"      }t        j                  dd"      }t        j                  d|z        }t        j                  dd|z        }| j                  ||       | j                  ||        | j                  | |       | j                  | |         y ),N{   r   i8rX   r>  ige~ r   rL  iNF rd   í l       90r   Q   r   i0& iC r      r
   r   ii)   2   rc         i
  l   E,J_   l     Jb   r  r   r}   r~       i   i4  l    d(	 r  )	rk  r   r(   r'   rE   r   r&   r9   	randrange)r<   basesr   r.   mr   rH   Mr*   r+   r7  a_bitsb_bitsrL   rM   s                  r!   $test_correctly_rounded_true_divisionz-LongTest.test_correctly_rounded_true_division9  s    	3"4#1a 1b!1a ;K7?5&1|k/I+J"JK5C</;ae4 L+kL8: 	PDTBYr	2 P""5CQK#7q#sdA,9NO""5CQK#7q#sdA,9NOP	P Q2uafb"c6BF74 	?A3^ ?""1%5#5#91=""1%5#5#9A2>?	? s 	2A <! 3U:1c6AAqDHl?502	2 	1d# 	02GHt 	1ArAaCy"a%0r1ub1Q3i0	1
 Q1aRUAsFb"c6BF74 	=A3^ =""1l?1#4q#8!<=	= sB 	+Aq!T'*	+ "c'2t8, 	+A4[ +$$Q*$$Q!A.""1a(""A2q)""1qb)""A2r*+	+ u 	'A%%d+F%%a.F  F+A  AvI.Aq!$q1"%r1%rA2&	'r"   c                    | j                  t              5  ddz   d d d        | j                  t              5  dddz   z   d d d        | j                  t              5  ddz	   d d d        | j                  t              5  dddz   z	   d d d        y # 1 sw Y   {xY w# 1 sw Y   `xY w# 1 sw Y   IxY w# 1 sw Y   y xY w)Nr   r>  r   r  )r   r   r   s    r!   test_negative_shift_countz"LongTest.test_negative_shift_count  s    z* 	"H	z* 	AI,	z* 	"H	z* 	AI,	 		 		 		 		 	s.   B
B" B.
B:B"B+.B7:Cc                 @   | j                  dd       | j                  dd       | j                  t              5  ddz   d d d        | j                  dddz  z  d       | j                  t              5  dddz   z   d d d        y # 1 sw Y   IxY w# 1 sw Y   y xY w)Nr   r
   r   r  )rN   r   r   r   s    r!   test_lshift_of_zerozLongTest.test_lshift_of_zero  s    #!$z* 	G	qDy)1-z* 	19	 		 		 	s   B5
BBBc                     | j                  dt        j                  z  d       | j                  dt        j                  dz   z  d       y )Nr   r   rN   r   r-  r   s    r!   test_huge_lshift_of_zeroz!LongTest.test_huge_lshift_of_zero  s:    
 	ckk)1-s{{Q/3r"   r  g?F)memusedry_runc                 x    | j                  dt        j                  dz   z  ddz  t        j                  z         y )Nr   r  r  )r<   sizes     r!   test_huge_lshiftzLongTest.test_huge_lshift  s/     	s{{T12AI4LMr"   c                    ddz  }| j                  d|z	  d       | j                  d|z	  d       | j                  d|z	  d       | j                  d|z	  d       | j                  d	d
z  |z	  d       | j                  d	d
z   |z	  d       y )Nr   r  r   r   ir
   ic  ir   r   rN   )r<   
huge_shifts     r!   test_huge_rshiftzLongTest.test_huge_rshift  s    $Y
z)1-#*,b1+Q/%J.3C:-q1!S&J.3r"     g?c                     ddz  dz   t         j                  z  }| j                  |t         j                  dz   z	  ddz  dz          | j                  |t         j                  dz   z	  d       y )Nr   r  r   i  rb   r  r   )r   r-  rN   )r<   r  r   s      r!   test_huge_rshift_of_hugez!LongTest.test_huge_rshift_of_huge  s]     cRCKK/#++/2Q#XNC#++"45q9r"   c                    | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  ddz  d	z	  dd
z         | j                  ddz   d	z	  dd
z          | j                  ddz  d	z   d	z	  dd
z         | j                  ddz  d	z    d	z	  dd
z   d	z
         y )Nr   iii1  iir   r   r      r  r   s    r!   test_small_rshiftzLongTest.test_small_rshift  s   "%S)"%S)C(t,C(t,C1af-!S&A3w/!S&1**AsF31c6A:!+afWq[9r"   c                    | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  ddz  dz	  ddz         | j                  ddz   dz	  ddz          | j                  dt        t        z  z
  t        z	  t                | j                  t        dz
  t        t        z  z
  t        z	  t                y )	Nr   r
   r   r>  r   r   w   r   )rN   BASEr7   r   s    r!   test_medium_rshiftzLongTest.test_medium_rshift  s    !$R(A&r*C1af-!S&A3w/ 	!d4i-E1D59$(T$Y.584%@r"   c                    | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  ddz  dz	  ddz         | j                  ddz   dz	  ddz          y )Nr   r
   r   r   rv  `   r  r   s    r!   test_big_rshiftzLongTest.test_big_rshift  s~    1%b)Q'+C2q"u-!S&BB/r"   c                    | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  ddz  dz  ddz         | j                  ddz   dz  ddz          y )	NT   iib  ir   r  r   r   r  r   s    r!   test_small_lshiftzLongTest.test_small_lshift  s~    "%S)4(e,C1af-!S&A3w/r"   c                     | j                  dd       | j                  dd       | j                  dd       | j                  dd       y )Ni T  i i  i <r  r   s    r!   test_medium_lshiftzLongTest.test_medium_lshift  sB    %(V,F+w/r"   c                    | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  ddz  dz  ddz         | j                  ddz   dz  ddz          y )	Nl        l     l       l    r   r   rv     r  r   s    r!   test_big_lshiftzLongTest.test_big_lshift  s~    :.k2\26C2q#v.!S&BC0r"   c                 x    ddz  }| dz   }|dz   }| j                  ||z   d       | j                  ||z
  d       y )Nr   rd   r   )assertIs)r<   r*   r+   cs       r!   #test_small_ints_in_huge_calculationz,LongTest.test_small_ints_in_huge_calculation  sC    HBFEa!eQa!eQr"   c                    | j                  t        ddd      d       | j                  dd       d\  }}}| j                  ||z  |z  d       | j                  t        ddd      d       | j                  dd       d	\  }}}| j                  ||z  |z  d       | j                  t        dd
dd
z  dz
        d       | j                  dd
z  dd
z  dz
  z  d       dd
dd
z  dz
  }}}| j                  ||z  |z  d       y )Nrc   rX     r   )rc   rX   r     r   r   )r   r  r   rd   )r  pow)r<   r*   r   rz  s       r!   test_pow_uses_cached_small_intsz(LongTest.test_pow_uses_cached_small_ints  s    c"aoq)mQ'1aa1fqj!$c!R-q1-q1$1aa1fqj!$c!S!S&1*-q1a3h!s(Q,/3S!S&1*a1a1fqj!$r"   c                    ddz  }| j                  |dz   |z  d       | j                  |dz   |z  d       | j                  ||dz  z  d       | j                  ||dz  z  d       t        d|z  dz   |      \  }}| j                  |d       | j                  |d       t        d|z  dz   |      \  }}| j                  |d       | j                  |d       t        d| z  dz
  |       \  }}| j                  |d       | j                  |d       t        d|z  dz
  |       \  }}| j                  |d       | j                  |d       y )	Nrc   rd   r   r   r   rX   r
   r>  )r  r)   )r<   bigr    r/   s       r!   "test_divmod_uses_cached_small_intsz+LongTest.test_divmod_uses_cached_small_ints  s<   CisQw#oq)sQw3&*ccQh'+ccRi("-a#gk3'1aab3hnc*1aaaC4j1nsd+1aaa#gkC4(1aar"   c           	         t        dd      D ]  }| j                  ||dz          | j                  ||dz         | j                  ||dz
         | j                  ||dz         | j                  ||dz         | j                  ||dz         | j                  ||dz         | j                  ||         | j                  ||dz         | j                  |t        t        |                   | j                  ||dz  dz	  t        |              d}| j                  ||z
  d       | j                  d|z  d       y )Nrp    r   r   r
   r   l            )rE   r  r8   r   )r<   rH   s     r!   test_small_intszLongTest.test_small_ints1  s   r3 	.AMM!QU#MM!QU#MM!QU#MM!Q!V$MM!QV$MM!QU#MM!QU#MM!qbS!MM!QT"MM!SQ[)MM!QT1Wc!f-	. a!eQa!eQr"   c                    d}t        dd      D ]  }|j                         }| j                  |t        t	        |      j                  d                   |dk7  r2| j                  d|dz
  z  t        |      cxk  xr d|z  k  nc        n| j                  |d       |dk7  s| j                  |dt        j                  t        j                  t        |            t        j                  d      z  |z         z           | j                  dj                         d       | j                  dj                         d       | j                  dj                         d       | j                  dj                         d       | j                  d	j                         d       d
D ]  }d|z  }| j                  |dz
  j                         |       | j                  d|z
  j                         |       | j                  |j                         |dz          | j                  | j                         |dz          | j                  |dz   j                         |dz          | j                  | dz
  j                         |dz           y )Ng|=ii  z-0br   r   r   r
   r   )r   rX   r   r~   ro  r  rv  !   ?   @      )rE   r   rN   lenr   lstripr;   r$   r   floorr	  )r<   tinyrL   krH   r*   s         r!   test_bit_lengthzLongTest.test_bit_lengthC  s   vu% 	>AAQCFMM%$8 9:AvAaCCF 9QT 9:  A&Av
   A

Q(!4t;)= %= >	>$ 	!)1-!)1-"*A.!)1-"*A.< 	7A1Aac--/3ac--/3a^^-qs3qb__.!4ac--/15qbd..0!A#6	7r"   c                    t        dd      D ]:  }| j                  |j                         t        |      j	                  d             < dD ]  }d|z  }| j                  |j                         d       | j                  |dz
  j                         |       | j                  |dz  j                         d       | j                  |dz
  d	z  j                         |d
z
          y )Nir  r9  )rc   ro  r  r  A   i  iZ i r   r   r  r   i  r}   )rE   rN   	bit_countr   count)r<   r*   r.   s      r!   test_bit_countzLongTest.test_bit_counte  s    ud# 	?AQ[[]CFLL,=>	? > 	CC3AQ[[]A.a!e..0#6a"f//115q1um668#'B	Cr"   c                 
   i ddddddddddddddd	dd
ddddddddddddddddddddd}t        ddd      D ]_  }|j                         D ]J  \  }}t        ||z   d      }||z   }| j                  ||       | j	                  t        |      t               L a | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        d d      d       | j                  t        d!d      d"       | j                  t        d#d      d"       | j                  t        d$d      d%       | j                  t        d&d      d%       | j                  t        d'd      d(       | j                  t        d)d*      d+       | j                  t        d,d*      d-       | j                  t        d.d      d/       | j                  t        d.d      d0       | j                  t        d.d*      d1       | j                  t        d.d2      d3       | j                  t        d.d4      d5       | j                  t        d.d6      d7       | j                  t        d.d8      d9       | j                  t        d.d:      d;       | j                  t        d.d<      d=       | j                  t        d.d>      d?       | j                  t        d.d@      d       | j                  t        d.dA      d       | j                  t        d.dB      d       t        dd"      D ]M  }t        d|z  dCz   d*      }d|z  dDz   }| j                  ||       | j	                  t        |      t               O t        d      D ]e  }t        d"      D ]U  }	t        j                  dEdF      }
t        |
|      }| j                  ||
       | j	                  t        |      t               W g dGdHdIdJdd"z  dd"z  fD ]  }| j                  t        dK|      dK         t        d"      D ]T  }	t        j                  dEdF      }
t        |
      }| j                  ||
       | j	                  t        |      t               V dL}|D ]  }| j                  t        t        d|         y )MNr   r   r   rX   r   rb   r   rc   r   r}   r   r   r   r   rW   r   rw  r~   )ro        ii  r
   ijr   i8ikrS  iii1   rr  3   rd         ru  rt     i,  iԡ r>  i i i l   ! l   ! l   ~! l    ! r   l   ! rp  l   `! il    ! r^  l    '! il    z+ il    v|o rs  l    ,Gx iiiiF i ir  r   r   r   r   i{ )brianr   y                )rE   itemsroundrN   r  typer8   r9   rx  r   r   )r<   	test_dictoffsetr  r   r   r   expectr   rH   rL   huge_nbad_exponentsr  s                 r!   
test_roundzLongTest.test_roundp  sG   8Qq 8!A 8q 8Aa 81 8a 8r8R8!"28'(8-/846r8;=b8BDR8IKB88r8&(RB8	 D#r* 	.F!) .1AfHb)V8  h/d3i-	.	. 	tR$/tR$/sB.sB+sB+r2*q"q)q"q)r2*r2*r2,sB-sB-sB-sB-vr*F3vr*F3{B/={B/={B/={B/={B/={B/={B/={B/={B/={C0+>{C0!4{C0!4{D115 r3 	*AA+CUV^FS&)MM$s)S)		* q 	.A3Z .$$VU3Aqk  a(d3i-	.	. uguafb#gE 	>FU7F3W=	> s 	*A  /A(CS!$MM$s)S)		* + 	6Ai15	6r"   c                 8    d= fd	}i ddddddd	d
dddddddddddddddddddddd d!d"d#d$} ||d%d&'       i ddddddd	d
dddddddd(dd)dddddd*dddd+dd,d!d-d#d.} ||d/d&'       dddddddd0d1d2d3
} ||d%d'       dddddd*dd+d1d4d3
} ||d/d'        j                  t        dj                  dd%d'        j                  t        dj                  dd%d&'        j                  t        dj                  dd/d'        j                  t        dj                  dd/d&'        j                  t        dj                  d5d%d'        j                  t        dj                  d5d/d'        j                  dj                  dd%      d6        j                  dj                  d7d%      d8        j                  dj                  d7d%      d9        j                  dj                  d7d%d&'      d:        j                  t        dj                  dd%        G d; d<t              } j                  dj                  d |d%            d        j                  dj                  d |d/            d6       y )>NFc           	      b   dd}| j                         D ]  \  }}	 j                  |j                  t        |      ||      |       t        |      dk(  r(|dk(  r#|s!	 j                  |j                         |       	 j                   ||t        |      ||      |        y # t        $ r"}t        dj                  |||            |d }~ww xY w# t        $ r }t        dj                  |            |d }~ww xY w# t        $ r"}t        dj                  |||            |d }~ww xY w)	Nc                      |dk(  rt        |      }n|dk(  rt        t        |            }t         fdD              S )Nlittler  c              3   4   K   | ]  }|d z  z	  dz    yw)r}      Nr   )r   rH   r   s     r!   r   zSLongTest.test_to_bytes.<locals>.check.<locals>.equivalent_python.<locals>.<genexpr>  s     >1a1Q3h$.>s   )rE   reversedbytes)r   length	byteordersignedorders   `    r!   equivalent_pythonz@LongTest.test_to_bytes.<locals>.check.<locals>.equivalent_python  s;    (!&ME%'$U6]3E>>>>r"   r  z4failed to convert {} with byteorder={} and signed={}r   r  +failed to convert {} with default argumentszmCode equivalent from docs is not equivalent for conversion of {0} with byteorder byteorder={1} and signed={2}F)r  rN   to_bytesr  	ExceptionAssertionErrorr   testsr  r  r  r  r   errr<   s          r!   checkz%LongTest.test_to_bytes.<locals>.check  sP   ? #(++- OhC$$c(mYvN " x=A%)u*<V4(((C
O$$) #h-6K )O
 ! C(Ni8:?BCC % 4,I#VD\+0344 ! O(%%+VD)V%DF LOOOsG   -B)  C%D)	C2CC	D  C;;D 	D.D))D.r       r      r
         r         r                    r                   s                        r  Tr                               r              )
r   r   r  r   r  r  r     r          r   r"   rb   s       s        s   c                       e Zd Zy)&LongTest.test_to_bytes.<locals>.SubStrNr   r   r   r   r"   r!   SubStrr  :      r"   r  r  )r   r   r  rN   r   )r<   r  tests1tests2tests3tests4r  s   `      r!   test_to_byteszLongTest.test_to_bytes  s   %	OP
w
w
 
 '	

 '
 +
 
 
 +
 +
 
 
 ;
 O
 ?
  O!
" o#
& 	feD)
w
w
 
 '	

 '
 +
 
 
 +
 +
 
 
 ;
 K
 ?
  O!
" o#
& 	fht, "
 	feE* "
 	fhu--#E%P-#E$O-#HUS-#HTR-"5O-"8ER!a/5!a/1HI!a/1HI"q%=0	2-!q%@	S 	!a7A!a)9:C@r"   c                     dM fd	}i ddddddddd	dd
ddddddddddddddddddddddd d!d"d#d$d%} ||d&d'(       i ddddddddd	dd
dddddddddddd)dd*dddddd	ddd d!d"d#d$d+} ||d,d'(       ddddd-ddd d.d"d/d0} ||d&d(       ddddd-ddd d.d"d/d1} ||d,d(        G d2 d3t               } j                  t        |j                  dd&            |        j	                  |j                  dd&      d        j                  t        |j                  dd&d(            |        j	                  |j                  dd&d(      d        j                  t        |j                  dd,            |        j	                  |j                  dd,      d        j                  t        |j                  dd,d(            |        j	                  |j                  dd,d(      d        j	                  t         j                  g d4d&d'(      d#        j	                  t         j                  d4d&d'(      d#        j	                  t         j                  t        d5      d&d'(      d#        j	                  t         j                  t        d5      d&d'(      d#        j	                  t         j                  t        j                  d6d5      d&d'(      d#        j	                  t         j                  t        d5      d&d'(      d#        j                  t        t         j                  dgd&        j                  t        t         j                  dgd7        j                  t        t         j                  dgd8        j                  t        t         j                  d9d&        j                  t        t         j                  d:d&        j                  t        t         j                  dd&        j                  t        t         j                  dd&d'        j                  t        |j                  d9d&        j                  t        |j                  d:d&        j                  t        |j                  dd&        j                  t        t         j                  dd&d'        G d; d<t               }|j                  dd&      } j                  t        |      |        j	                  |d=        G d> d?t               }	|	j                  dd&      } j                  t        |      |	        j	                  |d        j	                  t        |d@dA      dB        G dC dD      }
 G dE dF      } G dG dH      } G dI dJ      } j	                  t         j                   |
             d        j                  t        t         j                   |               j                  t        t         j                   |               j                  t        t         j                   |               G dK dLt              } j	                  t         j                  d |d&            d        j	                  t         j                  d |d,            d       y )NNFc           	      2   dd}| j                         D ]w  \  }}	 j                  t        j                  |||      |       |dk(  r(|s&	 j                  t        j                  |      |       	 j                   ||||      |       y y # t        $ r"}t        dj                  |||            |d }~ww xY w# t        $ r }t        dj                  |            |d }~ww xY w# t        $ r"}t        dj                  |||            |d }~ww xY w)Nc                     |dk(  rt        |       }n|dk(  rt        t        |             }t        d t              D              }|r|r|d   dz  r|ddt	        |      z  z  z  }|S )Nr  r  c              3   2   K   | ]  \  }}||d z  z    yw)r}   Nr   )r   rH   r+   s      r!   r   zULongTest.test_from_bytes.<locals>.check.<locals>.equivalent_python.<locals>.<genexpr>G  s     GTQQqSGs   r
   r   r   r}   )rY   r  sum	enumerater  )
byte_arrayr  r  little_orderedr   s        r!   r  zBLongTest.test_from_bytes.<locals>.check.<locals>.equivalent_pythonA  so    (%)*%5N%'%)(:*>%?NGY~-FGGn.2Dt2KaN 3333Ar"   r  z6failed to convert {} with byteorder={!r} and signed={}r  r  zeCode equivalent from docs is not equivalent for conversion of {0} with byteorder={1!r} and signed={2}r  )r  rN   r8   
from_bytesr  r  r   r  s          r!   r  z'LongTest.test_from_bytes.<locals>.check@  s>   
 #(++- ChC$$tYvF " %f4((NN40$&	C$$)$	&I -C
 ! C(Pi8:?BCC % 4,I#VD\+0344 ! C(Pi8: @CCCsG   (B%B?3C+	B<B77B<?	C(C##C(+	D4DDr"   r   r  s     r  r   r	  r  r
   r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  )r  r  r  r  r  Tr  r  r  )r
  r  r  r  r  r   r  r  )r"   r  r  r  r  r  r  r  r  r  r  )r"   r  r  r  r  r  r	  r  r
  r  r  c                       e Zd Zy)'LongTest.test_from_bytes.<locals>.myintNr  r   r"   r!   myintr(    r  r"   r)  )r  r   r   r  Bzbig zlittle r{    c                       e Zd Zd Zy)(LongTest.test_from_bytes.<locals>.myint2c                 4    t         j                  | |dz         S )Nr   )r8   __new__)clsr   s     r!   r/  z0LongTest.test_from_bytes.<locals>.myint2.__new__  s    {{3	22r"   Nr   r   r   r/  r   r"   r!   myint2r-    s    3r"   r2  r   c                       e Zd Zd Zy)(LongTest.test_from_bytes.<locals>.myint3c                     d| _         y )Nbar)foo)r<   r   s     r!   r  z1LongTest.test_from_bytes.<locals>.myint3.__init__  s	     r"   N)r   r   r   r  r   r"   r!   myint3r4    s    !r"   r8  r7  noner6  c                       e Zd Zd Zy),LongTest.test_from_bytes.<locals>.ValidBytesc                      y)Nr  r   r   s    r!   	__bytes__z6LongTest.test_from_bytes.<locals>.ValidBytes.__bytes__  s    r"   Nr   r   r   r=  r   r"   r!   
ValidBytesr;    s    r"   r?  c                       e Zd Zd Zy).LongTest.test_from_bytes.<locals>.InvalidBytesc                      y)Nabcr   r   s    r!   r=  z8LongTest.test_from_bytes.<locals>.InvalidBytes.__bytes__  s    r"   Nr>  r   r"   r!   InvalidBytesrA    s    r"   rD  c                       e Zd Zy).LongTest.test_from_bytes.<locals>.MissingBytesNr  r   r"   r!   MissingBytesrF    s    r"   rG  c                       e Zd Zd Zy).LongTest.test_from_bytes.<locals>.RaisingBytesc                     ddz   y )Nr   r   r   r   s    r!   r=  z8LongTest.test_from_bytes.<locals>.RaisingBytes.__bytes__  s	    Ar"   Nr>  r   r"   r!   RaisingBytesrI    s    r"   rK  c                       e Zd Zy)(LongTest.test_from_bytes.<locals>.SubStrNr  r   r"   r!   r  rM    r  r"   r  r  )r8   r  r  r&  rN   	bytearrayarray
memoryviewr   r   r   getattrr%   r   )r<   r  r  r  r  r  r)  r2  rH   r8  r?  rD  rG  rK  r  s   `              r!   test_from_byteszLongTest.test_from_bytes?  s   +	C\

Q
 
 Q	

 
 R
 
 T
 T
 
 S
 
 
 
 
  !
" #
$  "#%+
. 	feD)

Q
 
 Q	

 
 R
 
 T
 T
 
 S
 
 
 
 
  !
" #
$  "#%+
. 	fht, "
 	feE* "
 	fhu-	C 	 	d5++GU;<eD))'591=!!'5!?@%	I))'5)GKd5++GX>?G))'8<a@d5++Xe , - ./4	6))'8E)JANNN;dN;V	ENN;dN;V	Eo&d ( <=C	Eo&d ( <=C	EKK_-uT ( CDJ	L't ( =>D	F*cnnseUC*cnnqc9E*cnnqc<H)S^^R?)S^^VUC)S^^Q>)S^^QtD)U%5%5r5A)U%5%5vuE)U%5%5q%@)S^^QtD	3S 	3 gu-d1gv&A	!S 	! gu-d1gv&AE62E:	 		 	 	 	 	 	
5q9)S^^\^D)S^^\^D+S^^\^L	S 	VE];Q?1ABAFr"   c                     t        dd      D ]<  }|j                  dd      }| j                  t        j	                  |d      |       > y )Nrp  r  r   Tr  )rE   r  r  r8   r&  )r<   rH   r+   s      r!   test_from_bytes_smallzLongTest.test_from_bytes_small  sF     r3 	=A

1T
*AMM#..4.8!<	=r"   c                     | j                  dj                                | j                  dj                                | j                  dj                                y )Nr
   r   r   )r;   
is_integerr   s    r!   test_is_integerzLongTest.test_is_integer  s;    )*()()r"   c                      G d dt               }t        d      D cg c]
  } |d       }}t        t         |      D ]  }| j                  |d        y c c}w )Nc                       e Zd ZddZy)<LongTest.test_access_to_nonexistent_digit_0.<locals>.Integerc                 @    t         j                  | |      }d|_        |S )Nr7  )r8   r/  r7  )r0  r   r<   s      r!   r/  zDLongTest.test_access_to_nonexistent_digit_0.<locals>.Integer.__new__  s    {{3. r"   N)r   r1  r   r"   r!   IntegerrZ    s    r"   r\  r  r   )r8   rE   maprN   )r<   r\  rH   integersr   s        r!   "test_access_to_nonexistent_digit_0z+LongTest.test_access_to_nonexistent_digit_0  sV    	c 	 ).d41GAJ44S(# 	#AQ"	# 5s   Ac                     dD ]M  }dD ]F  }| j                  t        ||z        t               | j                  t        ||z	        t               H O y )N)TF)r   r   )rN   r  r8   )r<   r   r   s      r!   test_shift_boolzLongTest.test_shift_bool'  sR    " 	<E <  eun!5s;  eun!5s;<	<r"   c           
      R    G d dt               }ddddt        j                  dz   dd |d	      g}|D ]r  }|j                         \  }}| j	                  ||ft        |      df       | j	                  t        |      t                | j	                  t        |      t                t y )
Nc                       e Zd Zy)-LongTest.test_as_integer_ratio.<locals>.myintNr  r   r"   r!   r)  rd  /  r  r"   r)  rc   r   rs  r   TFr   )r8   r   r-  as_integer_ratiorN   r  )r<   r)  r  r   	numeratordenominators         r!   test_as_integer_ratiozLongTest.test_as_integer_ratio.  s    	C 	QQaueBiH 	5E%*%;%;%="I{i5E
AGT)_c2T+.4		5r"   c           	          t        dd      D ]M  }d|z  dz
  }| j                  ||      5  | j                  |dz  dd|z  z  d|dz   z  z
  dz          d d d        O y # 1 sw Y   ZxY w)Nr   i  )bitlenr   r   )rE   rO   rN   )r<   rj  r   s      r!   test_squarezLongTest.test_square8  s    
 Asm 	CFf!AVq1 C  A1v:&1!+<=ACC C	CC Cs   (AA'	c           
      N   | j                  t        j                  t        j                  j
                         dddt        dz
  dfdt        z
  dft        dft         dft        t        z  dz
  dft        t        z  dfg	}|D ]a  \  }}| j                  |      5  | j                  |j                         t        j                  t        j                  |z  z          d d d        c  G d dt              }| j                  |j                  t        j                  j
                         |D ]_  \  }}| j                  |      5  | j                   ||      j                         |j                  |j                  |z  z          d d d        a y # 1 sw Y   xY w# 1 sw Y   yxY w)	N)r   r   )r   r   )r
   r   r   r   rX   c                       e Zd Zy)'LongTest.test___sizeof__.<locals>.MyIntNr  r   r"   r!   MyIntrn  ^  r  r"   ro  )
rN   r8   __itemsize__r   int_infosizeof_digitr  rO   
__sizeof____basicsize__)r<   r   r   r=   ro  s        r!   test___sizeof__zLongTest.test___sizeof__D  s   ))3<<+D+DE !VQKtVQK1IUAJ$Y]A$YN
 * 	NE7e$   $$&%%(8(87(BB 		C 	 	++S\\-F-FG) 	NE7e$   %L++-''%*<*<w*FF 	  s   AFAFF	F$	N)T)?r   r   r   rC   rI   rU   r`   ri   rm   rp   rs   rv   r   r   r   r   r   r   r   requires_IEEE_754r   r  r  r3  rX  r\  ra  re  rg  rk  r~  r  r  cpython_onlyr  
bigmemtestr   r-  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rR  rT  rW  r_  ra  rh  rk  ru  r   r"   r!   r3   r3   s   s4   0C#>N+.+6+/
S>1'6Mr5"0" C0 C0J8>;$Z*x_DB9
& HD%&L< Y' Y'v 4 4 Wd*8UKN L N4 Wc)$F: G :
: 
A0001     % %   0 $ 7D	CH6TCAJLG\ = =*
#<5
C$r"   r3   __main__)#unittestr  r   r   r9   r   rO  rq  bits_per_digitr7   r  rG   r[   rZ   ru   rl   rE   rH   r\   r   r   r   r   r   min_expr'   r   r(   r&   r   r1   TestCaser3   r   mainrk   s   0r!   <module>r     sc     
    	##Ezax  	 aD$!)%79K
L	qw ANN26	qB   1QB #81QB#88 8
..

nn$$nn$$~~&&k>Al(BQ(F$GG *'\+<ux   up/ zHMMO ]2 !#8s   <
D9
D>