Your IP : 216.73.216.213


Current Path : /opt/alt/python39/lib64/python3.9/test/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/__pycache__/test_math.cpython-39.opt-1.pyc

a

XC?h�]�@s�ddlmZmZmZddlmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZdZed�Zed�Zed�ZejjZejjZd\ZZeed	kZed
kr�ejdZneZe
j �!e�p�e
j"Z#e
j �$e#d�Z%e
j �$e#d�Z&d
d�Z'dd�Z(dd�Z)dd�Z*dd�Z+dd�Z,dd�Z-d+dd�Z.Gdd �d �Z/Gd!d"�d"e0�Z1Gd#d$�d$e2�Z3Gd%d&�d&ej4�Z5Gd'd(�d(ej4�Z6d)d*�Z7ed
k�r�e7�dS),�)�run_unittest�verbose�requires_IEEE_754)�supportNg�h㈵��>�nan�inf�-inf)���7y�ACg�):��@g��7y�AC�__main__zmath_testcases.txtzcmath_testcases.txtcCs.t�dt�d|��d}|dkr*|d}|S)a�Convert a non-NaN float x to an integer, in such a way that
    adjacent floats are converted to adjacent integers.  Then
    abs(ulps(x) - ulps(y)) gives the difference in ulps between two
    floats.

    The results from this function will only make sense on platforms
    where native doubles are represented in IEEE 754 binary64 format.

    Note: 0.0 and -0.0 are converted to 0 and -1, respectively.
    z<qz<drl)�structZunpackZpack)�x�n�r�3/opt/alt/python39/lib64/python3.9/test/test_math.py�to_ulps's
rcCs|rdt||d@�SdS)zANumber of '1' bits in binary expansion of a nonnnegative integer.�r)�count_set_bits)r
rrrrMsrcCsD||d?}|sdS|dkr |S||dB}t||�t||�SdS)z�Product of integers in range(start, stop, 2), computed recursively.
    start and stop should both be odd, with start <= stop.

    rN)�partial_product)�start�stopZ
numfactorsZmidrrrrQsrcCs`d}}tt|����D]6}|t||d?ddB||?ddB�9}||9}q||t|�>S)z�Factorial of nonnegative integer n, via "Binary Split Factorial Formula"
    described at http://www.luschny.de/math/factorial/binarysplitfact.html

    r)�reversed�range�
bit_lengthrr)r
�innerZouter�irrr�py_factorial_s
*
rcCsLtt|�t|��}t||�}||ks0||kr4dSd}|�||||�SdS)z�Given finite floats `expected` and `got`, check that they're
    approximately equal to within the given number of ulps or the
    given absolute tolerance, whichever is bigger.

    Returns None on success and an error message on failure.
    NzAerror = {:.3g} ({:d} ulps); permitted error = {:.3g} or {:d} ulps)�absr�format)�expected�got�ulp_tol�abs_tolZ	ulp_errorZ	abs_errorZfmtrrr�
ulp_abs_checkjsr"ccs�t|���}|D]x}d|vr,|d|�d��}|��s6q|�d�\}}|��\}}}|��}|d}	|dd�}
||t|�t|	�|
fVqWd�n1s�0YdS)z�Parse a file with test values

    -- starts a comment
    blank lines, or lines containing only a comment, are ignored
    other lines are expected to have the form
      id fn arg -> expected [flag]*

    �--N�->rr)�open�index�strip�split�float)�fname�fp�line�lhs�rhs�id�fn�arg�
rhs_pieces�exp�flagsrrr�parse_mtestfile|s	
r5c
	cs�t|���}|D]�}|�d�s|��s&q|�d�\}}|��\}}}}|��}	|	d|	d}
}|	dd�}||t|�t|�t|
�t|�|fVqWd�n1s�0YdS)z�Parse a file with test values

    Empty lines or lines starting with -- are ignored
    yields id, fn, arg_real, arg_imag, exp_real, exp_imag
    r#r$rr�N)r%�
startswithr'r(r))
r*r+r,r-r.r/r0Zarg_realZarg_imagr2Zexp_realZexp_imagr4rrr�parse_testfile�s
�r8��cCs�||krdSd}t|t�r.t|t�r.t|�}nt|t�rJt|t�rJt|�}t|t�r�t|t�r�t�|�rxt�|�rxd}n$t�|�s�t�|�r�nt||||�}|dur�d}|�||�}|d�|�7}|SdSdS)a�Compare arguments expected and got, as floats, if either
    is a float, using a tolerance expressed in multiples of
    ulp(expected) or absolutely (if given and greater).

    As a convenience, when neither argument is a float, and for
    non-finite floats, exact equality is demanded. Also, nan==nan
    as far as this function is concerned.

    Returns None on success and an error message on failure.
    Nz	not equalzexpected {!r}, got {!r}z ({}))�
isinstancer)�int�math�isnan�isinfr"r)rrr r!�failure�fail_fmtZfail_msgrrr�result_check�s&
rBc@seZdZdd�Zdd�ZdS)�	FloatLikecCs
||_dS�N��value��selfrFrrr�__init__�szFloatLike.__init__cCs|jSrDrE�rHrrr�	__float__�szFloatLike.__float__N)�__name__�
__module__�__qualname__rIrKrrrrrC�srCc@seZdZdS)�IntSubclassN�rLrMrNrrrrrO�srOc@seZdZdd�Zdd�ZdS)�MyIndexablecCs
||_dSrDrErGrrrrI�szMyIndexable.__init__cCs|jSrDrErJrrr�	__index__�szMyIndexable.__index__N�rLrMrNrIrRrrrrrQ�srQc@sneZdZd�dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Ze
dd��Zdd�Ze�ejdko�e��dvd�dd��Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zejd*d+��Zd,d-�Zd.d/�Zd0d1�Z e
e�e!d2�d3d4���Z"d5d6�Z#d7d8�Z$d9d:�Z%d;d<�Z&d=d>�Z'd?d@�Z(dAdB�Z)dCdD�Z*e
dEdF��Z+e
e�,dGd�dHdI���Z-dJdK�Z.dLdM�Z/dNdO�Z0dPdQ�Z1e
dRdS��Z2dTdU�Z3dVdW�Z4dXdY�Z5dZd[�Z6d\d]�Z7e
d^d_��Z8d`da�Z9dbdc�Z:ddde�Z;dfdg�Z<e
dhdi��Z=e
djdk��Z>e�?e@dl�dmdn��ZAe
dodp��ZBe
dqdr��ZCdsdt�ZDdudv�ZEdwdx�ZFe
dydz��ZGe
d{d|��ZHd}d~�ZIdd��ZJd�d��ZKd�S)��	MathTestsr9r:cCs,t||||�}|dur(|�d�||��dS)aaCompare arguments expected and got, as floats, if either
        is a float, using a tolerance expressed in multiples of
        ulp(expected) or absolutely, whichever is greater.

        As a convenience, when neither argument is a float, and for
        non-finite floats, exact equality is demanded. Also, nan==nan
        in this function.
        Nz{}: {})rB�failr)rH�namerrr r!r@rrr�ftest�s	zMathTests.ftestcCs8|�dtjd�|�dtjd�|�tjdtj�dS)N�pig-DT�!	@�egiW�
