a
    ze]                    @   s  d dl mZmZmZ d dlmZ d dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlZd dlZdZedZedZedZejjZejjZd\ZZee d	kZed
krejd  ZneZe
j !epe
j"Z#e
j $e#dZ%e
j $e#dZ&dd Z'dd Z(dd Z)dd Z*dd Z+dd Z,dd Z-d+ddZ.G dd  d Z/G d!d" d"e0Z1G d#d$ d$e2Z3G d%d& d&ej4Z5G d'd( d(ej4Z6d)d* Z7ed
kre7  dS ),    )run_unittestverboserequires_IEEE_754)supportNgh㈵>naninf-inf) 7yACg):@g7yAC__main__zmath_testcases.txtzcmath_testcases.txtc                 C   s.   t dt d| d }|dk r*|d  }|S )Nz<qz<dr   l            )structunpackpack)xn r   $/usr/lib/python3.9/test/test_math.pyto_ulps'   s    
r   c                 C   s   | rdt | | d @  S dS )N   r   )count_set_bits)r   r   r   r   r   M   s    r   c                 C   sD   ||  d? }|sdS |dkr | S | | dB }t | |t || S d S Nr   )partial_product)startstopZ
numfactorsZmidr   r   r   r   Q   s    r   c                 C   s`   d }}t t|  D ]6}|t| |d ? d dB | |? d dB 9 }||9 }q|| t|  > S r   )reversedrange
bit_lengthr   r   )r   innerZouterir   r   r   py_factorial_   s
    *
r   c                 C   sL   t t| t| }t | | }||ks0||kr4d S d}|||||S d S )NzAerror = {:.3g} ({:d} ulps); permitted error = {:.3g} or {:d} ulps)absr   format)expectedgotulp_tolabs_tolZ	ulp_errorZ	abs_errorfmtr   r   r   ulp_abs_checkj   s    r&   c                 c   s   t | }|D ]x}d|v r,|d |d }| s6q|d\}}| \}}}| }|d }	|dd  }
||t|t|	|
fV  qW d    n1 s0    Y  d S )N--->r   r   )openindexstripsplitfloat)fnamefplinelhsrhsidfnarg
rhs_piecesexpflagsr   r   r   parse_mtestfile|   s    	
r9   c              	   c   s   t | }|D ]}|ds| s&q|d\}}| \}}}}| }	|	d |	d  }
}|	dd  }||t|t|t|
t||fV  qW d    n1 s0    Y  d S )Nr'   r(   r   r      )r)   
startswithr+   r,   r-   )r.   r/   r0   r1   r2   r3   r4   Zarg_realZarg_imagr6   Zexp_realZexp_imagr8   r   r   r   parse_testfile   s    
r<              c                 C   s   || krd S d}t | tr.t |tr.t|}nt |trJt | trJt| } t | trt |trt| rxt|rxd }n$t| st|rnt| |||}|d urd}|| |}|d|7 }|S d S d S )Nz	not equalzexpected {!r}, got {!r}z ({}))
isinstancer-   intmathisnanisinfr&   r    )r!   r"   r#   r$   failurefail_fmtZfail_msgr   r   r   result_check   s&    
rF   c                   @   s   e Zd Zdd Zdd ZdS )	FloatLikec                 C   s
   || _ d S NvalueselfrJ   r   r   r   __init__   s    zFloatLike.__init__c                 C   s   | j S rH   rI   rL   r   r   r   	__float__   s    zFloatLike.__float__N)__name__
__module____qualname__rM   rO   r   r   r   r   rG      s   rG   c                   @   s   e Zd ZdS )IntSubclassNrP   rQ   rR   r   r   r   r   rS      s   rS   c                   @   s   e Zd Zdd Zdd ZdS )MyIndexablec                 C   s
   || _ d S rH   rI   rK   r   r   r   rM      s    zMyIndexable.__init__c                 C   s   | j S rH   rI   rN   r   r   r   	__index__   s    zMyIndexable.__index__NrP   rQ   rR   rM   rV   r   r   r   r   rU      s   rU   c                   @   sn  e Zd ZdddZdd Zdd Zd	d
 Zdd Zdd Zdd Z	dd Z
dd Zdd Zedd Zdd Zeejdkoe dv ddd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zejd*d+ Zd,d- Zd.d/ Zd0d1 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~ ZIdd ZJdd ZKdS )	MathTestsr=   r>   c                 C   s,   t ||||}|d ur(| d|| d S )Nz{}: {})rF   failr    )rL   namer"   r!   r#   r$   rD   r   r   r   ftest   s    	zMathTests.ftestc                 C   s8   |  dtjd |  dtjd | tjdtj  d S )Npig-DT!	@egiW
@r:   )r[   rA   r\   r]   assertEqualtaurN   r   r   r   testConstants   s    zMathTests.testConstantsc                 C   s   |  ttj | dtdtj | dtdtjd  | dtdd |  ttjt |  ttjt |  ttjdt	  |  ttjdt	  | 
ttt d S )Nzacos(-1)zacos(0)r   r:   zacos(1)r   )assertRaises	TypeErrorrA   acosr[   r\   
ValueErrorINFNINFeps
assertTruerB   NANrN   r   r   r   testAcos  s    zMathTests.testAcosc                 C   s   |  ttj | dtdd | dtdd |  ttjd |  ttjd | ttt |  ttjt | 	t
tt d S )Nzacosh(1)r   r   zacosh(2)r:   g5qB?ra   )rb   rc   rA   acoshr[   re   r^   rf   rg   ri   rB   rj   rN   r   r   r   	testAcosh  s    zMathTests.testAcoshc                 C   s   |  ttj | dtdtj d  | dtdd | dtdtjd  |  ttjt |  ttjt |  ttjdt	  |  ttjdt	  | 
ttt d S )Nzasin(-1)ra   r:   zasin(0)r   zasin(1)r   )rb   rc   rA   asinr[   r\   re   rf   rg   rh   ri   rB   rj   rN   r   r   r   testAsin  s    zMathTests.testAsinc                 C   s   |  ttj | dtdd | dtdd | dtdd | ttt | ttt | t	tt
 d S )	Nzasinh(0)r   zasinh(1)r   g'ya64?z	asinh(-1)ra   g'ya64)rb   rc   rA   asinhr[   r^   rf   rg   ri   rB   rj   rN   r   r   r   	testAsinh"  s    zMathTests.testAsinhc                 C   s   |  ttj | dtdtj d  | dtdd | dtdtjd  | dtttjd	  | d
tttj d	  | t	tt
 d S )Nzatan(-1)ra      zatan(0)r   zatan(1)r   z	atan(inf)r:   z
atan(-inf))rb   rc   rA   atanr[   r\   rf   rg   ri   rB   rj   rN   r   r   r   testAtan+  s    zMathTests.testAtanc                 C   s   |  ttj | dtdd | dtdd | dtdd |  ttjd	 |  ttjd
 |  ttjt |  ttjt | 	t
tt d S )Nzatanh(0)r   z
atanh(0.5)      ?gz?zatanh(-0.5)      gzr   ra   )rb   rc   rA   rs   r[   atanhre   rf   rg   ri   rB   rj   rN   r   r   r   	testAtanh4  s    zMathTests.testAtanhc                 C   s  |  ttj | dtddtj d  | dtddtj d  | dtddd | d	tddtjd  | d
tddtjd  | dtdttj | dtddtj | dtddtj | tddd | tddd | tdtd | 	t
tdt | dtdttj  | dtddtj  | dtddtj  | tddd | tddd | tdtd | 	t
tdt | dttttjd d  | dttdtjd  | dttdtjd  | dttdtjd  | dttdtjd  | dttttjd  | 	t
ttt | dttttj d d  | dttdtj d  | dttdtj d  | dttdtj d  | d ttdtj d  | d!ttttj d  | 	t
ttt | d"tdttj | d#tddtjd  | d$tddtjd  | tdtd | 	t
tdt | d%tdttj  | d&tddtj d  | d'tddtj d  | tdtd | 	t
tdt | 	t
ttt | 	t
ttd | 	t
ttd | 	t
ttd | 	t
ttd | 	t
ttt | 	t
ttt d S )(Nzatan2(-1, 0)ra   r   r:   zatan2(-1, 1)r   rr   zatan2(0, 1)zatan2(1, 1)zatan2(1, 0)zatan2(0., -inf)r>   zatan2(0., -2.3)ffffffzatan2(0., -0.)       ffffff@zatan2(-0., -inf)zatan2(-0., -2.3)zatan2(-0., -0.)zatan2(inf, -inf)   zatan2(inf, -2.3)zatan2(inf, -0.)zatan2(inf, 0.)zatan2(inf, 2.3)zatan2(inf, inf)zatan2(-inf, -inf)zatan2(-inf, -2.3)zatan2(-inf, -0.)zatan2(-inf, 0.)zatan2(-inf, 2.3)zatan2(-inf, inf)zatan2(2.3, -inf)zatan2(2.3, -0.)zatan2(2.3, 0.)zatan2(-2.3, -inf)zatan2(-2.3, -0.)zatan2(-2.3, 0.))rb   rc   rA   atan2r[   r\   rg   r^   rf   ri   rB   rj   rN   r   r   r   	testAtan2?  sf     "zMathTests.testAtan2c                 C   sf  |  ttj | ttt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 G dd d}G dd dt}G dd d}| t| d | t| d | ttdd |  ttj|  | }dd |_	|  ttj| |  ttj|d d S )Nru   r         ?      ?r:   rv   r         ra         r>   rz   c                   @   s   e Zd Zdd ZdS )z$MathTests.testCeil.<locals>.TestCeilc                 S   s   dS N*   r   rN   r   r   r   __ceil__  s    z-MathTests.testCeil.<locals>.TestCeil.__ceil__NrP   rQ   rR   r   r   r   r   r   TestCeil  s   r   c                   @   s   e Zd Zdd ZdS )z%MathTests.testCeil.<locals>.FloatCeilc                 S   s   dS r   r   rN   r   r   r   r     s    z.MathTests.testCeil.<locals>.FloatCeil.__ceil__Nr   r   r   r   r   	FloatCeil  s   r   c                   @   s   e Zd ZdS )z&MathTests.testCeil.<locals>.TestNoCeilNrT   r   r   r   r   
TestNoCeil  s   r   r   g     @E@+   c                  W   s   | S rH   r   argsr   r   r   <lambda>      z$MathTests.testCeil.<locals>.<lambda>)
rb   rc   rA   ceilr^   r@   typer-   rG   r   )rL   r   r   r   tr   r   r   testCeil|  s*    
zMathTests.testCeilc                 C   s  |  tddd |  tddd |  tddd |  tddd |  td	d
d | ttj |  tddd |  tdd
d |  ttdt |  ttd
t |  ttdt |  ttd
t |  tdtd |  tdtd |  tttt |  tttt |  tttt |  tttt | ttt	d | ttt	t | ttt	t | ttt	t	 | t
ttt	 |  ttdt	d d S )Nr   r   r   r>   ir   r|         @      @rz                @)r^   rA   copysignrb   rc   rf   rg   ri   rB   rj   rC   r   rN   r   r   r   testCopysign  s0    zMathTests.testCopysignc                 C   s   |  ttj | jdttj d dtdd | dtdd | jdttjd dtdd | dttjd	 z0| ttt	 | ttt
 W n2 ty   |  ttjt	 |  ttjt
 Y n0 | ttt d S )
Nz
cos(-pi/2)r:   r   r   r$   zcos(0)z	cos(pi/2)zcos(pi)ra   )rb   rc   rA   cosr[   r\   ulpri   rB   rf   rg   re   rj   rN   r   r   r   testCos  s    &$zMathTests.testCoswin32)ZARMZARM64zEWindows UCRT is off by 2 ULP this test requires accuracy within 1 ULPc                 C   s   |  ttj | dtdd | dtddtdd   d | ttt | ttt | t	tt
 d S )Nzcosh(0)r   r   zcosh(2)-2*cosh(1)**2r:   ra   )rb   rc   rA   coshr[   r^   rf   rg   ri   rB   rj   rN   r   r   r   testCosh  s    &zMathTests.testCoshc                 C   sr   |  ttj | dttjd | dttjd d | dttj d d | d	td
d
 d S )Nzdegrees(pi)g     f@zdegrees(pi/2)r:   g     V@zdegrees(-pi/4)rr   g     Fz
degrees(0)r   )rb   rc   rA   degreesr[   r\   rN   r   r   r   testDegrees  s
    zMathTests.testDegreesc                 C   s   |  ttj | dtddtj  | dtdd | dtdtj | ttt | ttd | 	t
tt |  ttjd d S )	Nzexp(-1)ra   r   zexp(0)r   zexp(1)r>   @B )rb   rc   rA   r7   r[   r]   r^   rf   rg   ri   rB   rj   OverflowErrorrN   r   r   r   testExp  s    zMathTests.testExpc                 C   sN   |  ttj | dtdd | dtdd | dtdd d S )Nzfabs(-1)ra   r   zfabs(0)r   zfabs(1))rb   rc   rA   fabsr[   rN   r   r   r   testFabs  s    zMathTests.testFabsc                 C   s   |  tdd d}tddD ]4}||9 }|  t|| |  t|t| q | ttjd | ttjdd   d S )Nr   r     ra   
   d   )r^   rA   	factorialr   r   rb   re   )rL   totalr   r   r   r   testFactorial  s    zMathTests.testFactorialc                 C   s*  |  t" | tdd W d    n1 s20    Y  |  t  | ttjd W d    n1 sl0    Y  |  t  | ttjd W d    n1 s0    Y  |  t  | ttjd W d    n1 s0    Y  | ttjt	d | ttjt	d | ttjd d S )N      @x   g@r   }Ô%I5z5.2)
assertWarnsDeprecationWarningr^   rA   r   rb   re   rc   decimalDecimalrN   r   r   r   testFactorialNonIntegers  s    0...z"MathTests.testFactorialNonIntegersc                 C   sR   |  ttjdd  | t  |  ttjd W d    n1 sD0    Y  d S )Nr   r   }Ô%IT)rb   r   rA   r   r   r   rN   r   r   r   testFactorialHugeInputs  s    z!MathTests.testFactorialHugeInputsc                 C   sB  |  ttj | tttd | tdd | tdd | tdd | tdd | tdd | td	d
 G dd d}G dd dt}G dd d}| t| d | t| d | ttdd |  ttj|  | }dd |_	|  ttj| |  ttj|d d S )Nru   r   r   r   r   rv   ra   r   r   c                   @   s   e Zd Zdd ZdS )z&MathTests.testFloor.<locals>.TestFloorc                 S   s   dS r   r   rN   r   r   r   	__floor__  s    z0MathTests.testFloor.<locals>.TestFloor.__floor__NrP   rQ   rR   r   r   r   r   r   	TestFloor  s   r   c                   @   s   e Zd Zdd ZdS )z'MathTests.testFloor.<locals>.FloatFloorc                 S   s   dS r   r   rN   r   r   r   r     s    z1MathTests.testFloor.<locals>.FloatFloor.__floor__Nr   r   r   r   r   
FloatFloor  s   r   c                   @   s   e Zd ZdS )z(MathTests.testFloor.<locals>.TestNoFloorNrT   r   r   r   r   TestNoFloor!  s   r   r   g33333D@)   c                  W   s   | S rH   r   r   r   r   r   r   )  r   z%MathTests.testFloor.<locals>.<lambda>)
rb   rc   rA   floorr^   r@   r   r-   rG   r   )rL   r   r   r   r   r   r   r   	testFloor  s&    
zMathTests.testFloorc                 C   s  |  ttj | dtddd | dtddd | dtddd	 | d
tddd | dtddd | dtddd | tttd	 | ttd	t | tttt |  ttjd	d |  ttjt	d	 |  ttjt
d	 |  ttjt	d | tdt	d | tdt	d | tdt
d | tdt
d | tddd | tdt
d d S )Nzfmod(10, 1)r   r   r>   zfmod(10, 0.5)ru   zfmod(10, 1.5)r   r   zfmod(-10, 1)rz   zfmod(-10, 0.5)zfmod(-10, 1.5)r   r         )rb   rc   rA   fmodr[   ri   rB   rj   re   rf   rg   r^   rN   r   r   r   testFmod-  s(    zMathTests.testFmodc                    s     ttj  fdd}|dtdd |dtdd |d	td
d |dtdd  ttd t  ttd t  ttt	d  d S )Nc                    sB   || \}}\}}t || tks*||kr> d| ||f  d S Nz%s returned %r, expected %rr   rh   rY   )rZ   resultr!   mantr7   ZemantZeexprN   r   r   	testfrexpF  s
    z&MathTests.testFrexp.<locals>.testfrexpz	frexp(-1)ra   )rv   r   zfrexp(0)r   r   r   zfrexp(1)r   )ru   r   zfrexp(2)r:   )ru   r:   )
rb   rc   rA   frexpr^   rf   rg   ri   rB   rj   )rL   r   r   rN   r   	testFrexpC  s    zMathTests.testFrexpz2fsum is not exact on machines with double roundingc                    s8  ddl m} |j|j   fdd}g dfdgdfg ddfg dd	fg d
dfg ddfg ddfdd tddD tdfdd tddD tdfg ddfg ddfdd tdddD dg tdfg}d d tdD |fd!dtd"D d"  g d  f t|D ]x\}\}}zt	
|}W nN tyl   | d#|||f  Y n( ty   | d$|||f  Y n0 | || q*dd%lm}m}	m}
 td"D ]r}g d&d' }d}td(D ],}|	d| d) | }||7 }|| q|
| ||}| ||t	
| qd S )*Nr   )
float_infoc                    s   d\}}| D ]Z}t |\}}tt ||  }}||krR||| K }|}n||| K }||7 }qtttt|d   | }|dkrd|d > }|d|  t||@ o|d| d @  }||7 }t ||S )Nr   r:   r   r   r|   )	rA   r   r@   ldexpmaxlenbinr   bool)iterableZtmantZtexpr   r   r7   tailh)etinymant_digr   r   msumh  s    
"(z MathTests.testFsum.<locals>.msumr>   )r   r   r   0.++gd~QJr   gd~Qr   )      @Crv   g      g?C)r   r         9g     @C)g     @Cr   r   g     @C)g?Cru   g      <g?Cc                 S   s   g | ]}d | qS r   r   .0r   r   r   r   
<listcomp>  r   z&MathTests.testFsum.<locals>.<listcomp>r   i  z0x1.df11f45f4e61ap+2c                 S   s   g | ]}d | | qS )r   r   r   r   r   r   r     r   z-0x1.62a2af1bd3624p-1)r	   r   gؗҜ<g7yAC)g7yACg?g7yAgc                 S   s,   g | ]$}d | d |d   d |d   qS )r   2   4   r   r   r   r   r   r     r   i  r:   g      z0x1.5555555555555p+970c                 S   s   g | ]}d | qS )g333333?r   r   r   r   r   r   r     r   c                    s    g | ]} |d    |  qS )r   r   r   )termsr   r   r     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   ir   gh$.5g#B;r      r   )sysr   r   min_expr   r-   fromhexappend	enumeraterA   fsumr   rY   re   r^   r   r   r   )rL   r   r   test_valuesr   Zvalsr!   actualr   r   r   jsvr   )r   r   r   r   testFsumU  sj    







 
zMathTests.testFsumc                 C   sB  t j}| |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd	 | |dd
d	 | |ddd d}d}dD ]}|| }|| }| |||| | |||| | || || | ||| | | ||| | | || || | || | | | || | | q| | d | |dd | |d
d | |dddd | |dddd | t|d | t|dd | t|dd | t|ddd | |tdtdd	 d S )Nr   r   ra   r      r   T          j9W    P)}    "o  `T"-    l   8P9cC/[N
S9bXl	   9@{wM275k )	 l   Z'^%#>;*Q!/61^f            ^@      U@)rA   gcdr^   rb   rc   rU   )rL   r  r   ycabr   r   r   testGcd  sN    zMathTests.testGcdc                 C   s  ddl m} ddlm} tj}tjtjtdt	dt
df}tt|d D ]8}| ||d |  ttdd	 |d | D  qR| |d
dd | |ddd | ||d|dd | ||dd|dd|dd | |tdtdtdtdtd | |ddd | |dd | | d | dtd|d | |ddd|ddd | t |dd W d    n1 s0    Y  | t |ddd W d    n1 s0    Y  dtjjd  }| ttf |d| W d    n1 s,0    Y  | |tt | |dtt | |dtt | |dtt | |ttt | |ttt | |ttt | |ttt | |t tt | |t t t | |dt t | t|t | t|dt | t|td | t|dt | t|tt | t|t td }tdD ]&}| ||g|  |t|  qtdD ]2}	td|	  }
| td |
 d|
 d|
  qd S )!Nr   r   Fractionr         @g @r   c                 s   s   | ]}|d  V  qdS )r:   Nr   )r   r   r   r   r   	<genexpr>  r   z&MathTests.testHypot.<locals>.<genexpr>g      (@r         *@r   r=      r   r|   r>         %      %@r   rz   r   ru   r   皙?string皙@r   r   r   rr   ) r   r   	fractionsr  rA   hypotr]   r\   sqrtgammasinr   r   assertAlmostEqualsumr^   r   r   rb   rc   r   r   
