Uname:Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64

403WebShell
403Webshell
Server IP : 3.111.61.48  /  Your IP : 216.73.216.67
Web Server : Apache
System : Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64
User : ubuntu ( 1000)
PHP Version : 8.2.31
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3.10/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.10/test/__pycache__/test_math.cpython-310.pyc
o

�9j�j�@s�ddlmZmZmZddlmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZdZed�Zed�Zed�ZejjZejjZd\ZZeed	kZed
kr^ejdZneZe
j �!e�phe
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
kr�e7�dSdS),�)�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)�struct�unpack�pack)�x�n�r�%/usr/lib/python3.10/test/test_math.py�to_ulps's
rcCs|rdt||d@�SdS)zANumber of '1' bits in binary expansion of a nonnnegative integer.�r)�count_set_bits)rrrrrMsrcCs@||d?}|s
dS|dkr|S||dB}t||�t||�S)z�Product of integers in range(start, stop, 2), computed recursively.
    start and stop should both be odd, with start <= stop.

    r)�partial_product)�start�stop�
numfactors�midrrrrQsrcCs`d}}tt|����D]}|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�inner�outer�irrr�py_factorial_s
*
r cCsHtt|�t|��}t||�}||ks||krdSd}|�||||�S)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_tol�	ulp_error�	abs_error�fmtrrr�
ulp_abs_checkjsr*ccs��t|dd��H}|D]<}d|vr|d|�d��}|��sq
|�d�\}}|��\}}}|��}|d}	|dd�}
||t|�t|	�|
fVq
Wd�dS1sRwYdS)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]*

    �utf-8��encoding�--N�->rr)�open�index�strip�split�float)�fname�fp�line�lhs�rhs�id�fn�arg�
rhs_pieces�exp�flagsrrr�parse_mtestfile|s�	�"�r@c
	cs��t|dd��L}|D]@}|�d�s|��sq
|�d�\}}|��\}}}}|��}	|	d|	d}
}|	dd�}||t|�t|�t|
�t|�|fVq
Wd�dS1sVwYdS)	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,r.r/rr�N)r0�
startswithr2r3r4)
r5r6r7r8r9r:r;�arg_real�arg_imagr=�exp_real�exp_imagr?rrr�parse_testfile�s"���"�rG��cCs�||krdSd}t|t�rt|t�rt|�}nt|t�r%t|t�r%t|�}t|t�rNt|t�rNt�|�r<t�|�r<d}nt�|�sFt�|�rGnt||||�}|durcd}|�||�}|d�|�7}|SdS)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 ({}))�
isinstancer4�int�math�isnan�isinfr*r")r#r$r%r&�failure�fail_fmt�fail_msgrrr�result_check�s&
rRc@�eZdZdd�Zdd�ZdS)�	FloatLikecC�
||_dS�N��value��selfrXrrr�__init__��
zFloatLike.__init__cC�|jSrVrW�rZrrr�	__float__��zFloatLike.__float__N)�__name__�
__module__�__qualname__r[r_rrrrrT��rTc@�eZdZdS)�IntSubclassN�rarbrcrrrrrf��rfc@rS)�MyIndexablecCrUrVrWrYrrrr[�r\zMyIndexable.__init__cCr]rVrWr^rrr�	__index__�r`zMyIndexable.__index__N�rarbrcr[rjrrrrri�rdric@s�eZdZd�dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Ze
dd��Zdd�Ze�ejdkoCe��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$e
e�e!d9�d:d;���Z%d<d=�Z&d>d?�Z'd@dA�Z(dBdC�Z)dDdE�Z*dFdG�Z+dHdI�Z,e
dJdK��Z-e
e�.dLd�dMdN���Z/dOdP�Z0dQdR�Z1dSdT�Z2dUdV�Z3e
dWdX��Z4dYdZ�Z5d[d\�Z6d]d^�Z7d_d`�Z8dadb�Z9e
dcdd��Z:dedf�Z;dgdh�Z<didj�Z=dkdl�Z>e
dmdn��Z?e
dodp��Z@e�AeBdq�drds��ZCe
dtdu��ZDe
dvdw��ZEdxdy�ZFdzd{�ZGd|d}�ZHe
d~d��ZIe
d�d���ZJd�d��ZKd�d��ZLd�d��ZMd�S)��	MathTestsrHrIcCs0t||||�}|dur|�d�||��dSdS)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{}: {})rR�failr")rZ�namer$r#r%r&rOrrr�ftest�s	�zMathTests.ftestcCs8|�dtjd�|�dtjd�|�tjdtj�dS)N�pig-DT�!	@�egiW�
�@rA)rorLrprq�assertEqual�taur^rrr�
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)rrAzacos(1)r)
�assertRaises�	TypeErrorrL�acosrorp�
ValueError�INF�NINF�eps�
assertTruerM�NANr^rrr�testAcosszMathTests.testAcoscCs�|�ttj�|�dt�d�d�|�dt�d�d�|�ttjd�|�ttjd�|�t�t�t�|�ttjt�|�	t�
t�t���dS)Nzacosh(1)rrzacosh(2)rAg5�qB�?ru)rvrwrL�acoshroryrrrzr{r}rMr~r^rrr�	testAcosh
szMathTests.testAcoshcCs�|�ttj�|�dt�d�tjd�|�dt�d�d�|�dt�d�tjd�|�ttjt�|�ttjt�|�ttjdt	�|�ttjdt	�|�
t�t�t���dS)Nzasin(-1)rurAzasin(0)rzasin(1)r)
rvrwrL�asinrorpryrzr{r|r}rMr~r^rrr�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)rug'�ya64�)rvrwrL�asinhrorrrzr{r}rMr~r^rrr�	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)ru�zatan(0)rzatan(1)rz	atan(inf)rAz
atan(-inf))rvrwrL�atanrorprzr{r}rMr~r^rrr�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��rru)rvrwrLr�ro�atanhryrzr{r}rMr~r^rrr�	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)rurrAzatan2(-1, 1)rr�zatan2(0, 1)zatan2(1, 1)zatan2(1, 0)zatan2(0., -inf)rIzatan2(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.))rvrwrL�atan2rorpr{rrrzr}rMr~r^rrr�	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)Nr�r��?��?rAr�r��ru���rIr�c@�eZdZdd�ZdS)z$MathTests.testCeil.<locals>.TestCeilcS�dS�N�*rr^rrr�__ceil__��z-MathTests.testCeil.<locals>.TestCeil.__ceil__N�rarbrcr�rrrr�TestCeil��r�c@r�)z%MathTests.testCeil.<locals>.FloatCeilcSr�r�rr^rrrr��r�z.MathTests.testCeil.<locals>.FloatCeil.__ceil__Nr�rrrr�	FloatCeil�r�r�c@re)z&MathTests.testCeil.<locals>.TestNoCeilNrgrrrr�
TestNoCeil�rhr�r�g@E@�+cW�|SrVr��argsrrr�<lambda>��z$MathTests.testCeil.<locals>.<lambda>)
rvrwrL�ceilrrrK�typer4rTr�)rZr�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)
Nrr�r�rIi���r�r��@�@r����@)rrrL�copysignrvrwrzr{r}rMr~rNr!r^rrr�testCopysign�s0zMathTests.testCopysigncCs|�ttj�|jdt�tjd�dt�d�d�|�dt�d�d�|jdt�tjd�dt�d�d�|�dt�tj�d	�z|�t�t�t	���|�t�t�t
���Wntyr|�ttjt	�|�ttjt
�Ynw|�t�t�t���dS)
Nz
cos(-pi/2)rArr�r&zcos(0)z	cos(pi/2)zcos(pi)ru)
rvrwrL�cosrorp�ulpr}rMrzr{ryr~r^rrr�testCos�s&$�zMathTests.testCos�win32)�ARM�ARM64zEWindows 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)**2rAru)rvrwrL�coshrorrrzr{r}rMr~r^rrr�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)rAg�V@zdegrees(-pi/4)r�g�F�z
degrees(0)r)rvrwrL�degreesrorpr^rrr�testDegrees��
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)rurzexp(0)rzexp(1)rI�@B)
rvrwrLr>rorqrrrzr{r}rMr~�
OverflowErrorr^rrr�testExp�szMathTests.testExpcCsN|�ttj�|�dt�d�d�|�dt�d�d�|�dt�d�d�dS)Nzfabs(-1)rurzfabs(0)rzfabs(1))rvrwrL�fabsror^rrr�testFabs�szMathTests.testFabscCs�|�t�d�d�d}tdd�D]}||9}|�t�|�|�|�t�|�t|��q|�ttjd�|�ttjdd�dS)Nrr��ru�
�d)rrrL�	factorialrr rvry)rZ�totalrrrr�
testFactorial�szMathTests.testFactorialcCs�|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjt�d��|�ttjt�d��|�ttjd�dS)N�@g������@r��}Ô%�I���5z5.2)rvrwrLr��decimal�Decimalr^rrr�testFactorialNonIntegers�sz"MathTests.testFactorialNonIntegerscCs(|�ttjdd�|�ttjd�dS)Nr�r��}Ô%�I�T)rvr�rLr�rwr^rrr�testFactorialHugeInputssz!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)Nr�rr�rr�r�rur�r����c@r�)z&MathTests.testFloor.<locals>.TestFloorcSr�r�rr^rrr�	__floor__r�z0MathTests.testFloor.<locals>.TestFloor.__floor__N�rarbrcr�rrrr�	TestFloorr�r�c@r�)z'MathTests.testFloor.<locals>.FloatFloorcSr�r�rr^rrrr�r�z1MathTests.testFloor.<locals>.FloatFloor.__floor__Nr�rrrr�
FloatFloorr�r�c@re)z(MathTests.testFloor.<locals>.TestNoFloorNrgrrrr�TestNoFloorrhr�r�g33333�D@�)cWr�rVrr�rrrr�$r�z%MathTests.testFloor.<locals>.<lambda>)
rvrwrL�floorrrrKr�r4rTr�)rZr�r�r�r�rrr�	testFloor	s&
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�rrIz
fmod(10, 0.5)r�z
fmod(10, 1.5)r�r�zfmod(-10, 1)���r�zfmod(-10, 0.5)zfmod(-10, 1.5)r�r���)rvrwrL�fmodror}rMr~ryrzr{rrr^rrr�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)NcsF||\}}\}}t||�tks||kr!��d|||f�dSdS�Nz%s returned %r, expected %r�r!r|rm)rn�resultr#�mantr>�emant�eexpr^rr�	testfrexpAs
��z&MathTests.testFrexp.<locals>.testfrexpz	frexp(-1)ru)r�rzfrexp(0)r�rrzfrexp(1)r)r�rzfrexp(2)rA)r�rA)
rvrwrL�frexprrrzr{r}rMr~)rZr�rr^r�	testFrexp>szMathTests.testFrexpz2fsum is not exact on machines with double roundingcs.ddlm}|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]9\}\}}zt	�
|�}Wn%ty�|�d#|||f�Ynt
y�|�d$|||f�Ynw|�||�q�dd%lm}m}	m}
td"�D]7}gd&�d'}d}td(�D]}|	d|��d)|}
||
7}|�|
�q�|
|�||�}|�||�t	�
|��q�dS)*Nr)�
float_infocs�d\}}|D]-}t�|�\}}tt�|���|�}}||kr)|||K}|}n|||K}||7}qtttt|���d��|�}|dkrgd|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�rArrr�)	rLr�rK�ldexp�max�len�binr!�bool)�iterable�tmant�texprr�r>�tail�h)�etiny�mant_digrr�msumcs
"(z MathTests.testFsum.<locals>.msumrI)r�r�r��0��.�++g�d~�QJr�g�d~�Q�r�)�@Cr�g��g������?C)r�r���9g@C)g@Cr�r�g@C)g������?Cr�g�<g������?CcSsg|]}d|�qS�r�r��.0rrrr�
<listcomp>��z&MathTests.testFsum.<locals>.<listcomp>ri�z0x1.df11f45f4e61ap+2cSsg|]}d||�qS)r�rr�rrrr���z-0x1.62a2af1bd3624p-1)r	r�g��ؗ�Ҝ<g��7y�AC)g��7y�ACg�������?g��7y�A�g�������cSs,g|]}d|d|dd|d�qS)r��2�4rr�rrrr��s,����i�rAg�z0x1.5555555555555p+970cSsg|]}d|�qS)g333333�?r�r�rrrrr��r�cs g|]}�|d�|�qS�rrr)�termsrrr��s 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_exprr4�fromhex�append�	enumeraterL�fsumr�rmryrrrrr)rZr�r��test_valuesr�valsr#�actualrrr�j�s�vr)r�r�rr�testFsumPsn





��

��� �
�
���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]Z}||}||}|�|||�|�|�|||�|�|�|||�|�|�|||�|�|�|||�|�|�|||�|�|�|||�|�|�|||�|�ql|�|�d�|�|d�d�|�|d
�d�|�|ddd�d�|�|ddd�d�|�t|d�|�t|dd�|�t|dd�|�t|ddd�|�|td�td��d	�dS)Nrrrur�����x�T����� j9W P)�}� "o�`T"-� l�8P9�cC�/�[�N
S�9�b�Xl	9@{�wM�2�75�k )��	lZ��'^%#�>�;�*Q!/61^�f��^@�U@)rL�gcdrrrvrwri)rZr%r�y�c�a�brrr�testGcd�sN��zMathTests.testGcdcCs�ddlm}ddlm}tj}tjtjt�d�t�	d�t�
d�f}tt|�d�D]}|�
||d|��t�tdd	�|d|�D����q)|�|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�n1s�wY|�t��|ddd�Wd�n1s�wYdtjjd}|�ttf��
|d|�Wd�n	1�swY|�|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]}|�t�||g|�|t�|����q�td�D]}	t d|	}
|�t�d |
d|
�d|
��q�dS)!Nr�r���Fractionr��@g������@rcss�|]}|dVqdS)rANr)r�rrrr�	<genexpr>�s�z&MathTests.testHypot.<locals>.<genexpr>g(@r��*@rrH�
rr�rI�%��%@r�r�r�r��r皙�����?�string皙����@r�r�r�r�)!r�r��	fractionsr-rL�hypotrqrp�sqrt�gamma�sinrr��assertAlmostEqual�sumrrr�r�rvrwr
r��
max_10_expryr�rzr~r{r}rM�	FLOAT_MAX�isclose�	FLOAT_MIN)rZr�r-r9r�r�int_too_big_for_float�	fourthmaxrr>�scalerrr�	testHypot�sx$�$,�

����
�$�zMathTests.testHypotz7hypot() loses accuracy on machines with double roundingc	
Cs�tj}tj}tjdd�}dD]U\}}t�|�}t�|�}|j||||d��6t�|��t||�d||�d�	��}Wd�n1sFwY|�
|||�|�Wd�n1s^wYqdS)Ni�)�prec))z0x1.10e89518dca48p+29z0x1.1970f7565b7efp+30)z0x1.10106eb4b44a2p+29z0x1.ef0596cdc97f8p+29)z0x1.459c058e20bb7p+30z0x1.993ca009b9178p+29)z0x1.378371ae67c0cp+30z0x1.fbe6619854b4cp+29)z0x1.f4cd0574fb97ap+29z0x1.50fe31669340ep+30)z0x1.494b2cdd3d446p+29z0x1.212a5367b4c7cp+29)z0x1.f84e649f1e46dp+29z0x1.1fa56bef8eec4p+30)z0x1.2e817edd3d6fap+30z0x1.eb0814f1e9602p+29)z0x1.0d3a6e3d04245p+29z0x1.32a62fea52352p+30)z0x1.888e19611bfc5p+29z0x1.52b8e70b24353p+29)z0x1.538816d48a13fp+29z0x1.7967c5ca43e16p+29)z0x1.57b47b7234530p+29z0x1.74e2c7040e772p+29)z0x1.821b685e9b168p+30z0x1.677dc1c1e3dc6p+29)z0x1.9e8247f67097bp+29z0x1.24bd2dc4f4baep+29)z0x1.b73b59e0cb5f9p+29z0x1.da899ab784a97p+28)z0x1.94a8d2842a7cfp+30z0x1.326a51d4d8d8ap+30)z0x1.e930b9cd99035p+29z0x1.5a1030e18dff9p+30)z0x1.1592bbb0e4690p+29z0x1.a9c337b33fb9ap+29)z0x1.1243a50751fd4p+29z0x1.a5a10175622d9p+29)z0x1.57a8596e74722p+30z0x1.42d1af9d04da9p+30)z0x1.ee7dbd9565899p+29z0x1.7ab4d6fc6e4b4p+29)z0x1.5c6bfbec5c4dcp+30z0x1.02511184b4970p+30)z0x1.59dcebba995cap+30z0x1.50ca7e7c38854p+29)z0x1.768cdd94cf5aap+29z0x1.9cfdc5571d38ep+29)z0x1.dcf137d60262ep+29z0x1.1101621990b3ep+30)z0x1.3a2d006e288b0p+30z0x1.e9a240914326cp+29)z0x1.62a32f7f53c61p+29z0x1.47eb6cd72684fp+29)z0x1.d3bcb60748ef2p+29z0x1.3f13c4056312cp+30)z0x1.282bdb82f17f3p+30z0x1.640ba4c4eed3ap+30)z0x1.89d8c423ea0c6p+29z0x1.d35dcfe902bc3p+29)�hx�hyrr&rA)rLr9r�r��Contextr4r�subTest�localcontextr:rr)	rZr9r��high_precisionrHrIrr&�zrrr�testHypotAccuracy&s
%
"����zMathTests.testHypotAccuracycCsddlm}ddlm}tj}tj}|�|dd�d�|�|dd�d�td	�D]4}td
�D]-}t	dd�t|�D��}t	d
d�t|�D��}|�
|||�|tdd�t||�D����q.q(|�|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�n	1�s-wY|�t��|d�Wd�n	1�sGwY|�t��|dd(d*�Wd�n	1�scwY|�t��
|dd�Wd�n	1�s~wY|�t��
|d+d�Wd�n	1�s�wY|�t��
|d,d-�Wd�n	1�s�wY|�t��
|dd.�Wd�n	1�s�wY|�t��
|d/d0�Wd�n	1�s�wYd1tjjd
}
|�ttf��|d|
fd2�Wd�n	1�swY|�ttf��|d2d|
f�Wd�n	1�s0wYtd3�D]}t��t��}}|�||f|f�t||���q9td4d5dd6ttg}tj|d7d8�D]@}tj|d7d8�D]5}d9d:�t||�D�}tttj|���r�|�|||�t��qntttj |���r�|�!t� |||����qn�qet"d;}
td�D].}|
f|}d"|}|�!t�#|||�|
t�|���|�!t�#|||�|
t�|����q�td�D]+}t$d|}d<|d7|f}d=}|�t�||�d
|�|�t�||�d
|��q�dS)>Nrr+r,)r�r�r�)r�r�r�r�)rrAr�)r�rAru�	rHcs��|]	}t�dd�VqdS����rHN�r�uniform�r��krrrr/t��z%MathTests.testDist.<locals>.<genexpr>csrQrRrTrVrrrr/urXcss �|]\}}||dVqdS)r�Nr�r��px�qxrrrr/xs�)g,@r�)r�r�r0)�r)rA���r1r\rrAr]r)TTFTF)TFTTFr�)g�*@g)@g
�rIrr�)r�)rI)r�r�r�)rrr)r�r�r�c@re)zMathTests.testDist.<locals>.TNrgrrrr�T�rhr^)r�rHr")�p�q)r�rP)r5r6r7)rrAr�r�)rHr"r)r�rHr"r�abc�xyzr�)rAr��r2r�r3r�)�repeatcSsg|]\}}||�qSrrrYrrrr��r�z&MathTests.testDist.<locals>.<listcomp>r�r�)rIrI)%r�r�r8r-rL�distr:rrr�tupler=r>�zip�iterr�rvrwryr
r�r?r�rr!r{rzr~�	itertools�product�any�maprNrMr}r@rArB)rZ�D�Frfr:rrr_r`r^rC�values�diffsrDrr>rErrr�testDistes���	".,���������
���������"��

"&�zMathTests.testDistcCsD|�t��t�ddggd��Wd�dS1swYdS)NrrA)r�r�rH)rvryrLrfr^rrr�test_math_dist_leak�s"�zMathTests.test_math_dist_leakc
Cs.ttd��ttdd��dd�tdd�D�dd	d
dg}|D]9}|j|d��)t�|�}|�t|�t�|�|||�|�	||d
|d
�Wd�n1sUwYq!|�
t��
t�d�Wd�n1spwYt�d�}|�t|�t�|�|d
�t�d�}|�t|�t�|�|d�Gdd�dt
�}t�|d��}|�t|�t�|�|d�|�
t��t�|d��Wd�n1s�wYddt�d�dddg}|D]3}|j|d��"|�
t��
t�|�Wd�n1s�wYWd�n	1�swYq�dS)Nr�iX>i(FcSs(g|]}tdd�D]}d||�q	qS)i����(rA)r)r�rqrrrrr��s(z'MathTests.testIsqrt.<locals>.<listcomp>�<r	r�i'r�i�rWrruTFrc@rS)z(MathTests.testIsqrt.<locals>.IntegerLikecSrUrVrWrYrrrr[�r\z1MathTests.testIsqrt.<locals>.IntegerLike.__init__cSr]rVrWr^rrrrj�r`z2MathTests.testIsqrt.<locals>.IntegerLike.__index__Nrkrrrr�IntegerLike�rdrvi�r����r.za stringz3.5y@gY@r�)�listrrKrL�isqrt�assertIsr�rK�assertLessEqual�
assertLessrvryrr�objectr�r�rw)rZrrXrrv�
bad_valuesrrr�	testIsqrt�sX
����
���

�������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]`}||}||}|||}|�|||�|�|�|||�|�|�|||�|�|�|||�|�|�|||�|�|�|||�|�|�|||�|�|�|||�|�ql|�|�d�|�|d�d�|�|d�d�|�|dd	d�d�|�|ddd	�d�|�t|d�|�t|dd	�|�t|dd�|�t|ddd�|�|td�td	��d
�dS)NrrrurrriYrriHrrrl ,�`aUx�-�xB�:Vn
Ldbl�m�e%Y%l};T^�	)r l�|/Kr2r!i�7r#r$)rL�lcmrrrvrwri)rZr�rr&r'r(r)�drrr�test_lcmsP��zMathTests.test_lcmc	Cs6|�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]�}|�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|���q�dS)Nz
ldexp(0,1)rrz
ldexp(1,1)rAzldexp(1,-1)rur�zldexp(-1,1)r�r�r�r�i���rIr��i+���i��ld(	� F�x:^Vr�rt)rvrwrLr�ror�rrrzr{r}rMr~�rZrrrr�	testLdexp<s8�zMathTests.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)rruzlog(1)rzlog(e)z	log(32,2)rrArHzlog(10**40, 10)r�rtzlog(10**40, 10**20)r�z
log(10**1000)r�gO�+��@r�)
rvrwrL�logrorqryr{rrrzr}rMr~r^rrr�testLog\s�zMathTests.testLogcCsh|�ttj�dddddfD]}|�t�|�t�t|���q|�ttjd�|�t�t�t�dS)NrA�Zi,ru)	rvrwrL�log1pr=r4ryrrrzr�rrr�	testLog1pls
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)NrrIrAr�r�r�i�g��@�g�@i�g@�@r�)
rvrwrL�log2rrryr{r}rMr~r^rrr�testLog2sszMathTests.testLog2r�cCs8dd�tdd�D�}dd�tdd�D�}|�||�dS)NcSsg|]}t�t�d|���qSr�)rLr�r�r�rrrr��sz+MathTests.testLog2Exact.<locals>.<listcomp>rr�cS�g|]}t|��qSr�r4r�rrrr��r�)rrr)rZrr#rrr�
testLog2Exact�szMathTests.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)皙�����?ruzlog10(1)rrz	log10(10)r�zlog10(10**1000)r�g@�@r�)
rvrwrL�log10roryr{rrr�rzr}rMr~r^rrr�	testLog10�szMathTests.testLog10cs���ttj��fdd�}|dt�d�d�|dt�d�d���t�t�d	tf���t�t�d
tf�t�t�}��t�	|d����t�	|d��dS)
NcsJ||\}}\}}t||�tkst||�r#��d|||f�dSdSr�r�)rnr�r#�v1�v2�e1�e2r^rr�testmodf�s
��z$MathTests.testModf.<locals>.testmodfz	modf(1.5)r�)r�r�z
modf(-1.5)r�)r�r�rIr�rr)
rvrwrL�modfrrrzr{r~r}rM)rZr��modf_nanrr^r�testModf�s
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)rAz	pow(2,-1)rur�r�rIr�r�r�r�g�r�r�r�g.�g�������gffffff�?r5��������?r�g��������g�������g�������gffffff��z	(-2.)**3.g �z	(-2.)**2.r�z	(-2.)**1.z	(-2.)**0.z
(-2.)**-0.z
(-2.)**-1.r�z
(-2.)**-2.g�?z
(-2.)**-3.g��)rvrwrL�powrorrrzr{r}rMr~ryr^rrr�testPow�s�zMathTests.testPowcCsr|�ttj�|�dt�d�tj�|�dt�d�tjd�|�dt�d�tjd�|�d	t�d
�d
�dS)Nzradians(180)�zradians(90)r�rAzradians(-45)i���r�z
radians(0)r)rvrwrL�radiansrorpr^rrr�testRadiansBr�zMathTests.testRadiansc	s�ddlm���fdd�}gd�}|D]D}�j|d��4|��\}}}t�|�}t�|�}t�|�}	||||	�t�||�}
��|
�	�|	�	��Wd�n1sRwYqt�d�}t
dd	�D]0}|dkriqb||}t
d
�D] }
|
|}t�||�}
||||
�t�||�}
||||
�qqqbtddd
dtt
fD]}��t�t|����t�|t��q�dD]}��t�|t
�|���t�|t�|�q�tddddt
fD]q}��t��t�t
|�Wd�n1s�wY��t��t�t|�Wd�n	1�swY��t��t�|d�Wd�n	1�s"wY��t��t�|d�Wd�n	1�s>wYq�dS)Nrr,cs��|��|��|�}}}��t|�t|d��|||}��|t|��t|�t|d�kr@��|dt|d��dSdS)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.
            rAN)r{r!rrrK)rr&�r�fx�fy�frr�r-rZrr�
validate_specMs�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�rIr�r�r�)r�r�rIr�r�)r8r-rKr3r4rrL�	remainderrr�hexrr~r{rz�assertIsNaNrvry)rZr��	testcasesr��x_hex�y_hex�expected_hexrr&r#r�tinyr�mrXrr�r�
testRemainderIs^;


��
�	������zMathTests.testRemaindercCs�|�ttj�|�dt�d�d�|�dt�tjd�d�|�dt�tjd�d�z|�t�t�t���|�t�t�t	���Wnt
y]|�t
tjt�|�t
tjt	�Ynw|�t�t�t���dS)Nzsin(0)rz	sin(pi/2)rArz
sin(-pi/2)ru)rvrwrLr<rorpr}rMrzr{ryr~r^rrr�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)**2rrAruzsinh(1)+sinh(-1))rvrwrL�sinhror�rrrzr{r}rMr~r^rrr�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)r�rAru)rvrwrLr:rorrrzryr{r}rMr~r^rrr�testSqrt�szMathTests.testSqrtcCs�|�ttj�|�dt�d�d�|�dt�tjd�d�|�dt�tjd�d�z|�t�t�t���|�t�t�t	���Wn|�t
tjt�|�t
tjt	�Y|�t�t�t���dS)Nztan(0)rz	tan(pi/4)r�rz
tan(-pi/4)ru)rvrwrL�tanrorpr}rMrzr{ryr~r^rrr�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)rrur�z	tanh(inf)z
tanh(-inf))rvrwrL�tanhror�rzr{r}rMr~r^rrr�testTanh�s�zMathTests.testTanhcCs8|�t�d�d�|�t�dt�d��t�dd��dS)Nr�r�)rrrLr�r�r^rrr�testTanhSigns
�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)Nrrur�r�g����?g�����g�!��rg-���?Y�i����c@r�)z'MathTests.test_trunc.<locals>.TestTrunccSr��N�rr^rrr�	__trunc__r�z1MathTests.test_trunc.<locals>.TestTrunc.__trunc__N�rarbrcr�rrrr�	TestTruncr�r�c@r�)z(MathTests.test_trunc.<locals>.FloatTrunccSr�r�rr^rrrr�r�z2MathTests.test_trunc.<locals>.FloatTrunc.__trunc__Nr�rrrr�
FloatTruncr�r�c@re)z)MathTests.test_trunc.<locals>.TestNoTruncNrgrrrr�TestNoTruncrhr�r�rAg�7@)	rrrL�truncr�rKr4rvrwrT)rZr�r�r�rrr�
test_truncs&zMathTests.test_trunccCs�|�t�d��|�t�d��|�t�d��|�t�d��|�t�td���|�t�td���|�t�td���dS)NrIr�r�r�rrr)r}rL�isfinite�assertFalser4r^rrr�testIsfinite$szMathTests.testIsfinitecCsx|�t�td���|�t�td���|�t�td�d��|�t�td���|�t�d��|�t�d��dS)Nrz-nanrrIr�)r}rLrMr4r�r^rrr�	testIsnan-szMathTests.testIsnancCs�|�t�td���|�t�td���|�t�d��|�t�d��|�t�td���|�t�d��|�t�d��dS)Nrrg�g�rrIr�)r}rLrNr4r�r^rrr�	testIsinf5szMathTests.testIsinfcCs|�t�tj��dSrV)r}rLrMrr^rrr�test_nan_constant>�zMathTests.test_nan_constantcCsJ|�t�tj��|�tjd�|�tjtd��|�tjtd��dS)NrIrr)r}rLrNr�
assertGreaterrrr4r^rrr�test_inf_constantBszMathTests.test_inf_constantzrequires verbose modecCs�zt�d�}Wn	|�d�Y|dkr|�d�zt�d�}Wn	ty*Ynw|�d�zt�d�}Wn
tyAYdSw|�d�dS)	Ni6e�z6underflowing exp() should not have raised an exceptionrz)underflowing exp() should have returned 0iʚ;z.overflowing exp() didn't trigger OverflowErrorr�z sqrt(-1) didn't raise ValueError)rLr>rmr�r:ry�rZrrrr�test_exceptionsNs$
�
�zMathTests.test_exceptionsc	Csddh}d}tjdkr&t��d}zttt|�d���}Wn	ty%Ynwd}g}tt	�D]s\}}}}	}
}}|	dks?|dkr@q.|dvrEq.|durR|dkrR||vrRq.t
t|�}
d	|vs_d
|vrbd}
nd|vrhd
}
z|
|�}Wntyyd}Ynty�d
}Ynwd\}}t
|
|||�}|dur�q.|�||||�}|�|�q.|r�|�dd�|��dSdS)N�tan0064�darwinr�.�{}: {}({!r}): {}rI)�rect�polar)r�rH�invalid�divide-by-zerory�overflowr��rHrIzFailures in test_testfile:
  �
  )r
