
    6bhY                        d dl mZmZmZ d dlmZ d dlmZmZ d dlm	Z	 d dl
Z
d dlZd dlZd dlmZmZmZmZ d dlZd dlZ ed      Z ed      ZdD  cg c]  } dD ]  } e| |        c}} Zed	fed
feefd
efd	efdefdefe efe d
fe d	fe dfe dfe e fde fde fd	e fd
e fee fedfedffD  cg c]  \  } } e| |       c}} Zee fedfedfed	fed
feefe efdefdefd	efd
efeeffD  cg c]  \  } } e| |       c}} Z G d dee
j4                        Z G d de	j8                        Zedk(  r e
j<                          yyc c}} w c c}} w c c}} w )    )requires_IEEE_754cpython_onlyimport_helper)ComplexesAreIdenticalMixin)parse_testfile	test_fileN)phasepolarrectpiinfnan)               r   ffffff@r   ffffffc            
       x   e Zd ZdD  cg c]  }t        t        |       c}}}} Zej                  d        ej                  d        d Zd Z	 	 ddZ	d Z
d	 Zd
 Zd Zd Zed        Zd Zd Zed        Zd Zd Zed        Zd Zd Zd Zd Zd Zed        Zed        Zed        Zyc c}}}} w )
CMathTests)acosacoshasinasinhatanatanhcoscoshexploglog10sinsinhsqrttantanhc                 .    t        j                  | d      S )Ny     @        cmathr   xs    9/opt/python-3.12.12/usr/lib/python3.12/test/test_cmath.py<lambda>zCMathTests.<lambda><   s    UYYq*%=    c                 .    t        j                  d|       S )Ny      ,@      ;r&   r(   s    r*   r+   zCMathTests.<lambda>=   s    UYYw%:r,   c                 0    t        t        d      | _        y )Nzutf-8)encoding)openr   test_valuesselfs    r*   setUpzCMathTests.setUp?   s    	G<r,   c                 8    | j                   j                          y N)r1   closer2   s    r*   tearDownzCMathTests.tearDownB   s     r,   Nc                    t        j                  |      r:t        j                  |      ry| j                  |xs dj                  |             t        j                  |      r+||k(  ry| j                  |xs dj                  ||             |sT|sRt        j
                  d|      t        j
                  d|      k7  r%| j                  |xs dj                  ||             	 t        ||z
        }|t        ||t        |      z        k  ry| j                  |xs dj                  ||             y# t        $ r Y 1w xY w)a  Fail if the two floating-point numbers are not almost equal.

        Determine whether floating-point values a and b are equal to within
        a (small) rounding error.  The default values for rel_err and
        abs_err are chosen to be suitable for platforms where a float is
        represented by an IEEE 754 double.  They allow an error of between
        9 and 19 ulps.
        Nz{!r} should be nanz>finite result where infinity expected: expected {!r}, got {!r}      ?z,zero has wrong sign: expected {!r}, got {!r}z({!r} and {!r} are not sufficiently close)	mathisnanfailformatisinfcopysignabsmaxOverflowError)r3   abrel_errabs_errmsgabsolute_errors          r*   rAssertAlmostEqualzCMathTests.rAssertAlmostEqualE   s"    ::a=zz!}IIc;188;<::a=AvIIc = 006q!> }}R#t}}R';;		# 2 "%%+VAq\3
	 1XN WgA.>!??		# J<CCAqI	K  		s   'D7 7	EEc           	         d}d}| j                  t        j                  |ddj                  t        j                  |             | j                  t        j                  |ddj                  t        j                  |             y )NgiW
@g-DT!	@	   zcmath.pi is {}; should be {})placesrH   zcmath.e is {}; should be {})assertAlmostEqualr'   r   r>   e)r3   
e_expectedpi_expecteds      r*   test_constantszCMathTests.test_constantsw   sp    +
,uxxQ.55ehhL 	 	Nuww
1-44UWWjI 	 	Kr,   c                 \   | j                  t        j                  j                  t        j                         | j                  t        j                  j
                  d       | j                  t        j                  j                  d       | j                  t        j                  j
                  t        j                         | j                  t	        j                  t        j                  j                               | j                  t        j                  j
                  d       | j                  t        j                  j                  d       | j                  t	        j                  t        j                  j
                               | j                  t	        j                  dt        j                  j                        d       | j                  t	        j                  dt        j                  j
                        d       | j                  t	        j                  dt        j                  j                        d       | j                  t	        j                  dt        j                  j
                        d       | j                  t        t        j                        d       | j                  t        t        j                        d       | j                  t        t        j                        d       | j                  t        t        j                        d       y )Nr   r:   r   infjr   nanj)assertEqualr'   r   realr;   imagrT   