max_10_expre   r   rf   rj   rg   ri   rB   	FLOAT_MAX	FLOAT_MIN)rL   r   r  r  r   r   int_too_big_for_float	fourthmaxr   r7   scaler   r   r   	testHypot  sl    $$,

*,*$zMathTests.testHypotc                 C   s  ddl m} ddlm} tj}tj}| |ddd | |ddd td	D ]h}td
D ]Z}t	dd t|D }t	dd t|D }| 
||||tdd t||D  q\qP| |g dg dd | |tg dtg dd | |ddd | |ddd | ||d|df|d|df|d | ||dd|ddf|dd|ddf|dd | |dd|d | |ddd | |ddd | d td |d!d" | d td |d"d! | |d#d$|d%d$ G d&d' d't	}	| ||	ddd | t |dd(d) W d    n1 sZ0    Y  | t |d W d    n1 s0    Y  | t |dd(d* W d    n1 s0    Y  | t |dd W d    n1 s0    Y  | t |d+d W d    n1 s20    Y  | t |d,d- W d    n1 sh0    Y  | t |dd. W d    n1 s0    Y  | t |d/d0 W d    n1 s0    Y  d1tjjd
  }
| ttf |d|
fd2 W d    n1 s"0    Y  | ttf |d2d|
f W d    n1 s`0    Y  td3D ]6}t t  }}| ||f|ft||  qrtd4d5dd6ttg}tj|d7d8D ]~}tj|d7d8D ]h}d9d: t||D }tttj|r| |||t n(tttj |r| !t ||| qܐqt"d; }tdD ]P}|f| }d"| }| ||||t|  | ||||t|  qZtdD ]V}t#d|  }d<| d7| f}d=}| t||d
|  | t||d
|  qd S )>Nr   r	  r
  )r   r   r   )r   r   r   r   )r   r:   r|   )rr   r:   ra   	   r=   c                 s   s   | ]}t d dV  qdS r=   Nr   uniformr   kr   r   r   r  9  r   z%MathTests.testDist.<locals>.<genexpr>c                 s   s   | ]}t d dV  qdS r%  r'  r)  r   r   r   r  :  r   c                 s   s   | ]\}}|| d  V  qdS )r   Nr   r   ZpxZqxr   r   r   r  =  r   )g      ,@r   )r   r   r  )   r   )r:   r  r,  r   r:   r-  r   )TTFTF)TFTTFr   )g     *@g      )@g      
r>   r   r   )rz   )r>   )r   r   ru   )r   r   r   )r   ru   r   c                   @   s   e Zd ZdS )zMathTests.testDist.<locals>.TNrT   r   r   r   r   T_  s   r.  )rr   r=   r   )pq)r      r$  )r  r  r  )r   r:   r|   rr   )r=   r   r   )rr   r=   r   r   abcZxyzr   )r:   r|      r  rz   r  r|   )repeatc                 S   s   g | ]\}}|| qS r   r   r+  r   r   r   r     r   z&MathTests.testDist.<locals>.<listcomp>r   rr   )r>   r>   )$r   r   r  r  rA   distr  r^   r   tupler  r  zipiterr   rb   rc   re   r   r   r  r   r   r   rg   rf   rj   	itertoolsproductanymaprC   rB   ri   r  r  )rL   DFr5  r  r   r   r/  r0  r.  r   valuesZdiffsr!  r   r7   r"  r   r   r   testDist*  s    ".,,(,*****.."
 zMathTests.testDistc              
   C   s4  t tdt tdd dd tddD  dd	 d
d g }|D ]r}| j|dR t|}| t|t | || | | 	||d |d   W d    qB1 s0    Y  qB| 
t td W d    n1 s0    Y  td}| t|t | |d td}| t|t | |d G dd dt}t|d}| t|t | |d | 
t t|d W d    n1 s0    Y  ddtddddg}|D ]j}| j|dF | 
t t| W d    n1 s0    Y  W d    n1 s"0    Y  qd S )Nr   iX> i(F c                 S   s(   g | ] }t d dD ]}d| | qqS )i(   r:   )r   )r   r]   r   r   r   r   r     r   z'MathTests.testIsqrt.<locals>.<listcomp><   r   r|   i'  r   i  rI   r   ra   TFr   c                   @   s   e Zd Zdd Zdd ZdS )z(MathTests.testIsqrt.<locals>.IntegerLikec                 S   s
   || _ d S rH   rI   rK   r   r   r   rM     s    z1MathTests.testIsqrt.<locals>.IntegerLike.__init__c                 S   s   | j S rH   rI   rN   r   r   r   rV     s    z2MathTests.testIsqrt.<locals>.IntegerLike.__index__NrW   r   r   r   r   IntegerLike  s   rC  i  r   r  za stringz3.5y              @g      Y@r   )listr   subTestrA   isqrtassertIsr   r@   assertLessEqualZ
assertLessrb   re   r^   objectr   r   rc   )rL   r   rJ   r   rC  Z
bad_valuesr   r   r   	testIsqrt  sF    

8(

.zMathTests.testIsqrtc                 C   sN  t j}| |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |dd	d
 | |d	dd
 | |ddd d}d}dD ]}|| }|| }|| | }| |||| | |||| | || || | ||| | | ||| | | || || | || | | | || | | q| | d | |dd | |dd | |dd	dd | |ddd	d | t|d | t|dd	 | t|dd | t|ddd | |tdtd	d
 d S )Nr   r   ra   r   r   r   iY  r   r   iH  r   r   r   l    ,`aUx-xB:Vn
