Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 3.146.105.252
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_math.cpython-310.pyc
o

abj�@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�7/usr/local/python-3.10/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�stopZ
numfactorsZmidrrrrQs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�innerZouter�irrr�py_factorial_s
*
rcCsHtt|�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_tolZ	ulp_errorZ	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)r+�
startswithr-r.r/)
r0r1r2r3r4r5r6Zarg_realZarg_imagr8Zexp_realZexp_imagr:rrr�parse_testfile�s"���"�r>��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 ({}))�
isinstancer/�int�math�isnan�isinfr%r)r r!r"r#�failure�fail_fmtZfail_msgrrr�result_check�s&
rHc@�eZdZdd�Zdd�ZdS)�	FloatLikecC�
||_dS�N��value��selfrNrrr�__init__��
zFloatLike.__init__cC�|jSrLrM�rPrrr�	__float__��zFloatLike.__float__N)�__name__�
__module__�__qualname__rQrUrrrrrJ��rJc@�eZdZdS)�IntSubclassN�rWrXrYrrrrr\��r\c@rI)�MyIndexablecCrKrLrMrOrrrrQ�rRzMyIndexable.__init__cCrSrLrMrTrrr�	__index__�rVzMyIndexable.__index__N�rWrXrYrQr`rrrrr_�rZr_c@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+e
dHdI��Z,e
e�-dJd�dKdL���Z.dMdN�Z/dOdP�Z0dQdR�Z1dSdT�Z2e
dUdV��Z3dWdX�Z4dYdZ�Z5d[d\�Z6d]d^�Z7d_d`�Z8e
dadb��Z9dcdd�Z:dedf�Z;dgdh�Z<didj�Z=e
dkdl��Z>e
dmdn��Z?e�@eAdo�dpdq��ZBe
drds��ZCe
dtdu��ZDdvdw�ZEdxdy�ZFdzd{�ZGe
d|d}��ZHe
d~d��ZId�d��ZJd�d��ZKd�d��ZLd�S)��	MathTestsr?r@cCs0t||||�}|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{}: {})rH�failr)rP�namer!r r"r#rFrrr�ftest�s	�zMathTests.ftestcCs8|�dtjd�|�dtjd�|�tjdtj�dS)N�pig-DT�!	@�egiW�
�@r<)rerCrfrg�assertEqual�taurTrrr�
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)rr<zacos(1)r)
�assertRaises�	TypeErrorrC�acosrerf�
ValueError�INF�NINF�eps�
assertTruerD�NANrTrrr�testAcosszMathTests.testAcoscCs�|�ttj�|�dt�d�d�|�dt�d�d�|�ttjd�|�ttjd�|�t�t�t�|�ttjt�|�	t�
t�t���dS)Nzacosh(1)rrzacosh(2)r<g5�qB�?rk)rlrmrC�acoshrerorhrprqrsrDrtrTrrr�	testAcosh
szMathTests.testAcoshcCs�|�ttj�|�dt�d�tjd�|�dt�d�d�|�dt�d�tjd�|�ttjt�|�ttjt�|�ttjdt	�|�ttjdt	�|�
t�t�t���dS)Nzasin(-1)rkr<zasin(0)rzasin(1)r)
rlrmrC�asinrerfrorprqrrrsrDrtrTrrr�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)rkg'�ya64�)rlrmrC�asinhrerhrprqrsrDrtrTrrr�	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)rk�zatan(0)rzatan(1)rz	atan(inf)r<z
atan(-inf))rlrmrC�atanrerfrprqrsrDrtrTrrr�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��rrk)rlrmrCr}re�atanhrorprqrsrDrtrTrrr�	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)rkrr<zatan2(-1, 1)rr|zatan2(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.))rlrmrC�atan2rerfrqrhrprsrDrtrTrrr�	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)Nrr��?��?r<r�r��rk���r@r�c@�eZdZdd�ZdS)z$MathTests.testCeil.<locals>.TestCeilcS�dS�N�*rrTrrr�__ceil__��z-MathTests.testCeil.<locals>.TestCeil.__ceil__N�rWrXrYr�rrrr�TestCeil��r�c@r�)z%MathTests.testCeil.<locals>.FloatCeilcSr�r�rrTrrrr��r�z.MathTests.testCeil.<locals>.FloatCeil.__ceil__Nr�rrrr�	FloatCeil�r�r�c@r[)z&MathTests.testCeil.<locals>.TestNoCeilNr]rrrr�
TestNoCeil�r^r�r�g@E@�+cW�|SrLr��argsrrr�<lambda>��z$MathTests.testCeil.<locals>.<lambda>)
rlrmrC�ceilrhrB�typer/rJr�)rPr�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�r@i���r�r��@�@r����@)rhrC�copysignrlrmrprqrsrDrtrErrTrrr�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)r<rr�r#zcos(0)z	cos(pi/2)zcos(pi)rk)
rlrmrC�cosrerf�ulprsrDrprqrortrTrrr�testCos�s&$�zMathTests.testCos�win32)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)**2r<rk)rlrmrC�coshrerhrprqrsrDrtrTrrr�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)r<g�V@zdegrees(-pi/4)r|g�F�z
degrees(0)r)rlrmrC�degreesrerfrTrrr�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)rkrzexp(0)rzexp(1)r@�@B)
rlrmrCr9rergrhrprqrsrDrt�
OverflowErrorrTrrr�testExp�szMathTests.testExpcCsN|�ttj�|�dt�d�d�|�dt�d�d�|�dt�d�d�dS)Nzfabs(-1)rkrzfabs(0)rzfabs(1))rlrmrC�fabsrerTrrr�testFabs�szMathTests.testFabscCs�|�t�d�d�d}tdd�D]}||9}|�t�|�|�|�t�|�t|��q|�ttjd�|�ttjdd�dS)Nrr��rk�
�d)rhrC�	factorialrrrlro)rP�totalrrrr�
testFactorial�szMathTests.testFactorialcCs�|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjt�d��|�ttjt�d��|�ttjd�dS)N�@g������@r��}Ô%�I���5z5.2)rlrmrCr��decimal�DecimalrTrrr�testFactorialNonIntegers�sz"MathTests.testFactorialNonIntegerscCs(|�ttjdd�|�ttjd�dS)Nr�r��}Ô%�I�T)rlr�rCr�rmrTrrr�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)Nrrr�rr�r�rkr�r����c@r�)z&MathTests.testFloor.<locals>.TestFloorcSr�r�rrTrrr�	__floor__r�z0MathTests.testFloor.<locals>.TestFloor.__floor__N�rWrXrYr�rrrr�	TestFloorr�r�c@r�)z'MathTests.testFloor.<locals>.FloatFloorcSr�r�rrTrrrr�r�z1MathTests.testFloor.<locals>.FloatFloor.__floor__Nr�rrrr�
FloatFloorr�r�c@r[)z(MathTests.testFloor.<locals>.TestNoFloorNr]rrrr�TestNoFloorr^r�r�g33333�D@�)cWr�rLrr�rrrr�$r�z%MathTests.testFloor.<locals>.<lambda>)
rlrmrC�floorrhrBr�r/rJr�)rPr�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�rr@z
fmod(10, 0.5)rz
fmod(10, 1.5)r�r�zfmod(-10, 1)���r�zfmod(-10, 0.5)zfmod(-10, 1.5)r�r���)rlrmrC�fmodrersrDrtrorprqrhrTrrr�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�rrrrc)rd�resultr �mantr9ZemantZeexprTrr�	testfrexpAs
��z&MathTests.testFrexp.<locals>.testfrexpz	frexp(-1)rk)r�rzfrexp(0)r�rrzfrexp(1)r)rrzfrexp(2)r<)rr<)
rlrmrC�frexprhrprqrsrDrt)rPr�rrTr�	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�r<rrr�)	rCr�rB�ldexp�max�len�binr�bool)�iterableZtmantZtexprr�r9�tail�h)�etiny�mant_digrr�msumcs
"(z MathTests.testFsum.<locals>.msumr@)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������?Crg�<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�r<g�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_exprr/�fromhex�append�	enumeraterC�fsumr�rcrorhr�r�r�)rPr�r��test_valuesrZvalsr �actualr�r�r��j�s�vr)r�r�r�r�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)Nrrrkr������x�T����� j9W P)�}� "o�`T"-� l�8P9�cC�/�[�N
S�9�b�Xl	9@{�wM�2�75�k )��	lZ��'^%#�>�;�*Q!/61^�f��^@�U@)rC�gcdrhrlrmr_)rPrr�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)r<Nr)r�rrrr�	<genexpr>�s�z&MathTests.testHypot.<locals>.<genexpr>g(@r��*@r
r?�
rr�r@�%��%@r�r�r�r�r皙�����?�string皙����@r�r�r�r|)!r�r��	fractionsrrC�hypotrgrf�sqrt�gamma�sinrr��assertAlmostEqual�sumrhr�r�rlrmr�r��
max_10_expror�rprtrqrsrD�	FLOAT_MAX�isclose�	FLOAT_MIN)rPr�rr(r�r�int_too_big_for_float�	fourthmaxrr9�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�)Zprec))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�hyrrr<)rCr(r�r�ZContextr/r��subTestZlocalcontextr)rh)	rPr(r�Zhigh_precisionr6r7rr�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)>Nrrr)r�r�r�)r�r�r�r�)rr<r�)r|r<rk�	r?cs��|]	}t�dd�VqdS����r?N�r��uniform�r��krrrrt��z%MathTests.testDist.<locals>.<genexpr>csr<r=r?rArrrrurCcss �|]\}}||dVqdS)r�Nr�r�ZpxZqxrrrrxs�)g,@r�)r�r�r)�r)r<���r rErr<rFr)TTFTF)TFTTFr�)g�*@g)@g
�r@rr�)r�)r@)r�r�r)rrr)r�rr�c@r[)zMathTests.testDist.<locals>.TNr]rrrr�T�r^rG)r|r?r)�p�q)r��r;)r$r%r&)rr<r�r|)r?rr�)r|r?rr��abcZxyzr�)r<r��r!r�r"r�)�repeatcSsg|]\}}||�qSrrrDrrrr��r�z&MathTests.testDist.<locals>.<listcomp>r�r|)r@r@)%r�r�r'rrC�distr)rhr�tupler,r-�zip�iterr�rlrmror�r�r.r�r�rrqrprt�	itertools�product�any�maprErDrsr/r0r1)rP�D�FrNr)rrrHrIrGr2�valuesZdiffsr3rr9r4rrr�testDistes���	".,���������
���������"��

"&�zMathTests.testDistc
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����(r<)r)r�rgrrrrr��s(z'MathTests.testIsqrt.<locals>.<listcomp>�<r�r�i'r�i�rMrrkTFrc@rI)z(MathTests.testIsqrt.<locals>.IntegerLikecSrKrLrMrOrrrrQ�rRz1MathTests.testIsqrt.<locals>.IntegerLike.__init__cSrSrLrMrTrrrr`�rVz2MathTests.testIsqrt.<locals>.IntegerLike.__index__Nrarrrr�IntegerLike�rZr\i�r����rza stringz3.5y@gY@r�)�listrr8rC�isqrt�assertIsr�rB�assertLessEqualZ
assertLessrlrorh�objectr�r�rm)rPrrNrr\Z
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)Nrrrkr�rriYrr	iHrrr
l ,�`aUx�-�xB�:Vn
Ldbl�m�e%Y%l};T^�	)rl�|/Kr2ri�7rr)rC�lcmrhrlrmr_)rPrdrrrrr�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)r<zldexp(1,-1)rkrzldexp(-1,1)r�r�r�r�i���r@r��i+���i��ld(	� F�x:^Vr�rZ)rlrmrCr�rer�rhrprqrsrDrt�rPrrrr�	testLdexp7s8�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)rrkzlog(1)rzlog(e)z	log(32,2)rr<r?zlog(10**40, 10)r�rZzlog(10**40, 10**20)rhz
log(10**1000)r�gO�+��@r�)
rlrmrC�logrergrorqrhrprsrDrtrTrrr�testLogWs�zMathTests.testLogcCsh|�ttj�dddddfD]}|�t�|�t�t|���q|�ttjd�|�t�t�t�dS)Nr<�Zi,rk)	rlrmrC�log1pr,r/rorhrprirrr�	testLog1pgs
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@r<r�r|r�i�g��@�g�@i�g@�@r�)
rlrmrC�log2rhrorqrsrDrtrTrrr�testLog2nszMathTests.testLog2r�cCs8dd�tdd�D�}dd�tdd�D�}|�||�dS)NcSsg|]}t�t�d|���qSr�)rCrqr�r�rrrr��sz+MathTests.testLog2Exact.<locals>.<listcomp>r�rpcS�g|]}t|��qSr�r/r�rrrr��r�)rrh)rPrr 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)皙�����?rkzlog10(1)rrz	log10(10)r�zlog10(10**1000)r�g@�@r�)
rlrmrC�log10rerorqrhrkrprsrDrtrTrrr�	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�)rdr�r Zv1Zv2�e1�e2rTrr�testmodf�s
��z$MathTests.testModf.<locals>.testmodfz	modf(1.5)r�)rr�z
modf(-1.5)r�)r�r�r@r�rr)
rlrmrC�modfrhrprqrtrsrD)rPr{Zmodf_nanrrTr�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)r<z	pow(2,-1)rkrr�r@r�r�r�r�g�r�r�r�g.�g�������gffffff�?r$��������?rvg��������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��)rlrmrC�powrerhrprqrsrDrtrorTrrr�testPow�s�zMathTests.testPowcCsr|�ttj�|�dt�d�tj�|�dt�d�tjd�|�dt�d�tjd�|�d	t�d
�d
�dS)Nzradians(180)�zradians(90)rmr<zradians(-45)i���r|z
radians(0)r)rlrmrC�radiansrerfrTrrr�testRadians=r�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)Nrrcs��|��|��|�}}}��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.
            r<N)rarrhrB)rr�rZfxZfy�frr�rrPrr�
validate_specHs�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@r�r�r�)r�r�r@r�r�)r'rr8r.r/r�rC�	remainderrh�hexrrtrqrp�assertIsNaNrlro)rPr�Z	testcasesr�Zx_hexZy_hexZexpected_hexrrr rZtinyr�mrNrr�r�
testRemainderDs^;


��
�	������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)r<rz
sin(-pi/2)rk)rlrmrCr+rerfrsrDrprqrortrTrrr�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)**2rr<rkzsinh(1)+sinh(-1))rlrmrC�sinhrer�rhrprqrsrDrtrTrrr�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|r<rk)rlrmrCr)rerhrprorqrsrDrtrTrrr�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)rk)rlrmrC�tanrerfrsrDrprqrortrTrrr�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)rrkr�z	tanh(inf)z
tanh(-inf))rlrmrC�tanhrer�rprqrsrDrtrTrrr�testTanh�s�zMathTests.testTanhcCs8|�t�d�d�|�t�dt�d��t�dd��dS)Nr�r�)rhrCr�r�rTrrr�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)Nrrkr�r�g����?g�����g�!��rg-���?Y�i����c@r�)z'MathTests.test_trunc.<locals>.TestTrunccSr��N�rrTrrr�	__trunc__r�z1MathTests.test_trunc.<locals>.TestTrunc.__trunc__N�rWrXrYr�rrrr�	TestTruncr�r�c@r�)z(MathTests.test_trunc.<locals>.FloatTrunccSr�r�rrTrrrr�r�z2MathTests.test_trunc.<locals>.FloatTrunc.__trunc__Nr�rrrr�
FloatTruncr�r�c@r[)z)MathTests.test_trunc.<locals>.TestNoTruncNr]rrrr�TestNoTruncr^r�r�r<g�7@)	rhrC�truncr�rBr/rlrmrJ)rPr�r�r�rrr�
test_truncs&zMathTests.test_trunccCs�|�t�d��|�t�d��|�t�d��|�t�d��|�t�td���|�t�td���|�t�td���dS)Nr@r�r�r�rrr)rsrC�isfinite�assertFalser/rTrrr�testIsfiniteszMathTests.testIsfinitecCsx|�t�td���|�t�td���|�t�td�d��|�t�td���|�t�d��|�t�d��dS)Nrz-nanrr@r�)rsrCrDr/r�rTrrr�	testIsnan(szMathTests.testIsnancCs�|�t�td���|�t�td���|�t�d��|�t�d��|�t�td���|�t�d��|�t�d��dS)Nrrg�g�rr@r�)rsrCrEr/r�rTrrr�	testIsinf0szMathTests.testIsinfcCs|�t�tj��dSrL)rsrCrDrrTrrr�test_nan_constant9�zMathTests.test_nan_constantcCsJ|�t�tj��|�tjd�|�tjtd��|�tjtd��dS)Nr@rr)rsrCrErZ
assertGreaterrhr/rTrrr�test_inf_constant=szMathTests.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)rCr9rcr�r)ro�rPrrrr�test_exceptionsIs$
�
�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)NZtan0064�darwinr�.�{}: {}({!r}): {}r@)ZrectZpolar)r�r?�invalid�divide-by-zeroro�overflowr��r?r@zFailures in test_testfile:
  �
  )r��platformZmac_verrOrUrBr.ror>�	test_file�getattrrCr�rHrr�rc�join)rPZ
SKIP_ON_TIGERZosx_versionZversion_txtrG�failuresr5r6�arZaiZer�eir:�funcr�r"r#rF�msgrrr�
test_testfileisT
�
�
��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�ror�r�r�r*rL�lgammagV瞯�<�erfcr@r�r��$@r�r�zFailures in test_mtestfile:
  r�)r;�math_testcasesr�rCror�rHrr�rcr�)rPrGr�r5r6r7r r:r�r!r"r#rFr�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)8Nrr?)rr<rJi�r�i_7)rr<r�r|r?r)r�r�r�r�r�r)rr<r�r�r�)r�r�r�r|r?)rr�rrr�)r�r�r�rrr�)rrr��a�c��br��abZabababababab)rr<rr<rr<rr<rr<rr<rL)rrr<r�r)rrr<r�)rr<r�rcSs|D]}||9}q|SrLr)r�r�elemrrr�_naive_prods
z(MathTests.test_prod.<locals>._naive_prodi'i���rki���r�cSrsrrt�r�rrrrr�r�z'MathTests.test_prod.<locals>.<listcomp>cSrsrrtr�rrrr�!r�cSrsrrtr�rrrr�#r�rrrr]r|)rr<r�r|r?r)rr�r�r|r?rr�r�rr�)rC�prodrhr^rrQr/rlrm�	bytearrayr�r�rBr�r�)rPr�rXr�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�rrrLr�r��1r��10r�rkr<r�T�Zcpython�)TT)TF)FFr?)rC�permr�rrhrlrmr�r�ror�check_impl_detailr�r`r�rBr\r_)rPr�r�rrBrrr�testPermAsb��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�rrr<r�r�r�r�r�r�rkr�Tr�r�r?)rC�combr�rrhrlrmr�r�rorr�r�r`r�rBr\r_)rPr�r�rrBrrr�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�Cr@g�������Cg��g��������r�z0x1.fffffffffffffp-1z0x1.0000000000001p+0r�r�)rhrC�	nextafterrpr/r��assertEqualSignr�r��min�epsilonr�r�rt)rPZsmallest_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|d��|�t�|�t�|��Wd�n1s~wYq^dS)	Nr�l�lr�lg�@r@r#)
rhrCr�r�r�r�r�r/r�rpr�rr8r�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)�	convertedrTrrrrUsz.MathTests.test_issue39871.<locals>.F.__float__N)rWrXrYrUrrrrrWr�rWznot a numberr�F)rCr�r�r�rlrmr�r�)rPrWr�rrrr�test_issue39871s��zMathTests.test_issue39871cCs"t�|�s|�d�|��dSdS)NzExpected a NaN, got {!r}.)rCrDrcrrOrrrr�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)rhrCr�)rPrrrrrr�"s zMathTests.assertEqualSignNr�)MrWrXrYrerjrurwryr{r~r�r�r�rr�r��unittestZskipIfr�r��machiner�r�r�r�r�r�rZcpython_onlyr�r�r�r��HAVE_DOUBLE_ROUNDINGrrr5r:rYrcrfrjrlrorrZrequires_mac_verrurxr}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�Z
skipUnlessrr�r�r�r�r�r�r�r�r�r�r�rrrrrb�s�


		=!
!�




�^*K�<q5, 



	

	
		




8
B\@F
-
rbc@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�)rsr0�rPrrr��kwargsrrr�
assertIsClose.�

�zIsCloseTests.assertIsClosecOr�)Nz%s and %s should not be close!r�)r�r0r�rrr�assertIsNotClose2r�zIsCloseTests.assertIsNotClosecO�,|D]\}}|j||g|�Ri|��qdSrL)r��rPZexamplesr�r�rrrrr�assertAllClose6��zIsCloseTests.assertAllClosecOr�rL)r�r�rrr�assertAllNotClose:r�zIsCloseTests.assertAllNotClosecCs||�t��|jdddd�Wd�n1swY|�t��|jddddd�Wd�dS1s7wYdS)Nrg0��.�+���rel_tolr�g _�©r�r#)rlror�rTrrr�test_negative_tolerances>s�"�z%IsCloseTests.test_negative_tolerancescCsgd�}|j|ddd�dS)N))r�r�)�N���@ir�)�;���r�)i90g��@)r@r�)�NFr�r@r��r�)rPZidentical_examplesrrr�test_identicalEszIsCloseTests.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�)rPZeight_decimal_places_examplesrrr�test_eight_decimal_placesOsz&IsCloseTests.test_eight_decimal_placescCs(gd�}|j|dd�|j|dd�dS)N))r�r@)g��&�.�r@)gu�?j�/ʠr@r~r�r�r�)r�r�)rPZnear_zero_examplesrrr�test_near_zeroWszIsCloseTests.test_near_zerocCs<|�tt�|jttdd�|�tt�|jttdd�dS)Nr@r�)r�rprqrTrrr�test_identical_infiniteasz$IsCloseTests.test_identical_infinitecCsRttftdfdtfttfttfttftdfdtftdfdtfg
}|j|dd�dS)Nr�r�g������g�������?r�)rtrprqr�)rPZnot_close_examplesrrr�test_inf_ninf_nanhs�zIsCloseTests.test_inf_ninf_nancCs0gd�}|j|dd�gd�}|j|dd�dS)N))r�r�)�333333�r)�Y��n��rr@r�))r�g�?)g�������?r�)gZb���tigTb���tir�)rPZzero_tolerance_close_examplesZ!zero_tolerance_not_close_examplesrrr�test_zero_tolerancewsz IsCloseTests.test_zero_tolerancecCs|jddgdd�dS)N)r;r�)r�r;rvr�r�rTrrr�test_asymmetry�r�zIsCloseTests.test_asymmetrycCs(ddg}|j|dd�|j|dd�dS)N)����)i�[i�[r�r�r�r�)rPZinteger_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)Nrrz
1.00000001z1.0z1.00000001e-20z1.0e-20z1.00000001e-100z1.0e-100z
1.00000001e20z1.0e20r�r�r�)r�r�r�r�)rPr�Zdecimal_examplesrrr�
test_decimals�s�zIsCloseTests.test_decimalscCsdddlm}|dd�d|d�f|d�|d�f|dd�|dd�fg}|j|dd	�|j|d
d	�dS)Nrrrrrl �	(q�e�	rhr�r�r�)r'rr�r�)rPrZfraction_examplesrrr�test_fractions�s�zIsCloseTests.test_fractionsN)rWrXrYrCr0r�r�r�r�r�r�r�r�r�r�rrrrrrrrrr�+s"

r�cCsNddlm}t��}|�t�t��|�t�t��|�|d��t|�dS)Nr)�DocFileSuitezieee754.txt)	�doctestr	r�Z	TestSuiteZaddTestZ	makeSuiterbr�r)r	Zsuiterrr�	test_main�srr�)8Ztest.supportrrr�testrr�rRr�rC�osr�r�rr�rrr/rtrprqr�r�r/r�r1rrr�rW�argv�file�__file__�path�dirname�curdirZtest_dirr�r�r�rrrrr%r;r>rHrJrBr\rbr_ZTestCaserbr�rrrrr�<module>sp&
-L{
�
© 2025 GrazzMean