�@r6)rWr=rXrY�assertEqualZtaurJrrr�
testConstants�szMathTests.testConstantscCs�|�ttj�|�dt�d�tj�|�dt�d�tjd�|�dt�d�d�|�ttjt�|�ttjt�|�ttjdt	�|�ttjdt	�|�
t�t�t���dS)Nzacos(-1)���zacos(0)rr6zacos(1)r)
�assertRaises�	TypeErrorr=ZacosrWrX�
ValueError�INF�NINF�eps�
assertTruer>�NANrJrrr�testAcosszMathTests.testAcoscCs�|�ttj�|�dt�d�d�|�dt�d�d�|�ttjd�|�ttjd�|�t�t�t�|�ttjt�|�	t�
t�t���dS)Nzacosh(1)rrzacosh(2)r6g5�qB�?r\)r]r^r=ZacoshrWr_rZr`rarcr>rdrJrrr�	testAcosh
szMathTests.testAcoshcCs�|�ttj�|�dt�d�tjd�|�dt�d�d�|�dt�d�tjd�|�ttjt�|�ttjt�|�ttjdt	�|�ttjdt	�|�
t�t�t���dS)Nzasin(-1)r\r6zasin(0)rzasin(1)r)
r]r^r=ZasinrWrXr_r`rarbrcr>rdrJrrr�testAsinszMathTests.testAsincCs�|�ttj�|�dt�d�d�|�dt�d�d�|�dt�d�d�|�t�t�t�|�t�t�t�|�t�	t�t
���dS)	Nzasinh(0)rzasinh(1)rg'�ya64�?z	asinh(-1)r\g'�ya64�)r]r^r=ZasinhrWrZr`rarcr>rdrJrrr�	testAsinh"szMathTests.testAsinhcCs�|�ttj�|�dt�d�tjd�|�dt�d�d�|�dt�d�tjd�|�dt�t�tjd	�|�d
t�t�tjd	�|�t�	t�t
���dS)Nzatan(-1)r\�zatan(0)rzatan(1)rz	atan(inf)r6z
atan(-inf))r]r^r=�atanrWrXr`rarcr>rdrJrrr�testAtan+szMathTests.testAtancCs�|�ttj�|�dt�d�d�|�dt�d�d�|�dt�d�d�|�ttjd	�|�ttjd
�|�ttjt�|�ttjt�|�	t�
t�t���dS)Nzatanh(0)rz
atanh(0.5)��?g�z��?zatanh(-0.5)��g�z��rr\)r]r^r=rjrWZatanhr_r`rarcr>rdrJrrr�	testAtanh4szMathTests.testAtanhcCs|�ttj�|�dt�dd�tjd�|�dt�dd�tjd�|�dt�dd�d�|�d	t�dd�tjd�|�d
t�dd�tjd�|�dt�dt�tj�|�d
t�dd�tj�|�dt�dd�tj�|�t�dd�d�|�t�dd�d�|�t�dt�d�|�	t�
t�dt���|�dt�dt�tj�|�dt�dd�tj�|�dt�dd�tj�|�t�dd�d�|�t�dd�d�|�t�dt�d�|�	t�
t�dt���|�dt�tt�tjdd�|�dt�td�tjd�|�dt�td�tjd�|�dt�td�tjd�|�dt�td�tjd�|�dt�tt�tjd�|�	t�
t�tt���|�dt�tt�tjdd�|�dt�td�tjd�|�dt�td�tjd�|�dt�td�tjd�|�d t�td�tjd�|�d!t�tt�tjd�|�	t�
t�tt���|�d"t�dt�tj�|�d#t�dd�tjd�|�d$t�dd�tjd�|�t�dt�d�|�	t�
t�dt���|�d%t�dt�tj�|�d&t�dd�tjd�|�d't�dd�tjd�|�t�dt�d�|�	t�
t�dt���|�	t�
t�tt���|�	t�
t�td���|�	t�
t�td���|�	t�
t�td���|�	t�
t�td���|�	t�
t�tt���|�	t�
t�tt���dS)(Nzatan2(-1, 0)r\rr6zatan2(-1, 1)rrizatan2(0, 1)zatan2(1, 1)zatan2(1, 0)zatan2(0., -inf)r:zatan2(0., -2.3)�ffffff�zatan2(0., -0.)���ffffff@zatan2(-0., -inf)zatan2(-0., -2.3)zatan2(-0., -0.)zatan2(inf, -inf)�zatan2(inf, -2.3)zatan2(inf, -0.)zatan2(inf, 0.)zatan2(inf, 2.3)zatan2(inf, inf)zatan2(-inf, -inf)zatan2(-inf, -2.3)zatan2(-inf, -0.)zatan2(-inf, 0.)zatan2(-inf, 2.3)zatan2(-inf, inf)zatan2(2.3, -inf)zatan2(2.3, -0.)zatan2(2.3, 0.)zatan2(-2.3, -inf)zatan2(-2.3, -0.)zatan2(-2.3, 0.))r]r^r=�atan2rWrXrarZr`rcr>rdrJrrr�	testAtan2?sf "zMathTests.testAtan2cCsf|�ttj�|�ttt�d���|�t�d�d�|�t�d�d�|�t�d�d�|�t�d�d�|�t�d�d	�|�t�d
�d	�|�t�d�d�|�t�d�d�Gd
d�d�}Gdd�dt�}Gdd�d�}|�t�|��d�|�t�|��d�|�t�td��d�|�ttj|��|�}dd�|_	|�ttj|�|�ttj|d�dS)Nrlr��?��?r6rmr��r\���r:rpc@seZdZdd�ZdS)z$MathTests.testCeil.<locals>.TestCeilcSsdS�N�*rrJrrr�__ceil__�sz-MathTests.testCeil.<locals>.TestCeil.__ceil__N�rLrMrNr{rrrr�TestCeil�sr}c@seZdZdd�ZdS)z%MathTests.testCeil.<locals>.FloatCeilcSsdSryrrJrrrr{�sz.MathTests.testCeil.<locals>.FloatCeil.__ceil__Nr|rrrr�	FloatCeil�sr~c@seZdZdS)z&MathTests.testCeil.<locals>.TestNoCeilNrPrrrr�
TestNoCeil�srrzg@E@�+cWs|SrDr��argsrrr�<lambda>��z$MathTests.testCeil.<locals>.<lambda>)
r]r^r=ZceilrZr<�typer)rCr{)rHr}r~r�trrr�testCeil|s*
zMathTests.testCeilcCs�|�t�dd�d�|�t�dd�d�|�t�dd�d�|�t�dd�d�|�t�d	d
�d�|�ttj�|�t�dd�d�|�t�dd
�d�|�t�td�t�|�t�td
�t�|�t�td�t�|�t�td
�t�|�t�dt�d�|�t�dt�d�|�t�tt�t�|�t�tt�t�|�t�tt�t�|�t�tt�t�|�t�t�t	d���|�t�t�t	t���|�t�t�t	t���|�t�t�t	t	���|�t�
t�tt	���|�tt�dt	��d�dS)
Nrrzrur:i���rwrr�@�@rp���@)rZr=�copysignr]r^r`rarcr>rdr?rrJrrr�testCopysign�s0zMathTests.testCopysigncCs|�ttj�|jdt�tjd�dt�d�d�|�dt�d�d�|jdt�tjd�dt�d�d�|�dt�tj�d	�z0|�t�t�t	���|�t�t�t
���Wn2ty�|�ttjt	�|�ttjt
�Yn0|�t�t�t���dS)
Nz
cos(-pi/2)r6rr�r!zcos(0)z	cos(pi/2)zcos(pi)r\)
r]r^r=ZcosrWrX�ulprcr>r`rar_rdrJrrr�testCos�s&$zMathTests.testCosZwin32)ZARMZARM64zEWindows UCRT is off by 2 ULP this test requires accuracy within 1 ULPcCs�|�ttj�|�dt�d�d�|�dt�d�dt�d�dd�|�t�t�t�|�t�t�t�|�t�	t�t
���dS)Nzcosh(0)rrzcosh(2)-2*cosh(1)**2r6r\)r]r^r=�coshrWrZr`rarcr>rdrJrrr�testCosh�s&zMathTests.testCoshcCsr|�ttj�|�dt�tj�d�|�dt�tjd�d�|�dt�tjd�d�|�d	t�d
�d
�dS)Nzdegrees(pi)g�f@z
degrees(pi/2)r6g�V@zdegrees(-pi/4)rig�F�z
degrees(0)r)r]r^r=ZdegreesrWrXrJrrr�testDegrees�s
zMathTests.testDegreescCs�|�ttj�|�dt�d�dtj�|�dt�d�d�|�dt�d�tj�|�t�t�t�|�t�t�d�|�	t�
t�t���|�ttjd�dS)	Nzexp(-1)r\rzexp(0)rzexp(1)r:�@B)
r]r^r=r3rWrYrZr`rarcr>rd�
OverflowErrorrJrrr�testExp�szMathTests.testExpcCsN|�ttj�|�dt�d�d�|�dt�d�d�|�dt�d�d�dS)Nzfabs(-1)r\rzfabs(0)rzfabs(1))r]r^r=ZfabsrWrJrrr�testFabs�szMathTests.testFabscCs�|�t�d�d�d}tdd�D]4}||9}|�t�|�|�|�t�|�t|��q |�ttjd�|�ttjdd�dS)Nrr��r\�
�d)rZr=�	factorialrrr]r_)rH�totalrrrr�
testFactorial�szMathTests.testFactorialcCs*|�t��"|�t�d�d�Wd�n1s20Y|�t�� |�ttjd�Wd�n1sl0Y|�t�� |�ttjd�Wd�n1s�0Y|�t�� |�ttjd�Wd�n1s�0Y|�ttjt�	d��|�ttjt�	d��|�ttjd�dS)N�@�xg������@rw�}Ô%�I���5z5.2)
�assertWarns�DeprecationWarningrZr=r�r]r_r^�decimal�DecimalrJrrr�testFactorialNonIntegers�s0...z"MathTests.testFactorialNonIntegerscCsR|�ttjdd�|�t�� |�ttjd�Wd�n1sD0YdS)Nr�r��}Ô%�I�T)r]r�r=r�r�r�rJrrr�testFactorialHugeInputssz!MathTests.testFactorialHugeInputscCsB|�ttj�|�ttt�d���|�t�d�d�|�t�d�d�|�t�d�d�|�t�d�d�|�t�d�d�|�t�d	�d
�Gdd�d�}Gd
d�dt�}Gdd�d�}|�t�|��d�|�t�|��d�|�t�td��d�|�ttj|��|�}dd�|_	|�ttj|�|�ttj|d�dS)Nrlrrurrvrmr\rwrx���c@seZdZdd�ZdS)z&MathTests.testFloor.<locals>.TestFloorcSsdSryrrJrrr�	__floor__sz0MathTests.testFloor.<locals>.TestFloor.__floor__N�rLrMrNr�rrrr�	TestFloorsr�c@seZdZdd�ZdS)z'MathTests.testFloor.<locals>.FloatFloorcSsdSryrrJrrrr�sz1MathTests.testFloor.<locals>.FloatFloor.__floor__Nr�rrrr�
FloatFloorsr�c@seZdZdS)z(MathTests.testFloor.<locals>.TestNoFloorNrPrrrr�TestNoFloor!sr�rzg33333�D@�)cWs|SrDrr�rrrr�)r�z%MathTests.testFloor.<locals>.<lambda>)
r]r^r=ZfloorrZr<r�r)rCr�)rHr�r�r�r�rrr�	testFloors&
zMathTests.testFloorcCs�|�ttj�|�dt�dd�d�|�dt�dd�d�|�dt�dd�d	�|�d
t�dd�d�|�d
t�dd�d�|�dt�dd�d�|�t�t�td	���|�t�t�d	t���|�t�t�tt���|�ttjd	d�|�ttjt	d	�|�ttjt
d	�|�ttjt	d�|�t�dt	�d�|�t�dt	�d�|�t�dt
�d�|�t�dt
�d�|�t�dd�d�|�t�dt
�d�dS)Nzfmod(10, 1)r�rr:z
fmod(10, 0.5)rlz
fmod(10, 1.5)rvruzfmod(-10, 1)���rpzfmod(-10, 0.5)zfmod(-10, 1.5)rwr���)r]r^r=ZfmodrWrcr>rdr_r`rarZrJrrr�testFmod-s(zMathTests.testFmodcs���ttj��fdd�}|dt�d�d�|dt�d�d�|d	t�d
�d�|dt�d
�d���t�t�dt���t�t�dt���t�t�t	�d��dS)NcsB||\}}\}}t||�tks*||kr>��d|||f�dS�Nz%s returned %r, expected %r�rrbrU)rV�resultr�mantr3ZemantZeexprJrr�	testfrexpFs
�z&MathTests.testFrexp.<locals>.testfrexpz	frexp(-1)r\)rmrzfrexp(0)r�rrzfrexp(1)r)rlrzfrexp(2)r6)rlr6)
r]r^r=�frexprZr`rarcr>rd)rHr�rrJr�	testFrexpCszMathTests.testFrexpz2fsum is not exact on machines with double roundingcs8ddlm}|j�|j����fdd�}gdfdgdfgd�dfgd�d	fgd
�dfgd�d
fgd�dfdd�tdd�D�t�d�fdd�tdd�D�t�d�fgd�dfgd�dfdd�tddd�D�dgt�d�fg}d d�td�D��|��fd!d�td"�D��d"g�df�t|�D]x\}\}}zt	�
|�}WnNt�yl|�d#|||f�Yn(t
�y�|�d$|||f�Yn0|�||��q*dd%lm}m}	m}
td"�D]r}gd&�d'}d}td(�D],}|	d|��d)|}
||
7}|�|
��q�|
|�||�}|�||�t	�
|���q�dS)*Nr)�
float_infocs�d\}}|D]Z}t�|�\}}tt�|���|�}}||krR|||K}|}n|||K}||7}qtttt|���d��|�}|dkr�d|d>}|d|t||@o�|d|d@�}||7}t�||�S)z�Full precision summation.  Compute sum(iterable) without any
            intermediate accumulation of error.  Based on the 'lsum' function
            at http://code.activestate.com/recipes/393090/

            r�r6rrrr)	r=r�r<�ldexp�max�len�binr�bool)�iterableZtmantZtexprr�r3�tail�h)�etiny�mant_digrr�msumhs