Ldbl   me%Y% l   };T^	 )r   l   |/Kr2 r   i7  r  r  )rA   lcmr^   rb   rc   rU   )rL   rL  r   r  r  r  r  dr   r   r   test_lcm  sP    zMathTests.test_lcmc              	   C   s:  |  ttj | dtddd | dtddd | dtddd | d	tddd
 |  ttjdd |  ttjdd | tddd | tddd | ttdt | ttdt | 	t
ttd ddddd fD ]0}| tt| t | tt| t | td| d | td| d | td| d | td| d | 	t
tt|  |  ttjd| |  ttjd| | td|d | td|d | tt|t | tt|t | 	t
tt| qd S )Nz
ldexp(0,1)r   r   z
ldexp(1,1)r:   zldexp(1,-1)ra   ru   zldexp(-1,1)r   r   r   r   ir>   rz      i+i l    d(	       Fx:^V r   rA  )rb   rc   rA   r   r[   r   r^   rf   rg   ri   rB   rj   rL   r   r   r   r   	testLdexp  s6    zMathTests.testLdexpc                 C   s  |  ttj | dtdtj d | dtdd | dttjd | dtdd	d
 | dtdd dd | dtdd dd	 | dtdd d |  ttjd |  ttjdd   |  ttjt | tt	t	 | 
ttt d S )Nzlog(1/e)r   ra   zlog(1)r   zlog(e)z	log(32,2)r   r:   r=   zlog(10**40, 10)r   rA  zlog(10**40, 10**20)rP  zlog(10**1000)r   gO+@r   )rb   rc   rA   logr[   r]   re   rg   r^   rf   ri   rB   rj   rN   r   r   r   testLog  s    zMathTests.testLogc                 C   sh   |  ttj ddd dd fD ] }| t|tt| q |  ttjd | ttt d S )Nr:   Z   i,  ra   )	rb   rc   rA   log1pr  r-   re   r^   rf   rQ  r   r   r   	testLog1p,  s
    zMathTests.testLog1pc                 C   s   |  ttj | tdd | tdd | tdd | tdd d | tdd	 d
 | tdd d |  ttjd |  ttjt | ttt	 d S )Nr   r>   r:   r   rr   r   i  g     @   g      @i  g     @@r   )