assertTruer<   r   rU   r@   reprr2   s    r*   test_infinity_and_nan_constantsz*CMathTests.test_infinity_and_nan_constants   s   2-#.$((3

599>>23-#.

5::??34r599>>:B?r599>>:B?r5::??;R@r5::??;R@ 	eii%0ejj)62eii%0ejj)62r,   c           
      B   ddddddd t               t        g} G d d      } G d	 d
t               G fdd      } G d dt               } G d d      } G d d      } G fdd      } G fdd      }| j                  D ]  }	| j	                   |	 |             |	             | j	                   |	 |              |	             | j	                   |	 |              |	             | j	                   |	 |              |	t         |                          | j                  t        |	 |              | j                  t        |	 |              |D ]  }
| j                  t        |	 ||
             ! | j                  |	 |               y )Nyz@7Ă??g]ֆznot complex             @c                       e Zd Zd Zd Zy).CMathTests.test_user_object.<locals>.MyComplexc                     || _         y r6   value)r3   rd   s     r*   __init__z7CMathTests.test_user_object.<locals>.MyComplex.__init__   s	    "
r,   c                     | j                   S r6   rc   r2   s    r*   __complex__z:CMathTests.test_user_object.<locals>.MyComplex.__complex__   s    zz!r,   N)__name__
__module____qualname__re   rg    r,   r*   	MyComplexra      s    #"r,   rl   c                       e Zd Zy)2CMathTests.test_user_object.<locals>.SomeExceptionNrh   ri   rj   rk   r,   r*   SomeExceptionrn          r,   rp   c                       e Zd Z fdZy)7CMathTests.test_user_object.<locals>.MyComplexExceptionc                     r6   rk   )r3   rp   s    r*   rg   zCCMathTests.test_user_object.<locals>.MyComplexException.__complex__   s	    ##r,   N)rh   ri   rj   rg   )rp   s   r*   MyComplexExceptionrs      s    $r,   ru   c                       e Zd Zy);CMathTests.test_user_object.<locals>.NeitherComplexNorFloatNro   rk   r,   r*   NeitherComplexNorFloatrw      rq   r,   rx   c                       e Zd Zd Zd Zy)*CMathTests.test_user_object.<locals>.Indexc                      yN   rk   r2   s    r*   __int__z2CMathTests.test_user_object.<locals>.Index.__int__       ar,   c                      yr|   rk   r2   s    r*   	__index__z4CMathTests.test_user_object.<locals>.Index.__index__   s    r,   N)rh   ri   rj   r~   r   rk   r,   r*   Indexrz      s    ')r,   r   c                       e Zd Zd Zy)*CMathTests.test_user_object.<locals>.MyIntc                      yr|   rk   r2   s    r*   r~   z2CMathTests.test_user_object.<locals>.MyInt.__int__   r   r,   N)rh   ri   rj   r~   rk   r,   r*   MyIntr      s    'r,   r   c                   "    e Zd ZfdZ fdZy)4CMathTests.test_user_object.<locals>.FloatAndComplexc                     S r6   rk   r3   flt_args    r*   	__float__z>CMathTests.test_user_object.<locals>.FloatAndComplex.__float__       r,   c                     S r6   rk   )r3   cx_args    r*   rg   z@CMathTests.test_user_object.<locals>.FloatAndComplex.__complex__   s    r,   N)rh   ri   rj   r   rg   )r   r   s   r*   FloatAndComplexr      s    r,   r   c                       e Zd Z fdZy).CMathTests.test_user_object.<locals>.JustFloatc                     S r6   rk   r   s    r*   r   z8CMathTests.test_user_object.<locals>.JustFloat.__float__   r   r,   N)rh   ri   rj   r   )r   s   r*   	JustFloatr      s    r,   r   )objectNotImplemented	Exceptiontest_functionsrV   intassertRaises	TypeError)r3   non_complexesrl   ru   rx   r   r   r   r   fbad_complexrp   r   r   s              @@@r*   test_user_objectzCMathTests.test_user_object   si    , '1b$>3	" 	"	I 		$ 	$
	V 		* 	*	( 	(
	 	
	 	 $$AQy011V9=Q011V9=Qy{^QwZ8QuwZ3uw<9 i,B,DEiEG4,!!)Q	+0FG  - mQ0B0DE! %r,   c           	          | j                   D ]5  }dD ].  }| j                   ||       ||j                                      0 7 | j                   D ]   }dD ]  }| j                  t        ||        " y )N)r}   r_   )rD   long_string01j )r   rV   r   r   r   )r3   r   args      r*   test_input_typezCMathTests.test_input_type   sk     $$A  33==?);<  %
 $$A:!!)Q4 ; %r,   c                    g d}||D cg c]  }|  c}z   g dz   }|dgz   |D cg c]  }d|z  	 c}z   }dg|z   }dg|z   |D cg c]  }|  c}z   }|||||||||||||d}|j                         D ]r  \  }}	t        t        |      }