�platform�mac_verrgrmrKr3ryrG�	test_file�getattrrLr�rRr"r
rm�join)rZ�
SKIP_ON_TIGER�osx_version�version_txtrP�failuresr:r;�ar�ai�er�eir?�funcr�r%r&rO�msgrrr�
test_testfilensT
�
�
��zMathTests.test_testfilec	Cs*d}g}tt�D]|\}}}}}tt|�}d|vsd|vrd}nd|vr%d}z||�}	Wnty6d}	Ynty@d}	Ynwd\}
}|dkrLd	}
n|d
krSd}n|dkrk|d
krk|dkrbd}
n	|dkrid}
nd}
t||	|
|�}|durwq|�||||�}
|�|
�q|r�|�	dd�
|��dSdS)Nr�r�r�ryr�r�r�r;rd�lgammagV瞯�<�erfcrIr�r��$@r�r�zFailures in test_mtestfile:
  r�)r@�math_testcasesr�rLryr�rRr"r
rmr�)rZrPr�r:r;r<r#r?r�r$r%r&rOr�rrr�test_mtestfile�sH
�
��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�n	1�s3wY|�|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)8NrrH)rrArai�r�i_7)rrAr�r�rHr)r�r�r�r�r�r#)rrAr�r�r�)r�r�r�r�rH)rr�rrr�)r�r�r�rrr�)r(r)r'��a�c��br��ab�abababababab)rrArrArrArrArrArrArd)rrrAr�r)rrrAr�)rrAr�rcSs|D]}||9}q|SrVr)r�r�elemrrr�_naive_prods
z(MathTests.test_prod.<locals>._naive_prodi'i���rui���r�cSr�rr��r�rrrrr�$r�z'MathTests.test_prod.<locals>.<listcomp>cSr�rr�r�rrrr�&r�cSr�rr�r�rrrr�(r�rrrrwr�)rrAr�r�rHr")rr�r�r�rHr"r�r�r"r)rL�prodrrrxrrir4rvrw�	bytearrayr�r�rKr�r�)rZr�rpr�r�rrr�	test_prod�s�  �



$$   �zMathTests.test_prodc	CsLtj}tj}td�D]}t|d�D]}|�|||�||�|||��qq
tdd�D]#}td|�D]}|�|||�||d|d�|||d|��q3q,tdd�D]}|�||d�d�|�||d�|�|�|||�||��qUtd�D]}|�||�||��|�||d�||��qy|�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��rH|�t|||�dD]\}}|�|||�d�|�
t|||��t��qJ|�|td�td��d�|�|td�td��d�td
�D]!}|�
t|td�t|���t�|�
t|td�t|���t��q�dS)Nr�rrrdr�r��1r��10r�rurAr�T��cpython�)TT)TF)FFrH)rL�permr�rrrrvrwr�r�ryr�check_impl_detailr�rzr�rKrfri)rZrr�rrWrrr�testPermFsb��4�"�zMathTests.testPermc
Cs�tj}tj}td�D] }t|d�D]}|�|||�||�||�|||��qq
tdd�D]!}td|�D]}|�|||�||d|d�||d|��q7q0td�D]}|�||d�d�|�|||�d�qVtdd�D]}|�||d�|�|�|||d�|�qptd�D]}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]\}}|�|||�d�|�
t|||��t��q�|�|td�td��d�|�|td�td��d�td
�D]!}|�
t|td�t|���t�|�
t|td�t|���t��q�dS)Nr�rrrAr�r�rr�rr�rur�TrrrH)rL�combr�rrrrvrwr�r�ryrrr�rzr�rKrfri)rZrr�rrWrrr�testComb�sn��0��""�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�CrIg�������Cg��g��������r�z0x1.fffffffffffffp-1z0x1.0000000000001p+0r�r�)rrrL�	nextafterrzr4r�assertEqualSignr
r��min�epsilonr�r�r~)rZ�smallest_subnormal�largest_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|d��|�t�|�t�|��Wd�n1s~wYq^dS)	Nr�l�lr�lg�@rIr4)
rrrLr�r
r�r
rr@r
rzr�rrKr�rrr�test_ulp�s$�����zMathTests.test_ulpc	CstGdd�d�}tjtjtjfD](}|�}|�t��
|d|�Wd�n1s)wY|�t|dd��qdS)Nc@r�)z$MathTests.test_issue39871.<locals>.FcSsd|_dddS)NTrr)�	convertedr^rrrr_sz.MathTests.test_issue39871.<locals>.F.__float__N)rarbrcr_rrrrror�roznot a numberrF)rLr�r�r�rvrwr�r�)rZror�r&rrr�test_issue39871s��zMathTests.test_issue39871cCs"t�|�s|�d�|��dSdS)NzExpected a NaN, got {!r}.)rLrMrmr"rYrrrr�#s
�zMathTests.assertIsNaNcCs,|�||�|�t�d|�t�d|��dS)zSimilar to assertEqual(), but compare also the sign with copysign().

        Function useful to compare signed zeros.
        r�N)rrrLr�)rZrr&rrrr's zMathTests.assertEqualSignNr�)Nrarbrcrortrr�r�r�r�r�r�r�rr�r��unittest�skipIfr