rb   rc   rA   log2r^   re   rg   ri   rB   rj   rN   r   r   r   testLog23  s    zMathTests.testLog2r   c                 C   s8   dd t ddD }dd t ddD }| || d S )Nc                 S   s   g | ]}t t d |qS r   )rA   rY  r   r   r   r   r   r   J  r   z+MathTests.testLog2Exact.<locals>.<listcomp>r   rX  c                 S   s   g | ]}t |qS r   r-   r   r   r   r   r   K  r   )r   r^   )rL   r   r!   r   r   r   testLog2ExactE  s    zMathTests.testLog2Exactc                 C   s   |  ttj | dtdd | dtdd | dtdd | d	tdd
 d |  ttjd |  ttjdd
   |  ttjt | tt	t	 | 
ttt d S )Nz
log10(0.1)皙?ra   zlog10(1)r   r   z	log10(10)r   zlog10(10**1000)r   g     @@r   )rb   rc   rA   log10r[   re   rg   r^   rS  rf   ri   rB   rj   rN   r   r   r   	testLog10N  s    zMathTests.testLog10c                    s     ttj  fdd}|dtdd |dtdd  ttd	tf  ttd
tf tt} t	|d   t	|d  d S )Nc                    sF   || \}}\}}t || tks.t || rB d| ||f  d S r   r   )rZ   r   r!   Zv1Zv2e1e2rN   r   r   testmodf]  s
    z$MathTests.testModf.<locals>.testmodfz	modf(1.5)r   )ru   r   z