t        t        |      }|	D ]H  } ||      }| j	                   |
|      |j
                         | j                  d|j                         J t dD ]k  }|D ]d  }t        j                  ||      }| j	                  t        j                  ||      |j
                         | j                  d|j                         f m y c c}w c c}w c c}w )N)g{Gz?g?g?      ?g?gGz?)r   r:         r:   r   )r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   )r   r_   g      $@)	itemsgetattrr;   r'   rJ   rW   rV   rX   r   )r3   r1   r)   unit_intervalpositivenonnegative	real_liner   fnvaluesfloat_fn
complex_fnvzbases                  r*   test_cmath_matches_mathz"CMathTests.test_cmath_matches_math   s   
 7 $;&?;ar;&?? "%{(C{!A{(CCdXo D8O8&<8ar8&<<	 #"   )..0JBtR(H +JqM''QVV<  QVV,  1 #DIIa&''D(9166B  QVV,  #E '@ )D '=s   
EE!
E&c                 H   dh}d }t         j                  dk(  r@t        j                         d   }	 t        t	        t
        |j                  d                  }d }d }t        t              D ]  \  }}}}	}
}}t        ||	      }t        |
|      }|
|dk  r||v r0|dk(  r|}n|d	k(  r|}nt        t        |      }d
|v sd|v r,	  ||      }| j                  dj                  ||||	             d|v r,	  ||      }| j                  dj                  ||||	              ||      }d|v rRt        t!        |j"                        |j$                        }t        t!        |j"                        |j$                        }d|v rRt        |j"                  t!        |j$                              }t        |j"                  t!        |j$                              }|dv rd}nd}dj                  ||||	|j"                  |j$                  |j"                  |j$                        }| j'                  |j"                  |j"                  ||       | j'                  |j$                  |j$                  |        y # t        $ r Y 'w xY w# t        $ r Y "w xY w# t        $ r Y 2w xY w)Ntan0064darwinr   .c                 V    t        j                  | j                  | j                        S )zaWrapped version of rect that accepts a complex number instead of
            two float arguments.)r'   r   rW   rX   r   s    r*   rect_complexz5CMathTests.test_specific_values.<locals>.rect_complex%  s     ::affaff--r,   c                 $    t        t        |        S )zYWrapped version of polar that returns a complex number instead of
            two floats.)complexr
   r   s    r*   polar_complexz6CMathTests.test_specific_values.<locals>.polar_complex*  s     E!H%%r,   )
   r^   r   r
   zdivide-by-zeroinvalidz9ValueError not raised in test {}: {}(complex({!r}, {!r}))overflowz<OverflowError not raised in test {}: {}(complex({!r}, {!r}))zignore-real-signzignore-imag-sign)r   r   V瞯<
       z{}: {}(complex({!r}, {!r}))