"(z MathTests.testFsum.<locals>.msumr:)r�rur��0��.�++g�d~�QJrwg�d~�Q�r�)�@Crmg��g������?C)r�ru��9g@C)g@Crur�g@C)g������?Crlg�<g������?CcSsg|]}d|�qS�rur��.0r
rrr�
<listcomp>�r�z&MathTests.testFsum.<locals>.<listcomp>ri�z0x1.df11f45f4e61ap+2cSsg|]}d||�qS)rwrr�rrrr��r�z-0x1.62a2af1bd3624p-1)r	rug��ؗ�Ҝ<g��7y�AC)g��7y�ACg�������?g��7y�A�g�������cSs,g|]$}d|d|dd|d�qS)r��2�4rr�rrrr��r�����i�r6g�z0x1.5555555555555p+970cSsg|]}d|�qS)g333333�?r�r�rrrrr��r�cs g|]}�|d�|�qS)rrr�)�termsrrr��r�r�zDtest %d failed: got OverflowError, expected %r for math.fsum(%.100r)zAtest %d failed: got ValueError, expected %r for math.fsum(%.100r))�random�gauss�shuffle)�r�i����r�gh�$.5���g#B����;r���r�)�sysr�r��min_exprr)�fromhex�append�	enumerater=Zfsumr�rUr_rZr�r�r�)rHr�r��test_valuesrZvalsr�actualr�r�r��j�s�vr)r�r�r�r�testFsumUsj





��

��� ��
�zMathTests.testFsumcCsBtj}|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d	�|�|dd
�d	�|�|dd�d
�d}d}dD]�}||}||}|�|||�|�|�|||�|�|�|||�|�|�|||�|�|�|||�|�|�|||�|�|�|||�|�|�|||�|�q�|�|�d�|�|d�d�|�|d
�d�|�|ddd�d�|�|ddd�d�|�t|d�|�t|dd�|�t|dd�|�t|ddd�|�|td�td��d	�dS)Nrrr\r�����r��T����� j9W P)�}� "o�`T"-� l�8P9�cC�/�[�N
S�9�b�Xl	9@{�wM�2�75�k )��	lZ��'^%#�>�;�*Q!/61^�f��^@�U@)r=�gcdrZr]r^rQ)rHr�r�y�c�a�brrr�testGcd�sN��zMathTests.testGcdcCs�ddlm}ddlm}tj}tjtjt�d�t�	d�t�
d�f}tt|�d�D]8}|�
||d|��t�tdd	�|d|�D����qR|�|d
d�d�|�|d
d�d�|�||d
�|d��d�|�||d
d�|dd��|dd��|�|td�td�td�td��t�d��|�|dd�d�|�|d�d�|�|�d�|�dt�d|d���|�|ddd�|ddd��|�t��|dd�Wd�n1�s�0Y|�t��|ddd�Wd�n1�s�0Ydtjjd}|�ttf��|d|�Wd�n1�s,0Y|�|t�t�|�|dt�t�|�|dt�t�|�|dt�t�|�|tt�t�|�|tt�t�|�|tt�t�|�|tt�t�|�|tt�t�|�|tt�t�|�|dt�t�|�t�|t���|�t�|dt���|�t�|td���|�t�|dt���|�t�|tt���|�t�|t���td}td�D]&}|�||g|�|t�|���q�td�D]2}	td|	}
|�t�d |
d|
�d|
��q�dS)!Nr�r���Fractionr��@g������@rcss|]}|dVqdS)r6Nr)r�r�rrr�	<genexpr>�r�z&MathTests.testHypot.<locals>.<genexpr>g(@r��*@r�r9�
r�rrr:�%��%@rurprvrl�r皙�����?�string皙����@r�r�r�ri) r�r��	fractionsr�r=�hypotrYrX�sqrt�gamma�sinrr��assertAlmostEqual�sumrZr�r�r]r^r�r��
max_10_expr_r�r`rdrarcr>�	FLOAT_MAX�	FLOAT_MIN)rHr�r�rr�r�int_too_big_for_float�	fourthmaxr
r3�scalerrr�	testHypot�sl$�$,�

�*,*$zMathTests.testHypotcCsddlm}ddlm}tj}tj}|�|dd�d�|�|dd�d�td	�D]h}td
�D]Z}t	dd�t|�D��}t	d
d�t|�D��}|�
|||�|tdd�t||�D����q\qP|�|gd�gd��d�|�|t
gd��t
gd���d�|�|dd�d�|�|dd�d�|�||d�|d�f|d�|d�f�|d��|�||dd�|dd�f|dd�|dd�f�|dd��|�|dd�|d��|�|dd�d�|�|dd�d�|�d t�d |d!d"���|�d t�d |d"d!���|�|d#d$�|d%d$��Gd&d'�d't	�}	|�||	d�d�d�|�t��|dd(d)�Wd�n1�sZ0Y|�t��|d�Wd�n1�s�0Y|�t��|dd(d*�Wd�n1�s�0Y|�t��|dd�Wd�n1�s�0Y|�t��|d+d�Wd�n1�s20Y|�t��|d,d-�Wd�n1�sh0Y|�t��|dd.�Wd�n1�s�0Y|�t��|d/d0�Wd�n1�s�0Yd1tjjd
}
|�ttf��|d|
fd2�Wd�n1�s"0Y|�ttf��|d2d|
f�Wd�n1�s`0Ytd3�D]6}t��t��}}|�||f|f�t||���qrtd4d5dd6ttg}tj|d7d8�D]~}tj|d7d8�D]h}d9d:�t||�D�}tttj|���r|�|||�t�n(tttj |���r�|�!t� |||����qܐq�t"d;}
td�D]P}|
f|}d"|}|�|||�|
t�|��|�|||�|
t�|���qZtd�D]V}t#d|}d<|d7|f}d=}|�t�||�d
|�|�t�||�d
|��q�dS)>Nrr�r�)rur�r�)r�r�rwr�)rr6rr)rir6r\�	r9css|]}t�dd�VqdS����r9N�r�Zuniform�r��krrrr�9r�z%MathTests.testDist.<locals>.<genexpr>css|]}t�dd�VqdSrrrrrrr�:r�css|]\}}||dVqdS)r�Nr�r�ZpxZqxrrrr�=r�)g,@ru)r�r�r�)�r)r6���r�rrr6rr�)TTFTF)TFTTFr�)g�*@g)@g
�r:rru)rp)r:)rvrvrl)rrr)rvrlrvc@seZdZdS)zMathTests.testDist.<locals>.TNrPrrrr�T_sr)rir9r�)�p�q)r��r)rrr)rr6rrri)r9r�r�)rir9r�r��abcZxyzr�)r6rr�r�rpr�rr)�repeatcSsg|]\}}||�qSrrrrrrr��r�z&MathTests.testDist.<locals>.<listcomp>r�ri)r:r:)$r�r�rr�r=�distrrZr�tupler	r
�zip�iterr�r]r^r_r�r�rr�r�rrar`rd�	itertools�product�any�mapr?r>rcrr
)rH�D�Fr"rrr�rrrr�valuesZdiffsrr
r3rrrr�testDist*s��".,��������,(,*****.."
 zMathTests.testDistc
Cs4ttd��ttdd��dd�tdd�D�dd	d
dg}|D]r}|j|d��Rt�|�}|�t|�t�|�|||�|�	||d
|d
�Wd�qB1s�0YqB|�
t��t�d�Wd�n1s�0Yt�d�}|�t|�t�|�|d
�t�d�}|�t|�t�|�|d�Gdd�dt
�}t�|d��}|�t|�t�|�|d�|�
t��t�|d��Wd�n1�s�0Yddt�d�dddg}|D]j}|j|d��F|�
t��t�|�Wd�n1�s0YWd�n1�s"0Y�q�dS)Nr�iX>i(FcSs(g|] }tdd�D]}d||�qqS)i����(r6)r)r�rYrrrrr��r�z'MathTests.testIsqrt.<locals>.<listcomp>�<r�rri'r�i�rErr\TFrc@seZdZdd�Zdd�ZdS)z(MathTests.testIsqrt.<locals>.IntegerLikecSs
||_dSrDrErGrrrrI�sz1MathTests.testIsqrt.<locals>.IntegerLike.__init__cSs|jSrDrErJrrrrR�sz2MathTests.testIsqrt.<locals>.IntegerLike.__index__NrSrrrr�IntegerLike�sr0i�r����r�za stringz3.5y@gY@r�)�listr�subTestr=Zisqrt�assertIsr�r<�assertLessEqualZ
assertLessr]r_rZ�objectr�r�r^)rHr�rFr�r0Z
bad_valuesrrr�	testIsqrt�sF
����
8(

.�zMathTests.testIsqrtcCsNtj}|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd	�d
�|�|d	d�d
�|�|dd
�d�d}d}dD]�}||}||}|||}|�|||�|�|�|||�|�|�|||�|�|�|||�|�|�|||�|�|�|||�|�|�|||�|�|�|||�|�q�|�|�d�|�|d�d�|�|d�d�|�|dd	d�d�|�|ddd	�d�|�t|d�|�t|dd	�|�t|dd�|�t|ddd�|�|td�td	��d
�dS)Nrrr\r�r�r�iYr�r�iHr�r�r�l ,�`aUx�-�xB�:Vn
Ldbl�m�e%Y%l};T^�	)r�l�|/Kr2r�i�7r�r�)r=�lcmrZr]r^rQ)rHr8rr�r�r�r��drrr�test_lcm�sP��zMathTests.test_lcmc	Cs:|�ttj�|�dt�dd�d�|�dt�dd�d�|�dt�dd�d�|�d	t�dd�d
�|�ttjdd�|�ttjd
d�|�t�dd�d�|�t�d
d�d�|�t�td�t�|�t�td�t�|�	t�
t�td���dddddfD�]0}|�t�t|�t�|�t�t|�t�|�t�d|�d�|�t�d
|�d�|�t�d|�d�|�t�d|�d�|�	t�
t�t|���|�ttjd|�|�ttjd
|�|�t�d|�d�|�t�d|�d�|�t�t|�t�|�t�t|�t�|�	t�
t�t|����qdS)Nz
ldexp(0,1)rrz
ldexp(1,1)r6zldexp(1,-1)r\rlzldexp(-1,1)r�rur�rwi���r:rp�i+���i��ld(	� F�x:^Vr�r.)r]r^r=r�rWr�rZr`rarcr>rd�rHr
rrr�	testLdexp�s6zMathTests.testLdexpcCs|�ttj�|�dt�dtj�d�|�dt�d�d�|�dt�tj�d�|�dt�dd	�d
�|�dt�dd
d�d
�|�dt�dd
d�d	�|�dt�dd�d�|�ttjd�|�ttjdd�|�ttjt�|�t�t	�t	�|�
t�t�t���dS)Nzlog(1/e)rr\zlog(1)rzlog(e)z	log(32,2)r�r6r9zlog(10**40, 10)r�r.zlog(10**40, 10**20)r<z
log(10**1000)r�gO�+��@rx)
r]r^r=�logrWrYr_rarZr`rcr>rdrJrrr�testLogs�zMathTests.testLogcCsh|�ttj�dddddfD] }|�t�|�t�t|���q |�ttjd�|�t�t�t�dS)Nr6�Zi,r\)	r]r^r=Zlog1pr	r)r_rZr`r=rrr�	testLog1p,s
zMathTests.testLog1pcCs�|�ttj�|�t�d�d�|�t�d�d�|�t�d�d�|�t�dd�d�|�t�dd	�d
�|�t�dd�d�|�ttjd
�|�ttjt�|�t�t�t	���dS)Nrr:r6rurir�i�g��@�g�@i�g@�@rx)
r]r^r=�log2rZr_rarcr>rdrJrrr�testLog23szMathTests.testLog2r�cCs8dd�tdd�D�}dd�tdd�D�}|�||�dS)NcSsg|]}t�t�d|���qSr�)r=rDr�r�rrrr�Jr�z+MathTests.testLog2Exact.<locals>.<listcomp>r�rCcSsg|]}t|��qSr�r)r�rrrr�Kr�)rrZ)rHr�rrrr�
testLog2ExactEszMathTests.testLog2ExactcCs�|�ttj�|�dt�d�d�|�dt�d�d�|�dt�d�d�|�d	t�dd
�d�|�ttjd�|�ttjdd
�|�ttjt�|�t�t	�t	�|�
t�t�t���dS)
Nz
log10(0.1)皙�����?r\zlog10(1)rrz	log10(10)r�zlog10(10**1000)r�g@�@rx)
r]r^r=Zlog10rWr_rarZr?r`rcr>rdrJrrr�	testLog10NszMathTests.testLog10cs���ttj��fdd�}|dt�d�d�|dt�d�d���t�t�d	tf���t�t�d
tf�t�t�}��t�	|d����t�	|d��dS)
NcsF||\}}\}}t||�tks.t||�rB��d|||f�dSr�r�)rVr�rZv1Zv2Ze1Ze2rJrr�testmodf]s
�z$MathTests.testModf.<locals>.testmodfz	modf(1.5)rv)rlruz
modf(-1.5)rx)rmrwr:rprr)
r]r^r=ZmodfrZr`rardrcr>)rHrJZmodf_nanrrJr�testModfZs
zMathTests.testModfcCs�|�ttj�|�dt�dd�d�|�dt�dd�d�|�dt�dd�d�|�dt�dd�d	�|�t�td�t�|�t�td�t�|�t�dt�d
�|�t�dt�d
�|�t�	t�t
d���|�t�	t�dt
���|�t�	t�dt
���|�t�dt
�d�|�t�dt�d�|�t�dd�d�|�t�dd
�d�|�t�dd�d�|�t�dd�d
�|�t�dd�d
�|�ttjdd�|�ttjdd�|�ttjdd�|�ttjdt�|�t�	t�dt
���|�t�tt�t�|�t�td�t�|�t�td
�t�|�t�td�t�|�t�td�d
�|�t�td�d
�|�t�td�d�|�t�td�d�|�t�td�d�|�t�tt�d�|�t�	t�tt
���|�t�dt�d�|�t�dd�d�|�t�dd
�d�|�t�dd�d�|�t�dd�d
�|�t�dd�d
�|�ttjdd�|�ttjdd�|�ttjdd�|�ttjdt�|�t�	t�dt
���|�t�tt�t�|�t�td�t�|�t�td
�t�|�t�td�t�|�t�td�d
�|�t�td�d
�|�t�td�d�|�t�td�d�|�t�td�d�|�t�tt�d�|�t�	t�tt
���|�t�dt�d
�|�t�dd�d�|�ttjdd
�|�t�dd�d
�|�t�dd�d
�|�t�dd�d
�|�t�dd�d
�|�ttjdd�|�t�dd�d�|�t�dt�d
�|�t�	t�dt
���|�t�d
t�d
�|�t�d
d�d
�|�t�d
d
�d
�|�t�d
d�d
�|�t�d
d�d
�|�t�d
d�d
�|�t�d
d�d
�|�t�d
d�d
�|�t�d
d�d
�|�t�d
t�d
�|�t�d
t
�d
�|�t�d
d�d
�|�t�dd�d
�|�t�t
d�d
�|�t�d
d�d
�|�t�dd�d
�|�t�t
d�d
�|�ttjdd
�|�ttjdd�|�t�dt�d�|�t�dt�d�|�t�dt�t�|�t�dt�t�|�t�dt�t�|�t�dt�t�|�t�dt�d�|�t�dt�d�|�t�dt�t�|�t�dt�t�|�t�dt�d�|�t�dt�d�|�t�dt�d�|�t�dt�d�|�t�dt�t�|�t�dt�t�|�dt�dd�d�|�d t�dd�d!�|�d"t�dd
�d�|�d#t�dd�d
�|�d$t�dd�d
�|�d%t�dd�d&�|�d't�dd�d(�|�d)t�dd�d*�|�ttjdd&�|�ttjdd	�dS)+Nzpow(0,1)rrzpow(1,0)zpow(2,1)r6z	pow(2,-1)r\rlrur:r�rqr�rpg�ror�rwg.�g�������gffffff�?r��������?rHg��������g�������g�������gffffff��z	(-2.)**3.g �z	(-2.)**2.r�z	(-2.)**1.z	(-2.)**0.z
(-2.)**-0.z
(-2.)**-1.rmz
(-2.)**-2.g�?z
(-2.)**-3.g��)r]r^r=�powrWrZr`rarcr>rdr_rJrrr�testPowms�zMathTests.testPowcCsr|�ttj�|�dt�d�tj�|�dt�d�tjd�|�dt�d�tjd�|�d	t�d
�d
�dS)Nzradians(180)�zradians(90)rAr6zradians(-45)i���riz
radians(0)r)r]r^r=ZradiansrWrXrJrrr�testRadianss
zMathTests.testRadiansc	s�ddlm���fdd�}gd�}|D]�}�j|d��h|��\}}}t�|�}t�|�}t�|�}	||||	�t�||�}
��|
�	�|	�	��Wd�q&1s�0Yq&t�d�}t
dd	�D]`}|dkr�q�||}t
d
�D]@}
|
|}t�||�}
||||
�t�||�}
||||
�q�q�tddd
dtt
fD]*}��t�t|����t�|t���q8dD].}��t�|t
�|���t�|t�|��qhtddddt
fD]�}��t��t�t
|�Wd�n1�s�0Y��t��t�t|�Wd�n1�s0Y��t��t�|d�Wd�n1�sJ0Y��t��t�|d�Wd�n1�s�0Y�q�dS)Nrr�cs��|��|��|�}}}��t|�t|d��|||}��|t|��t|�t|d�kr|��|dt|d��dS)z�
            Check that r matches remainder(x, y) according to the IEEE 754
            specification. Assumes that x, y and r are finite and y is nonzero.
            r6N)r5rrZr<)rr��rZfxZfy�frr
�r�rHrr�
validate_spec
sz.MathTests.testRemainder.<locals>.validate_spec)0z-4.0 1 -0.0z-3.8 1  0.8z-3.0 1 -0.0z-2.8 1 -0.8z-2.0 1 -0.0z-1.8 1  0.8z-1.0 1 -0.0z-0.8 1 -0.8z-0.0 1 -0.0z 0.0 1  0.0z 0.8 1  0.8z 1.0 1  0.0z 1.8 1 -0.8z 2.0 1  0.0z 2.8 1  0.8z 3.0 1  0.0z 3.8 1 -0.8z 4.0 1  0.0z&0x0.0p+0 0x1.921fb54442d18p+2 0x0.0p+0z?0x1.921fb54442d18p+0 0x1.921fb54442d18p+2  0x1.921fb54442d18p+0z?0x1.921fb54442d17p+1 0x1.921fb54442d18p+2  0x1.921fb54442d17p+1z?0x1.921fb54442d18p+1 0x1.921fb54442d18p+2  0x1.921fb54442d18p+1z?0x1.921fb54442d19p+1 0x1.921fb54442d18p+2 -0x1.921fb54442d17p+1z?0x1.921fb54442d17p+2 0x1.921fb54442d18p+2 -0x0.0000000000001p+2z00x1.921fb54442d18p+2 0x1.921fb54442d18p+2  0x0p0z?0x1.921fb54442d19p+2 0x1.921fb54442d18p+2  0x0.0000000000001p+2z?0x1.2d97c7f3321d1p+3 0x1.921fb54442d18p+2  0x1.921fb54442d14p+1z?0x1.2d97c7f3321d2p+3 0x1.921fb54442d18p+2 -0x1.921fb54442d18p+1z?0x1.2d97c7f3321d3p+3 0x1.921fb54442d18p+2 -0x1.921fb54442d14p+1z?0x1.921fb54442d17p+3 0x1.921fb54442d18p+2 -0x0.0000000000001p+3z00x1.921fb54442d18p+3 0x1.921fb54442d18p+2  0x0p0z?0x1.921fb54442d19p+3 0x1.921fb54442d18p+2  0x0.0000000000001p+3z?0x1.f6a7a2955385dp+3 0x1.921fb54442d18p+2  0x1.921fb54442d14p+1z?0x1.f6a7a2955385ep+3 0x1.921fb54442d18p+2  0x1.921fb54442d18p+1z?0x1.f6a7a2955385fp+3 0x1.921fb54442d18p+2 -0x1.921fb54442d14p+1z?0x1.1475cc9eedf00p+5 0x1.921fb54442d18p+2  0x1.921fb54442d10p+1z?0x1.1475cc9eedf01p+5 0x1.921fb54442d18p+2 -0x1.921fb54442d10p+1z 1  0.c  0.4z-1  0.c -0.4z 1 -0.c  0.4z-1 -0.c -0.4z 1.4  0.c -0.4z-1.4  0.c  0.4z 1.4 -0.c -0.4z-1.4 -0.c  0.4z$0x1.dp+1023 0x1.4p+1023  0x0.9p+1023z$0x1.ep+1023 0x1.4p+1023 -0x0.ap+1023z$0x1.fp+1023 0x1.4p+1023 -0x0.9p+1023)�casez1p-1074i���r�r:rpr�ro)rorpr:rqrq)rr�r3r(r)r�r=�	remainderrZ�hexrrdrar`�assertIsNaNr]r_)rHrTZ	testcasesrUZx_hexZy_hexZexpected_hexrr�rr�Ztinyr
�mrFrrSr�
testRemainder	sL;