modf(-1.5)r   )rv   r   r>   rz   r   r   )
rb   rc   rA   modfr^   rf   rg   rj   ri   rB   )rL   rb  Zmodf_nanr   rN   r   testModfZ  s    
zMathTests.testModfc                 C   s  |  ttj | dtddd | dtddd | dtddd | dtddd	 | ttdt | ttdt | tdtd
 | tdtd
 | t	tt
d | t	tdt
 | t	tdt
 | tdt
d | 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tjdd |  ttjdd |  ttjdd |  ttjdt | t	tdt
 | tttt | ttdt | ttdt | ttdt | ttdd
 | ttdd
 | ttdd | ttdd | ttdd | tttd | t	ttt
 | 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tjdd |  ttjdd |  ttjdd |  ttjdt | t	tdt
 | tttt | ttdt | ttdt | ttdt | ttdd
 | ttdd
 | ttdd | ttdd | ttdd | tttd | t	ttt
 | tdtd
 | tddd |  ttjdd | tddd
 | tddd
 | tddd
 | tddd
 |  ttjdd | tddd | tdtd
 | t	tdt
 | 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ddd
 | tt
dd
 | tddd
 | tddd
 | tt
dd
 |  ttjdd |  ttjdd | tdtd | tdtd | tdtt | tdtt | tdtt | tdtt | tdtd | tdtd | tdtt | tdtt | tdtd | tdtd | tdtd | tdtd | tdtt | tdtt | dtddd | d tddd! | d"tdd
d | d#tddd
 | d$tddd
 | d%tddd& | d'tddd( | d)tddd* |  ttjdd& |  ttjdd	 d S )+Nzpow(0,1)r   r   zpow(1,0)zpow(2,1)r:   z	pow(2,-1)ra   ru   r   r>   r   r{   r   rz   g       ry   r   r   g      .ggffffff?r  ?r]  ggggffffffz	(-2.)**3.g       z	(-2.)**2.r   z	(-2.)**1.z	(-2.)**0.z
(-2.)**-0.z
(-2.)**-1.rv   z
(-2.)**-2.g      ?z
(-2.)**-3.g      )rb   rc   rA   powr[   r^   rf   rg   ri   rB   rj   re   rN   r   r   r   testPowm  s    zMathTests.testPowc                 C   sr   |  ttj | dtdtj | dtdtjd  | dtdtj d  | d	td
d
 d S )Nzradians(180)   zradians(90)rU  r:   zradians(-45)irr   z
radians(0)r   )rb   rc   rA   radiansr[   r\   rN   r   r   r   testRadians  s
    zMathTests.testRadiansc              	      s  ddl m   fdd}g d}|D ]}j|dh | \}}}t|}t|}t|}	||||	 t||}
|
	 |		  W d    q&1 s0    Y  q&td}t