Expected: complex({!r}, {!r})
Received: complex({!r}, {!r})
Received value insufficiently close to expected value.)rG   rH   )rH   )sysplatformmac_vertuplemapr   split
ValueErrorr   r   r   r   r'   r=   r>   rC   rA   rW   rX   rJ   )r3   SKIP_ON_TIGERosx_versionversion_txtr   r   idr   araiereiflagsr   expectedfunctionactualreal_abs_errerror_messages                      r*   test_specific_valueszCMathTests.test_specific_values  s    #<<8#"**,Q/K#C[->->s-C$DE	.
	&
 .<I-F)BBBE"b/Cr2H &;+@&V|'w("5"-5(I,>P%c]F II 88>r2r28NP U"P%c]F II 88>r2r28NP c]F!U* V[[!16;;?"3x}}#5x}}E!U* c&++.>?"8==#hmm2DE %%$%I &RR]]HMM[[&++/  ##HMM6;;0<,9 $ ; ##HMM6;;,9 $ ;y .G  > "  % s5   (I4 J7J4	J J	JJ	J! J!c                      fd} |dd        |dd        |ddt         f        |ddt         d	z  f        |d
dt          d	z  f       t        d      } |t        |d      |df        |t        | d      |t         f        |t        d|      |t         d	z  f        |t        d|       |t          d	z  f        |t        ||      |t         dz  f        |t        ||       |t          dz  f        |t        | |      |dt         z  dz  f        |t        | |       |dt         z  dz  f       t        d      } |t        |d      ||f        |t        d|      ||f        |t        ||      ||f        |t        ||      ||f        |t        | |      ||f        |t        ||      ||f        |t        ||       ||f       y )Nc                 b     |       }t        ||      D ]  \  }}j                  ||        y r6   )ziprJ   )r   r   gotrO   gfuncr3   s        r*   checkz%CMathTests.check_polar.<locals>.checko  s1    s)CHc*1''1- +r,   r   )r   r   r]   )r:   r   r:                 ?r}   y             g      @r   r      r^      r   )r   floatr   )r3   r   r   r   r   s   ``   r*   check_polarzCMathTests.check_polarn  s   	. 	aab2r(b2rAv,cBa=!Elgc1oRy)gsdAb	*gaoR!V}-ga#rcAg/gc3#rAv/gcC4 3a.1gsdC 3B
"34gsdSD!Cb1#56Elgc1oSz*gaoSz*gc3#s,gc3#s,gsdC 3*-gc3#s,gcC4 3*-r,   c                 .    | j                  t               y r6   )r   r
   r2   s    r*   
test_polarzCMathTests.test_polar  s    r,   c                 \    t        j                  d      fd}| j                  |       y )N	_testcapic                     j                  d       	 t        |       j                  d       S # j                  d       w xY w)N   r   )	set_errnor
   )r   r   s    r*   polar_with_errno_setz9CMathTests.test_polar_errno.<locals>.polar_with_errno_set  s:    #'Qx##A&	##A&s	   
0 A)r   import_moduler   )r3   r   r   s     @r*   test_polar_errnozCMathTests.test_polar_errno  s+     "//<		' 	-.r,   c                 
   | j                  t        d      d       | j                  t        d      d       | j                  t        d      t               | j                  t        d      t               | j                  t        d      t                | j                  t        d      t        dz         | j                  t        d	      t         dz         | j                  t        t	        dd            d       | j                  t        t	        dd
            d
       | j                  t        t	        d
d            t               | j                  t        t	        d
d
            t                | j                  t        t	        t
         d
            t                | j                  t        t	        t
         d            t                | j                  t        t	        t
         t
                     dt        z         | j                  t        t	        dt
                     t         dz         | j                  t        t	        d
t
                     t         dz         | j                  t        t	        dt
                     t         dz         | j                  t        t	        dt
                     t         dz         | j                  t        t	        t
        t
                     t         dz         | j                  t        t	        t
        d            d
       | j                  t        t	        t
        d
            d
       | j                  t        t	        t
        d            d       | j                  t        t	        t
        d            d       | j                  t        t	        t
        t
                    t        dz         | j                  t        t	        dt
                    t        dz         | j                  t        t	        dt
                    t        dz         | j                  t        t	        d
t
                    t        dz         | j                  t        t	        dt
                    t        dz         | j                  t        t	        t
         t
                    dt        z         | j                  t        t	        t
         d            t               | j                  t        t	        t
         d            t               t        D ]/  }| j                  t        j                  t        |                   1 y )Nr   r   r:   r   y      Yny      Ynr   r}   y             r   r   g      r   r   g      ?)