4
,,,zMathTests.testRemaindercCs�|�ttj�|�dt�d�d�|�dt�tjd�d�|�dt�tjd�d�z0|�t�t�t���|�t�t�t	���Wn2t
y�|�t
tjt�|�t
tjt	�Yn0|�t�t�t���dS)Nzsin(0)rz	sin(pi/2)r6rz
sin(-pi/2)r\)r]r^r=rrWrXrcr>r`rar_rdrJrrr�testSin�szMathTests.testSincCs�|�ttj�|�dt�d�d�|�dt�d�dt�d�dd�|�dt�d�t�d�d�|�t�t�t�|�t�t�t�|�	t�
t�t���dS)Nzsinh(0)rzsinh(1)**2-cosh(1)**2rr6r\zsinh(1)+sinh(-1))r]r^r=ZsinhrWr�rZr`rarcr>rdrJrrr�testSinh�s&zMathTests.testSinhcCs�|�ttj�|�dt�d�d�|�dt�d�d�|�dt�d�d�|�t�t�t�|�ttjd�|�ttjt�|�	t�
t�t���dS)	Nzsqrt(0)rzsqrt(1)rzsqrt(4)rir6r\)r]r^r=rrWrZr`r_rarcr>rdrJrrr�testSqrt�szMathTests.testSqrtcCs�|�ttj�|�dt�d�d�|�dt�tjd�d�|�dt�tjd�d�z0|�t�t�t���|�t�t�t	���Wn,|�t
tjt�|�t
tjt	�Yn0|�t�t�t���dS)Nztan(0)rz	tan(pi/4)rirz
tan(-pi/4)r\)r]r^r=ZtanrWrXrcr>r`rar_rdrJrrr�testTan�szMathTests.testTancCs�|�ttj�|�dt�d�d�|jdt�d�t�d�dt�d�d�|�dt�t�d�|�dt�t�d�|�t�	t�t
���dS)	Nztanh(0)rztanh(1)+tanh(-1)rr\r�z	tanh(inf)z
tanh(-inf))r]r^r=�tanhrWr�r`rarcr>rdrJrrr�testTanh�s�zMathTests.testTanhcCs8|�t�d�d�|�t�dt�d��t�dd��dS)Nrpru)rZr=r`r�rJrrr�testTanhSign�s
�zMathTests.testTanhSigncCsZ|�t�d�d�|�t�d�d�|�tt�d��t�|�tt�d��t�|�t�d�d�|�t�d�d�|�t�d�d�|�t�d�d�|�t�d�d�|�t�d	�d
�Gdd�d�}Gd
d�dt�}Gdd�d�}|�t�|��d�|�t�|��d�|�ttj�|�ttjdd�|�ttjtd��|�ttj|��dS)Nrr\rvrxg����?g�����g�!��rg-���?Y�i����c@seZdZdd�ZdS)z'MathTests.test_trunc.<locals>.TestTrunccSsdS�N�rrJrrr�	__trunc__�sz1MathTests.test_trunc.<locals>.TestTrunc.__trunc__N�rLrMrNrerrrr�	TestTrunc�srgc@seZdZdd�ZdS)z(MathTests.test_trunc.<locals>.FloatTrunccSsdSrcrrJrrrre�sz2MathTests.test_trunc.<locals>.FloatTrunc.__trunc__Nrfrrrr�
FloatTrunc�srhc@seZdZdS)z)MathTests.test_trunc.<locals>.TestNoTruncNrPrrrr�TestNoTrunc�srirdr6g�7@)	rZr=Ztruncr�r<r)r]r^rC)rHrgrhrirrr�
test_trunc�s&zMathTests.test_trunccCs�|�t�d��|�t�d��|�t�d��|�t�d��|�t�td���|�t�td���|�t�td���dS)Nr:rprurwrrr)rcr=Zisfinite�assertFalser)rJrrr�testIsfinite�szMathTests.testIsfinitecCsx|�t�td���|�t�td���|�t�td�d��|�t�td���|�t�d��|�t�d��dS)Nrz-nanrr:ru)rcr=r>r)rkrJrrr�	testIsnan�szMathTests.testIsnancCs�|�t�td���|�t�td���|�t�d��|�t�d��|�t�td���|�t�d��|�t�d��dS)Nrrg�g�rr:ru)rcr=r?r)rkrJrrr�	testIsinf�szMathTests.testIsinfcCs|�t�tj��dSrD)rcr=r>rrJrrr�test_nan_constant�szMathTests.test_nan_constantcCsJ|�t�tj��|�tjd�|�tjtd��|�tjtd��dS)Nr:rr)rcr=r?rZ
assertGreaterrZr)rJrrr�test_inf_constantszMathTests.test_inf_constantzrequires verbose modecCs�zt�d�}Wn|�d�Yn0|dkr8|�d�zt�d�}WntyXYn0|�d�zt�d�}Wnty�Yn0|�d�dS)	Ni6e�z6underflowing exp() should not have raised an exceptionrz)underflowing exp() should have returned 0iʚ;z.overflowing exp() didn't trigger OverflowErrorrwz sqrt(-1) didn't raise ValueError)r=r3rUr�rr_�rHrrrr�test_exceptionss 