dd	D ]`}|dkrq|| }t
d
D ]@}|| }t||}
||||
 t| |}
|| ||
 qqtddddttfD ]*}tt| t|t q8dD ].}t|t| t|t| qhtddddtfD ]}t tt| W d    n1 s0    Y  t tt| W d    n1 s0    Y  t t|d W d    n1 sJ0    Y  t t|d W d    n1 s0    Y  qd S )Nr   r
  c                    s    |  | |  }}} t|t|d  || | }|t| t|t|d kr||d t|d  d S )Nr:   )rI  r   r^   r@   )r   r  rZfxZfyfrr   r  rL   r   r   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)casez1p-1074i   r   r>   rz   r   ry   )ry   rz   r>   r{   r{   )r  r  rF  r,   r-   r   rA   	remainderr^   hexr   rj   rg   rf   assertIsNaNrb   re   )rL   rn  Z	testcasesro  Zx_hexZy_hexZexpected_hexr   r  r!   r   Ztinyr   mrJ   r   rm  r   testRemainder	  sL    ;


4
,,,zMathTests.testRemainderc                 C   s   |  ttj | dtdd | dttjd d | dttj d d z0| ttt | ttt	 W n2 t
y   |  t
tjt |  t
tjt	 Y n0 | ttt d S )Nzsin(0)r   z	sin(pi/2)r:   r   z
sin(-pi/2)ra   )rb   rc   rA   r  r[   r\   ri   rB   rf   rg   re   rj   rN   r   r   r   testSin  s    zMathTests.testSinc                 C   s   |  ttj | dtdd | dtdd tdd  d | dtdtd d | ttt | ttt | 	t
tt d S )Nzsinh(0)r   zsinh(1)**2-cosh(1)**2r   r:   ra   zsinh(1)+sinh(-1))rb   rc   rA   sinhr[   r   r^   rf   rg   ri   rB   rj   rN   r   r   r   testSinh  s    &zMathTests.testSinhc                 C   s   |  ttj | dtdd | dtdd | dtdd | ttt |  ttjd |  ttjt | 	t
tt d S )	Nzsqrt(0)r   zsqrt(1)r   zsqrt(4)rr   r:   ra   )rb   rc   rA   r  r[   r^   rf   re   rg   ri   rB   rj   rN   r   r   r   testSqrt  s    zMathTests.testSqrtc                 C   s   |  ttj | dtdd | dttjd d | dttj d d z0| ttt | ttt	 W n,   |  t
tjt |  t
tjt	 Y n0 | ttt d S )Nztan(0)r   z	tan(pi/4)rr   r   z
tan(-pi/4)ra   )rb   rc   rA   tanr[   r\   ri   rB   rf   rg   re   rj   rN   r   r   r   testTan  s    zMathTests.testTanc                 C   s   |  ttj | dtdd | jdtdtd dtdd | dttd | dttd | t	tt
 d S )	Nztanh(0)r   ztanh(1)+tanh(-1)r   ra   r   z	tanh(inf)z
tanh(-inf))rb   rc   rA   tanhr[   r   rf   rg   ri   rB   rj   rN   r   r   r   testTanh  s    zMathTests.testTanhc                 C   s8   |  tdd |  tdtdtdd d S )Nrz   r   )r^   rA   r|  r   rN   r   r   r   testTanhSign  s    
zMathTests.testTanhSignc                 C   sZ  |  tdd |  tdd |  ttdt |  ttdt |  tdd |  tdd |  tdd |  tdd |  tdd |  td	d
 G dd d}G dd dt}G dd d}|  t| d |  t| d | ttj | ttjdd | ttjtd | ttj|  d S )Nr   ra   r   r   g?gg!r   g-?Yic                   @   s   e Zd Zdd ZdS )z'MathTests.test_trunc.<locals>.TestTruncc                 S   s   dS N   r   rN   r   r   r   	__trunc__  s    z1MathTests.test_trunc.<locals>.TestTrunc.__trunc__NrP   rQ   rR   r  r   r   r   r   	TestTrunc  s   r  c                   @   s   e Zd Zdd ZdS )z(MathTests.test_trunc.<locals>.FloatTruncc                 S   s   dS r  r   rN   r   r   r   r    s    z2MathTests.test_trunc.<locals>.FloatTrunc.__trunc__Nr  r   r   r   r   
FloatTrunc  s   r  c                   @   s   e Zd ZdS )z)MathTests.test_trunc.<locals>.TestNoTruncNrT   r   r   r   r   TestNoTrunc  s   r  r  r:   g     7@)	r^   rA   truncr   r@   r-   rb   rc   rG   )rL   r  r  r  r   r   r   
test_trunc  s&    zMathTests.test_truncc                 C   s   |  td |  td |  td |  td | ttd | ttd | ttd d S )Nr>   rz   r   r   r   r   r   )ri   rA   isfiniteassertFalser-   rN   r   r   r   testIsfinite  s    zMathTests.testIsfinitec                 C   sx   |  ttd |  ttd |  ttdd  | ttd | td | td d S )Nr   z-nanr   r>   r   )ri   rA   rB   r-   r  rN   r   r   r   	testIsnan  s    zMathTests.testIsnanc                 C   s   |  ttd |  ttd |  td |  td | ttd | td | td d S )Nr   r   g      g      r   r>   r   )ri   rA   rC   r-   r  rN   r   r   r   	testIsinf  s    zMathTests.testIsinfc                 C   s   |  ttj d S rH   )ri   rA   rB   r   rN   r   r   r   test_nan_constant  s    zMathTests.test_nan_constantc                 C   sJ   |  ttj | tjd | tjtd | tj td d S )Nr>   r   r   )ri   rA   rC   r   ZassertGreaterr^   r-   rN   r   r   r   test_inf_constant  s    zMathTests.test_inf_constantzrequires verbose modec                 C   s   zt d}W n   | d Y n0 |dkr8| d zt d}W n tyX   Y n0 | d zt d}W n ty   Y n0 | d d S )	Ni 6ez6underflowing exp() should not have raised an exceptionr   z)underflowing exp() should have returned 0i ʚ;z.overflowing exp() didn't trigger OverflowErrorr   z sqrt(-1) didn't raise ValueError)rA   r7   rY   r   r  re   rL   r   r   r   r   test_exceptions  s     

zMathTests.test_exceptionsc              	   C   sf  dh}d }t jdkrLt d }zttt|d}W n tyJ   Y n0 d}g }tt	D ]\}}}}	}
}}|	dks\|dkrq\|dv rq\|d ur|dk r||v rq\t
t|}d	|v sd
|v rd}
nd|v rd}
z||}W n, ty   d}Y n ty   d}Y n0 d\}}t|
|||}|d u r,q\|||||}|| q\|rb| dd|  d S )NZtan0064darwinr   .{}: {}({!r}): {}r>   )ZrectZpolar)r   r=   invaliddivide-by-zerore   overflowr   r=   r>   zFailures in test_testfile:
  
  )r   platformZmac_verr6  r<  r@   r,   re   r<   	test_filegetattrrA   r   rF   r    r   rY   join)rL   ZSKIP_ON_TIGERZosx_versionZversion_txtrE   failuresr3   r4   arZaiZereir8   funcr   r#   r$   rD   msgr   r   r   test_testfile.  sN    



zMathTests.test_testfilec              	   C   s(  d}g }t tD ]\}}}}}tt|}d|v s8d|v r>d}nd|v rJd}z||}	W n* tyl   d}	Y n ty   d}	Y n0 d\}
}|dkrd	}
n>|d
krd}n0|dkr|dkr|dk rd}
n|dk rd}
nd}
t||	|
|}|d u rq|||||}|| q|r$| 	dd
|  d S )Nr  r  r  re   r  r   r  r  r3  lgammagV瞯<erfcr>   r   r         $@r   r   zFailures in test_mtestfile:
  r  )r9   math_testcasesr  rA   re   r   rF   r    r   rY   r  )rL   rE   r  r3   r4   r5   r!   r8   r  r"   r#   r$   rD   r  r   r   r   test_mtestfileg  sD    

zMathTests.test_mtestfilec              
   C   s  t j}| |g d | |g ddd | |ttddd | |tttddd | |tddddd | |g d	d
 | |g dd | |g dd | |g dd | |g dd | |g dtd | t| | t|d | t|g d | jt|g ddd | jt|ddgdd t	dt	dg}| jt||t	dd | t|dgdgdgg | t|ddig | jt|ddigd ddid | jt|dgdgdggg d | |ddgddd | |ddgddgdg d | |g ddidddi | t |ddgd W d    n1 sf0    Y  | |g dd | |g d d | |g d!d d7d"d#}tdd$}| |||| td%d&}| |||| td'd(}| ||d d)d* tdd(D }| |||| d+d* td'd&D }| |||| d,d* td'd(D }| 
|| | 
|dddtd-ddg | 
|ddtd-ddg | 
|dtd-ddg | 
|dtd.td-dg | 
|dtd/td-dg | 
|dtd-td.dg | 
|dtd-td/dg | |dddtd.d0d1gtd/ | |dddtd/d0d1gtd. | 
|dddtd.d0d1g | 
|dddtd/d0d1g | 
|dddtd.d0ddg | 
|dddtd/d0ddg | t|g d2t | t|g d3t | t|tdd$t | t|tdd$d4dt | t|dtd5dd1dd6gtj d S )8Nr   r=   )r   r:   r1  i  r   i _7 )r   r:   r|   rr   r=   r   )r   r   r   r   r   r  )r   r:   r|   r   r   )r   r   r   rr   r=   )r   r           r   r   r  )r   r   r  r   r   r   )r  r  r      a   cr      br|   abZabababababab)r   r:   r   r:   r   r:   r   r:   r   r:   r   r:   r3  )r   r   r:   r|   r   )r   r   r:   r|   )r   r:   r|   r   c                 S   s   | D ]}||9 }q|S rH   r   )r   r   elemr   r   r   _naive_prod  s    
z(MathTests.test_prod.<locals>._naive_prodi'  ira   ir   c                 S   s   g | ]}t |qS r   r[  r   r   r   r   r   r     r   z'MathTests.test_prod.<locals>.<listcomp>c                 S   s   g | ]}t |qS r   r[  r  r   r   r   r     r   c                 S   s   g | ]}t |qS r   r[  r  r   r   r   r     r   r   r   r   rD  rr   )r   r:   r|   rr   r=   r   )r   r   r|   rr   r=   r   r   r   r   )r   )rA   prodr^   rE  r   r8  r-   rb   rc   	bytearrayrs  r   r@   r   r   )rL   r  r?  r  r   r   r   r   	test_prod  s      .



$$   zMathTests.test_prodc              	   C   sL  t j}t j}tdD ]8}t|d D ]&}| ||||||||   q$qtddD ]F}td|D ]6}| |||||d |d | ||d |  qfqXtddD ]>}| ||dd | ||d| | ||||| qtdD ].}| |||| | ||d || q| t|dd | t|dtd | t|dd | t|dd | t|tdd | t|d	d | t| | t|ddd
 | t| | t	|dd | t	|dd  d | t	|dd | t	|ddd   | |ddd | |ddd d dd }| ||dd | ||d| | ||d||d   t
jddr| t||| dD ]2\}}| |||d | t|||t q| |tdtdd | |tdtdd td
D ]B}| t|tdt|t | t|tdt|t qd S )Nr   r   r   r3  r   r   1r  10r|   ra   r:   r   TZcpython)TT)TF)FFr=   )rA   permr   r   r^   rb   rc   r   r   re   r   check_impl_detailr   rH  r   r@   rS   rU   )rL   r  r   r   r*  r   r   r   testPerm  s\    6zMathTests.testPermc              
   C   s  t j}t j}tdD ]@}t|d D ].}| ||||||||||    q$qtddD ]B}td|D ]2}| |||||d |d ||d |  qnq`tdD ](}| ||dd | |||d qtddD ],}| ||d| | |||d | qtdD ]6}t|d D ]"}| |||||||  q&q| t|dd | t|dtd | t|dd | t|dd | t|tdd | t|d	d | t|d | t|ddd
 | t| | t	|dd | t	|dd  d | t	|dd | t	|ddd   | |ddd | |ddd d dd }| ||dd | ||d| | ||d||d  d  | |||d | |||d | | |||d ||d  d  t