rN   r	   r   rV   r   INFcomplex_nansrY   r;   r<   r3   r   s     r*   
test_phasezCMathTests.test_phase  s   uQx,uRy"-uSz2.u[126u[1B37uRy"Q$/uSzB3q51 	wsC0137wsD12D9wtS12B7wtT23bS9 	uWcT4%89B3?uWcT4%89B3?uWcTC4%8958DuWTC4%89B3q5AuWTC4%89B3q5AuWS3$%782#a%@uWS3$%782#a%@uWS3$%782#a%@wsD12D9wsD12D9wsC0137wsC0137uWS#%67A>uWS#%67A>uWS#%67A>uWT3%78"Q$?uWT3%78"Q$?uWcT3%78$r'BuWcT3%78"=uWcT3%78"= AOODJJuQx01 r,   c           
      ^   t         D ]  }| j                  t        |      d        t        D ]!  }| j                  t        |      t               # | j                  t        t        t        t                     t               | j                  t        j                  t        t        t        d                         | j                  t        j                  t        t        t        d                         | j                  t        j                  t        t        t        d                         | j                  t        j                  t        t        t        d                         | j                  t        t        t        t                    t               | j                  t        t        t         t                    t               | j                  t        j                  t        t        dt                                 | j                  t        j                  t        t        dt                                 | j                  t        j                  t        t        dt                                 | j                  t        j                  t        t        dt                                 | j                  t        t        t        t                    t               | j                  t        j                  t        t        t        t                                 y )Nr   r   r   r   )
complex_zerosrV   rA   complex_infinitiesr   r   NANrY   r;   r<   r   s     r*   test_abszCMathTests.test_abs  s   ASVS)  $ASVS) $ 	WS3$/0#6

3wsD'9#:;<

3wsD'9#:;<

3wsC'8#9:;

3wsC'8#9:;WS#./5WcT3/0#6

3wtS'9#:;<

3wtS'9#:;<

3wsC'8#9:;

3wsC'8#9:;WS#./5

3wsC'8#9:;r,   c                 N    | j                  t        t        t        dd             y )NgU)r   rC   rA   r   r2   s    r*   test_abs_overflowszCMathTests.test_abs_overflows  s     	-ggw.GHr,   c                     d}t        |j                  |d   z
        |kD  st        |j                  |d   z
        |kD  r| j                  ||f       y y )NgHz>r   r]   )rA   rW   rX   r=   )r3   rD   rE   epss       r*   assertCEqualzCMathTests.assertCEqual  sN    qvv!}#s166AaD='9C'?IIq!f (@r,   c                 D   | j                  t        dd      d       | j                  t        dd      d       | j                  t        dt               d       | j                  t        dt        dz        d       | j                  t        dt         dz        d       y )	Nr   )r   r   r]   )r:   r   )r   r   r}   )r   r:   )r   r   )r  r   r   r2   s    r*   	test_rectzCMathTests.test_rect  s|    $q!*f-$q!*g.$q2#,1$q"Q$-1$q2#a%.(3r,   c           	         t        d      ddddt        d      t        d      g}|D ]d  }|D ]]  }t        ||      }| j                  t        j                  |      t        j                  |      xr t        j                  |             _ f y )Nz-infr   r   r   r   r   r   )r   r   rV   r'   isfiniter;   )r3   	real_valsr)   yr   s        r*   test_isfinitezCMathTests.test_isfinite  sx    6]D$#uU|U5\;	AAqM  !2"&--"2"Gt}}Q7GI  r,   c                 @   | j                  t        j                  d             | j                  t        j                  d             | j                  t        j                  t                     | j	                  t        j                  t
                     | j	                  t        j                  t        t
        d                   | j	                  t        j                  t        dt
                           | j	                  t        j                  t        t
        t
                           | j	                  t        j                  t        t
        t                           | j	                  t        j                  t        t        t
                           y Nr]   r   r   )assertFalser'   r<   r   rY   r   r   r2   s    r*   