zMathTests.test_exceptionsc	Csfdh}d}tjdkrLt��d}zttt|�d���}WntyJYn0d}g}tt	�D]�\}}}}	}
}}|	dks\|dkr�q\|dvr�q\|dur�|dkr�||vr�q\t
t|�}
d	|vs�d
|vr�d}
nd|vr�d
}
z|
|�}Wn,ty�d}Ynt�yd
}Yn0d\}}t
|
|||�}|du�r,q\|�||||�}|�|�q\|�rb|�dd�|��dS)NZtan0064�darwinr�.�{}: {}({!r}): {}r:)ZrectZpolar)r�r9�invalid�divide-by-zeror_�overflowr��r9r:zFailures in test_testfile:
  �
  )r��platformZmac_verr#r)r<r(r_r8�	test_file�getattrr=r�rBrr�rU�join)rHZ
SKIP_ON_TIGERZosx_versionZversion_txtrA�failuresr/r0ZarZaiZerZeir4�funcr�r r!r@�msgrrr�
test_testfile.sN



�zMathTests.test_testfilec	Cs(d}g}tt�D]�\}}}}}tt|�}d|vs8d|vr>d}nd|vrJd}z||�}	Wn*tyld}	Ynty�d}	Yn0d\}
}|dkr�d	}
n>|d
kr�d}n0|dkr�|d
kr�|dkr�d}
n|dkr�d}
nd}
t||	|
|�}|dur�q|�||||�}
|�|
�q|�r$|�	dd�
|��dS)Nrurvrwr_rxr�ryrr ZlgammagV瞯�<Zerfcr:rur��$@r�r�zFailures in test_mtestfile:
  rz)r5�math_testcasesr}r=r_r�rBrr�rUr~)rHrArr/r0r1rr4r�rr r!r@r�rrr�test_mtestfilegsD