jddr| t|||d  dD ]2\}}| |||d | t|||t q| |tdtdd | |tdtdd td
D ]B}| t|tdt|t | t|tdt|t qd S )Nr   r   r   r:   r   r   r  r  r  r|   ra   r   Tr  r  r=   )rA   combr   r   r^   rb   rc   r   r   re   r   r  r   rH  r   r@   rS   rU   )rL   r  r   r   r*  r   r   r   testCombF  sf    
2$"zMathTests.testCombc                 C   s  |  tdt d |  tdtd |  tddd |  tddd |  td	t td
 |  td	ttd |  tddd | tddd | tddd tjj	tjj
 }|  tdt| |  tdt| |  tdt |  |  tdt |  | t|dd | t| dd | t|dd | t| dd tjj}|  ttd| |  tt d|  |  t|tt |  t| t t  | ttd	 | td	t | ttt d S )Ng      0Cg/Cg     0Cg      Cr>   gCg      gr   z0x1.fffffffffffffp-1z0x1.0000000000001p+0r   rz   )r^   rA   	nextafterrf   r-   r   assertEqualSignr   r   minepsilonr   rs  rj   )rL   Zsmallest_subnormalZlargest_normalr   r   r   test_nextafter  sL    zMathTests.test_nextafterc              	   C   s  |  tdtjj |  tdd |  tdd |  tdd |  tdtjjtjj  |  tttttt	   |  tt	t	 | 