test_isnanzCMathTests.test_isnan      Q(R)S)*C()GCO45GAsO45GC$567GC$567GC$567r,   c                 @   | j                  t        j                  d             | j                  t        j                  d             | j                  t        j                  t                     | j	                  t        j                  t
                     | j	                  t        j                  t        t
        d                   | j	                  t        j                  t        dt
                           | j	                  t        j                  t        t
        t
                           | j	                  t        j                  t        t        t
                           | j	                  t        j                  t        t
        t                           y r  )r  r'   r?   r   rY   r   r   r2   s    r*   
test_isinfzCMathTests.test_isinf   r  r,   c                 d    t         D ]'  }| j                  t        j                  |      |       ) y r6   )r   assertComplexesAreIdenticalr'   r$   r   s     r*   testTanhSignzCMathTests.testTanhSign  $    A,,UZZ]A> r,   c                 d    t         D ]'  }| j                  t        j                  |      |       ) y r6   )r   r  r'   r   r   s     r*   testAtanSignzCMathTests.testAtanSign  r  r,   c                 d    t         D ]'  }| j                  t        j                  |      |       ) y r6   )r   r  r'   r   r   s     r*   testAtanhSignzCMathTests.testAtanhSign  s$    A,,U[[^Q? r,   )r   r   N) rh   ri   rj   r   r'   r   appendr4   r8   rJ   rR   r[   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r
  r  r  r  r  r  ).0fnamer   r'   s   0000r*   r   r   5   s6   :# $ :#geU+ :# $N
 =>:;=! CI#0KdK3,DFL
5.-` T; T;l.8  	/ 	/'2R<2 I I
4I	8	8 ? ? ? ? @ @G$s   B4
r   c                   <    e Zd Zej                  Zd Zd Zd Zd Zy)IsCloseTestsc                 z   | j                  t              5  | j                  ddd       d d d        | j                  t              5  | j                  ddd       d d d        | j                  t              5  | j                  dddd       d d d        y # 1 sw Y   oxY w# 1 sw Y   IxY w# 1 sw Y   y xY w)Nr   rel_tolabs_tol)r!  r#  )r   r   iscloser2   s    r*   test_reject_complex_tolerancesz+IsCloseTests.test_reject_complex_tolerances"  s    y)LLRL, * y)LLRL, * y)LLRRL8 *) *) *) *)s#   BB%:B1B"%B.1B:c                 X    g d}| j                  |d       | j                  |d       y )N))      ?      ?y    ?      ?)r'  y      ?    ?)y            ?y          ?)y      ?      y      ?g-q=r   gvIh%<=)assertAllCloseassertAllNotClose)r3   complex_exampless     r*   test_complex_valuesz IsCloseTests.test_complex_values,  s4     	,e</?r,   c                     g d}| j                  |d       | j                  |d       | j                  ddd       | j                  ddd       y )	N))y        MbP?r   )MbP?r   )MbP?MbP?r   )yMbPMbP?r   )MbP?MbPr   )yMbPMbPr   g~jtX?r"  gMb@?r/  r.  gMb`?r-  )r(  r)  assertIsCloseassertIsNotClose)r3   near_zero_exampless     r*   test_complex_near_zeroz#IsCloseTests.test_complex_near_zero7  s^      	.@17C<uElL%Hr,   c                 B   | j                  t        t        dz         | j                  t        dz  t               | j                  t        t                | j                  t         t               | j                  dt               | j                  dt        dz         y )Nr   r   )r1  r   r2   s    r*   test_complex_specialz!IsCloseTests.test_complex_specialG  sr    c3r6*c"fc*cC4(sdC(a%aR(r,   N)	rh   ri   rj   r'   r$  r%  r+  r3  r5  rk   r,   r*   r  r    s!    mmG9	@I )r,   r  __main__)test.supportr   r   r   test.support.testcaser   test.test_mathr   r   	test_mathunittestr'   r;   r	   r
   r   r   r   r   r   r   r   r   r   r   r   TestCaser   r  rh   main)r)   r	  s   00r*   <module>r>     s   G G < 4 "   ( (  
 ElEl(3I1[A[I	c
	c
	c
	c
	c
	s	s
s
s
s
t
t
t	t	t	sd	sd	sd	d	d)1
  1
1gam 1
  . 
sd	d	d	c
	c
	c

s	s	s	c
	c
	c
+
  +
$!Q1 +
 g@+X->-> g@T.)9)) .)b zHMMO C J,s   E<E>E$