�zMathTests.test_mtestfilec
Cs�tj}|�|g�d�|�|gdd�d�|�|ttdd���d�|�|tttdd����d�|�|tdd�dd�d�|�|gd	��d
�|�|gd��d�|�|gd
��d�|�|gd��d�|�|gd��d�|�|gd��td��|�t|�|�t|d�|�t|gd��|jt|gd�dd�|jt|ddgdd�t	d�t	d�g}|jt||t	d�d�|�t|dgdgdgg�|�t|ddig�|jt|ddigdddid�|jt|dgdgdgggd�|�|ddgdd�d�|�|ddgddgd�gd��|�|gddid�ddi�|�t��|ddgd�Wd�n1�sf0Y|�|gd��d�|�|gd ��d�|�|gd!��d�d7d"d#�}tdd$�}|�||�||��td%d&�}|�||�||��td'd(�}|�||�d�d)d*�tdd(�D�}|�||�||��d+d*�td'd&�D�}|�||�||��d,d*�td'd(�D�}|�
||��|�
|dddtd-�ddg��|�
|ddtd-�ddg��|�
|dtd-�ddg��|�
|dtd.�td-�dg��|�
|dtd/�td-�dg��|�
|dtd-�td.�dg��|�
|dtd-�td/�dg��|�|dddtd.�d0d1g�td/��|�|dddtd/�d0d1g�td.��|�
|dddtd.�d0d1g��|�
|dddtd/�d0d1g��|�
|dddtd.�d0ddg��|�
|dddtd/�d0ddg��|�t|gd2���t�|�t|gd3���t�|�t|tdd$���t�|�t|tdd$�d4d��t�|�t|dt
�d5�dd1dd6g��t
j�dS)8Nrr9)rr6ri�r�i_7)rr6rrrir9r�)rur�r�r�r�r�)rr6rrr�r�)rur�r�rir9)rr�rrr�)rurur�rrrz)r�r�r���a�cr��brrZabZabababababab)rr6rr6rr6rr6rr6rr6r )rrr6rrr)rrr6rr)rr6rrrcSs|D]}||9}q|SrDr)r�r�elemrrr�_naive_prod�s
z(MathTests.test_prod.<locals>._naive_prodi'i���r\i���r�cSsg|]}t|��qSrrF�r�rrrrr��r�z'MathTests.test_prod.<locals>.<listcomp>cSsg|]}t|��qSrrFr�rrrr��r�cSsg|]}t|��qSrrFr�rrrr��r�rrrr1ri)rr6rrrir9r�)rr�rrrir9r�rur�r�)r)r=�prodrZr2rr%r)r]r^�	bytearrayrYr�r<r�r�)rHr�r,r�r�rrr�	test_prod�s�  .