ttj ddddt	fD ]J}| j|d* |  t| t| W d    q1 s0    Y  qd S )	Nr   l          l          r   l            g      @r>   r  )r^   rA   r   r   r   r  r  r  r  rf   rs  r   rF  r  r   r   r   test_ulp  s    zMathTests.test_ulpc              	   C   st   G dd d}t jt jt jfD ]P}| }| t |d| W d    n1 sR0    Y  | t|dd qd S )Nc                   @   s   e Zd Zdd ZdS )z$MathTests.test_issue39871.<locals>.Fc                 S   s   d| _ dd  d S )NTr   r   )	convertedrN   r   r   r   rO     s    z.MathTests.test_issue39871.<locals>.F.__float__N)rP   rQ   rR   rO   r   r   r   r   r>    s   r>  znot a numberr  F)rA   r}   r   rq  rb   rc   r  r  )rL   r>  r  r  r   r   r   test_issue39871  s    (zMathTests.test_issue39871c                 C   s   t |s| d| d S )NzExpected a NaN, got {!r}.)rA   rB   rY   r    rK   r   r   r   rs    s    
zMathTests.assertIsNaNc                 C   s,   |  || |  td|td| d S )Nr   )r^   rA   r   )rL   r   r  r   r   r   r    s    zMathTests.assertEqualSignN)r=   r>   )LrP   rQ   rR   r[   r`   rk   rm   ro   rq   rt   rx   r~   r   r   r   r   unittestZskipIfr   r  machiner   r   r   r   r   r   r   Zcpython_onlyr   r   r   r   HAVE_DOUBLE_ROUNDINGr   r  r#  r@  rK  rN  rR  rT  rW  rZ  Zrequires_mac_verr\  r_  rd  rg  rj  ru  rv  rx  ry  r{  r}  r~  r  r  r  r  r  r  Z
skipUnlessr   r  r  r  r  r  r  r  r  r  rs  r  r   r   r   r   rX      s   

		=!
!



^*Jq5, 

 
 	
	
		




8
B\@F
-
rX   c                   @   s   e Zd ZejZdd Zdd Zdd Zdd Zd	d
 Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS ) IsCloseTestsc                 O   s0   | j | j||g|R i |d||f d d S )Nz%s and %s should be close!r  )ri   iscloserL   r  r  r   kwargsr   r   r   assertIsClose  s    
zIsCloseTests.assertIsClosec                 O   s0   | j | j||g|R i |d||f d d S )Nz%s and %s should not be close!r  )r  r  r  r   r   r   assertIsNotClose  s    
zIsCloseTests.assertIsNotClosec                 O   s,   |D ]"\}}| j ||g|R i | qd S rH   )r  rL   Zexamplesr   r  r  r  r   r   r   assertAllClose  s    zIsCloseTests.assertAllClosec                 O   s,   |D ]"\}}| j ||g|R i | qd S rH   )r  r  r   r   r   assertAllNotClose  s    zIsCloseTests.assertAllNotClosec                 C   sz   |  t  | jdddd W d    n1 s00    Y  |  t" | jddddd W d    n1 sl0    Y  d S )Nr   g0.+rel_tolr   g    _©r  r$   )rb   re   r  rN   r   r   r   test_negative_tolerances  s    .z%IsCloseTests.test_negative_tolerancesc                 C   s   g d}| j |ddd d S )N))r   r   )N@ir  );r  )i90  g    @)r>   rz   )NF r  r>   r  r  )rL   Zidentical_examplesr   r   r   test_identical
  s    zIsCloseTests.test_identicalc                 C   s(   g d}| j |dd | j|dd d S )N))g    חAg   חA)g:0yEgnyE)g	ѭ?gfNӭ?:0yE>r  &.>r  r  )rL   Zeight_decimal_places_examplesr   r   r   test_eight_decimal_places  s    z&IsCloseTests.test_eight_decimal_placesc                 C   s(   g d}| j |dd | j|dd d S )N))r  r>   )g&.r>   )gu?j/ʠr>   re  r  r  r   )r  r  )rL   Znear_zero_examplesr   r   r   test_near_zero  s    zIsCloseTests.test_near_zeroc                 C   s<   |  tt | j ttdd |  tt | j ttdd d S )Nr>   r   )r  rf   rg   rN   r   r   r   test_identical_infinite&  s    z$IsCloseTests.test_identical_infinitec                 C   sR   t t ft dfdt ftt ft tfttftdfdtftdfdtfg
}| j|dd d S )Nr   r   gg?r   )rj   rf   rg   r  )rL   Znot_close_examplesr   r   r   test_inf_ninf_nan-  s    zIsCloseTests.test_inf_ninf_nanc                 C   s0   g d}| j |dd g d}| j|dd d S )N))r   r   )333333r  )Ynr  r>   r  ))r   g     ?)g?r   )gZbtigTbtir  )rL   Zzero_tolerance_close_examplesZ!zero_tolerance_not_close_examplesr   r   r   test_zero_tolerance<  s    z IsCloseTests.test_zero_tolerancec                 C   s   | j ddgdd d S )N)r$  r   )r   r$  r]  r  r  rN   r   r   r   test_asymmetryH  s    zIsCloseTests.test_asymmetryc                 C   s(   ddg}| j |dd | j|dd d S )N) )i[i[r  r  r  r  )rL   Zinteger_examplesr   r   r   test_integersL  s
    zIsCloseTests.test_integersc                 C   sh   ddl m} |d|df|d|df|d|df|d	|d
fg}| j|dd | j|dd d S )Nr   r	  z
1.00000001z1.0z1.00000001e-20z1.0e-20z1.00000001e-100z1.0e-100z1.00000001e20z1.0e20r  r  r  )r   r   r  r  )rL   r   Zdecimal_examplesr   r   r   test_decimalsT  s    zIsCloseTests.test_decimalsc                 C   sd   ddl m} |ddd |df|d|df|dd|ddfg}| j|dd	 | j|d
d	 d S )Nr   r
  r   r  r  l       	(qe	 rP  r  r  r  )r  r  r  r  )rL   r  Zfraction_examplesr   r   r   test_fractions_  s    zIsCloseTests.test_fractionsN)rP   rQ   rR   rA   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r    s    

r  c                  C   sN   ddl m}  t }|tt |tt || d t| d S )Nr   )DocFileSuitezieee754.txt)	doctestr  r  Z	TestSuiteZaddTestZ	makeSuiterX   r  r   )r  Zsuiter   r   r   	test_maink  s    r  )r=   r>   )8Ztest.supportr   r   r   testr   r  r9  r   rA   osr  r   r   r   rh   r-   rj   rf   rg   r   r   r  r  r  r   r  r  rP   argvfile__file__pathdirnamecurdirZtest_dirr  r  r  r   r   r   r   r&   r9   r<   rF   rG   r@   rS   rJ  rU   ZTestCaserX   r  r  r   r   r   r   <module>   sl   &
-              {