r��machiner�r�r�r�r�r�r�cpython_onlyr�r�r�r��HAVE_DOUBLE_ROUNDINGrr*rFrOrrrsrr�r�r�r�r��requires_mac_verr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��
skipUnlessrr�r�r�r�rr	rrrr�rrrrrrl�s�


		=!
!�




�^*K�<q5, 



	

	
		




8
B\@F
-
rlc@s�eZdZejZdd�Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS) �IsCloseTestscO�0|j|j||g|�Ri|��d||fd�dS)Nz%s and %s should be close!�r�)r}rA�rZr(r)r��kwargsrrr�
assertIsClose3�

�zIsCloseTests.assertIsClosecOr)Nz%s and %s should not be close!r)r�rArrrr�assertIsNotClose7r!zIsCloseTests.assertIsNotClosecO�,|D]\}}|j||g|�Ri|��qdSrV)r �rZ�examplesr�rr(r)rrr�assertAllClose;��zIsCloseTests.assertAllClosecOr#rV)r"r$rrr�assertAllNotClose?r'zIsCloseTests.assertAllNotClosecCs||�t��|jdddd�Wd�n1swY|�t��|jddddd�Wd�dS1s7wYdS)Nrg0��.�+���rel_tolr�g _�©r*r&)rvryr r^rrr�test_negative_tolerancesCs�"�z%IsCloseTests.test_negative_tolerancescCsgd�}|j|ddd�dS)N))r�r�)�N���@ir-)�;���r.)i90g��@)rIr�)�NFr/rIr+�r&)rZ�identical_examplesrrr�test_identicalJszIsCloseTests.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()rZ�eight_decimal_places_examplesrrr�test_eight_decimal_placesTsz&IsCloseTests.test_eight_decimal_placescCs(gd�}|j|dd�|j|dd�dS)N))r4rI)g��&�.�rI)gu�?j�/ʠrIr�r)r3r�)r(r&)rZ�near_zero_examplesrrr�test_near_zero\szIsCloseTests.test_near_zerocCs<|�tt�|jttdd�|�tt�|jttdd�dS)NrIr�)r rzr{r^rrr�test_identical_infinitefsz$IsCloseTests.test_identical_infinitecCsRttftdfdtfttfttfttftdfdtftdfdtfg
}|j|dd�dS)Nr�r�g������g�������?r�)r~rzr{r()rZ�not_close_examplesrrr�test_inf_ninf_nanms�zIsCloseTests.test_inf_ninf_nancCs0gd�}|j|dd�gd�}|j|dd�dS)N))r�r�)�333333�r=)�Y��n��r>rIr)))r�g�?)g�������?r�)gZb���tigTb���tir5)rZ�zero_tolerance_close_examples�!zero_tolerance_not_close_examplesrrr�test_zero_tolerance|sz IsCloseTests.test_zero_tolerancecCs|jddgdd�dS)N)rPr�)r�rPr�r)r0r^rrr�test_asymmetry�r�zIsCloseTests.test_asymmetrycCs(ddg}|j|dd�|j|dd�dS)N)����)i�[i�[r3r)r4r5)rZ�integer_examplesrrr�
test_integers�s
�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.0e20r3r)r4)r�r�r&r()rZr��decimal_examplesrrr�
test_decimals�s�zIsCloseTests.test_decimalscCsdddlm}|dd�d|d�f|d�|d�f|dd�|dd�fg}|j|dd	�|j|d
d	�dS)Nrr,rrDrCl �	(q�e�	r�r3r)r4)r8r-r&r()rZr-�fraction_examplesrrr�test_fractions�s�zIsCloseTests.test_fractionsN)rarbrcrLrAr r"r&r(r,r2r7r9r:r<rArBrFrHrJrrrrr0s"

rcCsNddlm}t��}|�t�t��|�t�t��|�|d��t|�dS)Nr)�DocFileSuitezieee754.txt)	�doctestrKr�	TestSuite�addTest�	makeSuiterlrr)rK�suiterrr�	test_main�srQr�)8�test.supportrrr�testrrrjr�rL�osr�rrr
r|r4r~rzr{r�r�r@rrBrr&rra�argv�file�__file__�path�dirname�curdir�test_dirr�r�r�rrrr r*r@rGrRrTrKrfr}ri�TestCaserlrrQrrrr�<module>sp&
-Q{
�

Youez - 2016 - github.com/yon3zu
LinuXploit