$$   �zMathTests.test_prodc	CsLtj}tj}td�D]8}t|d�D]&}|�|||�||�|||��q$qtdd�D]F}td|�D]6}|�|||�||d|d�|||d|��qfqXtdd�D]>}|�||d�d�|�||d�|�|�|||�||��q�td�D].}|�||�||��|�||d�||��q�|�t|dd�|�t|dt�d��|�t|dd�|�t|dd�|�t|t�d�d�|�t|d	d�|�t|�|�t|ddd
�|�t|�|�t	|dd�|�t	|dd
d�|�t	|dd�|�t	|ddd
�|�|dd�d�|�|ddd
�d�dd
}|�||d�d�|�||d�|�|�||d�||d�t
jdd��r�|�t|||�dD]2\}}|�|||�d�|�
t|||��t��q�|�|td�td��d�|�|td�td��d�td
�D]B}|�
t|td�t|���t�|�
t|td�t|���t��qdS)Nr�rrr r�ru�1r��10rrr\r6r�T�Zcpython�)TT)TF)FFr9)r=�permr�rrZr]r^r�r�r_r�check_impl_detailr�r4r�r<rOrQ)rHr�r�r
rrrr�testPerms\�6zMathTests.testPermc
Cs�tj}tj}td�D]@}t|d�D].}|�|||�||�||�|||��q$qtdd�D]B}td|�D]2}|�|||�||d|d�||d|��qnq`td�D](}|�||d�d�|�|||�d�q�tdd�D],}|�||d�|�|�|||d�|�q�td�D]6}t|d�D]"}|�|||�||||���q&�q|�t|dd�|�t|dt�d��|�t|dd�|�t|dd�|�t|t�d�d�|�t|d	d�|�t|d�|�t|ddd
�|�t|�|�t	|dd�|�t	|ddd�|�t	|dd�|�t	|ddd�|�|dd�d�|�|ddd�d�dd}|�||d�d�|�||d�|�|�||d�||dd�|�|||�d�|�|||d�|�|�|||d�||dd�t
jd
d��r|�t|||d�dD]2\}}|�|||�d�|�
t|||��t��q|�|td�td��d�|�|td�td��d�td
�D]B}|�
t|td�t|���t�|�
t|td�t|���t��q�dS)Nr�rrr6r�rur�r�r�rrr\r�Tr�r�r9)r=�combr�rrZr]r^r�r�r_rr�r�r4r�r<rOrQ)rHr�r�r
rrrr�testCombFsf�
2$"zMathTests.testCombcCs|�t�dt�d�|�t�dt�d�|�t�dd�d�|�t�dd�d�|�t�d	t�t�d
��|�t�d	t�t�d��|�t�dd�d�|�t�d
d�d�|�t�dd
�d
�tjj	tjj
}|�t�dt�|�|�t�d
t�|�|�t�dt�|�|�t�d
t�|�|�t�|d�d�|�t�|d�d
�|�t�|d
�d�|�t�|d
�d
�tjj}|�t�td�|�|�t�td�|�|�t�|t�t�|�t�|t�t�|�t�t
d	��|�t�d	t
��|�t�t
t
��dS)Ng0Cg������/Cg0Cg�Cr:g�������Cg��g��������ruz0x1.fffffffffffffp-1z0x1.0000000000001p+0r�rp)rZr=�	nextafterr`r)r��assertEqualSignr�r��min�epsilonr�rYrd)rHZsmallest_subnormalZlargest_normalrrr�test_nextafter�sL������zMathTests.test_nextafterc	Cs|�t�d�tjj�|�t�d�d�|�t�d�d�|�t�d�d�|�t�d�tjjtjj�|�t�t�tt�tt	��|�t�t	�t	�|�
t�tj��ddddt	fD]J}|j|d��*|�t�|�t�|��Wd�q�1s�0Yq�dS)	Nrul�lr�lg�@r:r)
rZr=r�r�r�r�r�rr�r`rYrr3rqrrr�test_ulp�s��zMathTests.test_ulpc	CstGdd�d�}tjtjtjfD]P}|�}|�t��|d|�Wd�n1sR0Y|�t|dd��qdS)Nc@seZdZdd�ZdS)z$MathTests.test_issue39871.<locals>.FcSsd|_dddS)NTrr)�	convertedrJrrrrK�sz.MathTests.test_issue39871.<locals>.F.__float__N)rLrMrNrKrrrrr+�sr+znot a numberr�F)r=rsr�rWr]r^rkr})rHr+r�r�rrr�test_issue39871�s(zMathTests.test_issue39871cCst�|�s|�d�|��dS)NzExpected a NaN, got {!r}.)r=r>rUrrGrrrrY�s
zMathTests.assertIsNaNcCs,|�||�|�t�d|�t�d|��dS)zSimilar to assertEqual(), but compare also the sign with copysign().

        Function useful to compare signed zeros.
        ruN)rZr=r�)rHrr�rrrr��szMathTests.assertEqualSignN)r9r:)LrLrMrNrWr[rerfrgrhrkrnrtr�rr�r��unittestZskipIfr�r{�machiner�r�r�r�r�r�rZcpython_onlyr�r�r�r��HAVE_DOUBLE_ROUNDINGr�r�rr-r7r:r>r@rBrEZrequires_mac_verrGrIrKrNrPr[r\r]r^r_rarbrjrlrmrnrorpZ
skipUnlessrrrr�r�r�r�r�r�r�r�rYr�rrrrrT�s�


		=!
!�



�^*Jq5, 



	

	
		




8
B\@F
-
rTc@s�eZdZejZdd�Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS) �IsCloseTestscOs0|j|j||g|�Ri|��d||fd�dS)Nz%s and %s should be close!�r�)rc�isclose�rHr�r�r��kwargsrrr�
assertIsClose�s
�zIsCloseTests.assertIsClosecOs0|j|j||g|�Ri|��d||fd�dS)Nz%s and %s should not be close!r�)rkr�r�rrr�assertIsNotClose�s
�zIsCloseTests.assertIsNotClosecOs,|D]"\}}|j||g|�Ri|��qdSrD)r��rHZexamplesr�r�r�r�rrr�assertAllClose�szIsCloseTests.assertAllClosecOs,|D]"\}}|j||g|�Ri|��qdSrD)r�r�rrr�assertAllNotClose�szIsCloseTests.assertAllNotClosecCsz|�t�� |jdddd�Wd�n1s00Y|�t��"|jddddd�Wd�n1sl0YdS)Nrg0��.�+���rel_tolr�g _�©r�r!)r]r_r�rJrrr�test_negative_tolerancess.z%IsCloseTests.test_negative_tolerancescCsgd�}|j|ddd�dS)N))r�r�)�N���@ir�)�;���r�)i90g��@)r:rp)�NFr�r:r��r�)rHZidentical_examplesrrr�test_identical
szIsCloseTests.test_identicalcCs(gd�}|j|dd�|j|dd�dS)N))g�חAg�חA)g:�0�yE�g��n�yE�)g�	ѭ��?gfN�ӭ��?�:�0�yE>r���&�.>�r�r�)rHZeight_decimal_places_examplesrrr�test_eight_decimal_placessz&IsCloseTests.test_eight_decimal_placescCs(gd�}|j|dd�|j|dd�dS)N))r�r:)g��&�.�r:)gu�?j�/ʠr:rLr�r�r�)r�r�)rHZnear_zero_examplesrrr�test_near_zeroszIsCloseTests.test_near_zerocCs<|�tt�|jttdd�|�tt�|jttdd�dS)Nr:r�)r�r`rarJrrr�test_identical_infinite&sz$IsCloseTests.test_identical_infinitecCsRttftdfdtfttfttfttftdfdtftdfdtfg
}|j|dd�dS)Nr�rug������g�������?r�)rdr`rar�)rHZnot_close_examplesrrr�test_inf_ninf_nan-s�zIsCloseTests.test_inf_ninf_nancCs0gd�}|j|dd�gd�}|j|dd�dS)N))ruru)�333333�r�)�Y��n��r�r:r�))rug�?)g�������?ru)gZb���tigTb���tir�)rHZzero_tolerance_close_examplesZ!zero_tolerance_not_close_examplesrrr�test_zero_tolerance<sz IsCloseTests.test_zero_tolerancecCs|jddgdd�dS)N)rr�)r�rrHr�r�rJrrr�test_asymmetryHszIsCloseTests.test_asymmetrycCs(ddg}|j|dd�|j|dd�dS)N)����)i�[i�[r�r�r�r�)rHZinteger_examplesrrr�
test_integersLs
�zIsCloseTests.test_integerscCshddlm}|d�|d�f|d�|d�f|d�|d�f|d	�|d
�fg}|j|dd�|j|d
d�dS)Nrr�z
1.00000001z1.0z1.00000001e-20z1.0e-20z1.00000001e-100z1.0e-100z
1.00000001e20z1.0e20r�r�r�)r�r�r�r�)rHr�Zdecimal_examplesrrr�
test_decimalsTs�zIsCloseTests.test_decimalscCsdddlm}|dd�d|d�f|d�|d�f|dd�|dd�fg}|j|dd	�|j|d
d	�dS)Nrr�rr�r�l �	(q�e�	r<r�r�r�)rr�r�r�)rHr�Zfraction_examplesrrr�test_fractions_s�zIsCloseTests.test_fractionsN)rLrMrNr=r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��s 

r�cCsNddlm}t��}|�t�t��|�t�t��|�|d��t|�dS)Nr)�DocFileSuitezieee754.txt)	Zdoctestr�r�Z	TestSuiteZaddTestZ	makeSuiterTr�r)r�Zsuiterrr�	test_mainksr�)r9r:)8Ztest.supportrrr�testrr�r&r�r=�osr{r�rr�rbr)rdr`rar�r�rr�r
rr�r�rL�argv�file�__file__�path�dirname�curdirZtest_dirr~r�r|rrrrr"r5r8rBrCr<rOr6rQZTestCaserTr�r�rrrr�<module>sl&
-{