
    7bh6                       d dl mZmZ d dlmZ d dlZd dlZd dlZd dl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z   d	k(  Zed
k(  rej:                  d    ZneZe
j@                  jC                  e      xs e
jD                  Z#e
j@                  jI                  e#d      Z%e
j@                  jI                  e#d      Z&d Z'd Z(d Z)d Z*d Z+d Z,d Z-d"dZ. G d d      Z/ G d de0      Z1 G d de2      Z3 G d d      Z4 G d dejj                        Z6 G d d ejj                        Z7d! Z8ed
k(  r ejr                          yy)#    )verboserequires_IEEE_754)supportNgh㈵>naninf-inf) 7yACg):@g7yAC__main__zmath_testcases.txtzcmath_testcases.txtc                 v    t        j                  dt        j                  d|             d   }|dk  r|dz    }|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<dr   l            )structunpackpack)xns     8/opt/python-3.12.12/usr/lib/python3.12/test/test_math.pyto_ulpsr   (   s;     	dFKKa01!4A1ugJH    c                 2    | rdt        | | dz
  z        z   S dS )zANumber of '1' bits in binary expansion of a nonnnegative integer.   r   )count_set_bits)r   s    r   r   r   N   s!    ,-1~a!a%i((414r   c                 h    || z
  dz	  }|sy|dk(  r| S | |z   dz  }t        | |      t        ||      z  S )zProduct 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mids       r   r   r   R   sL    
 ,1$J	qz!Q&uc*_S$-GGGr   c                     dx}}t        t        | j                                     D ]+  }|t        | |dz   z	  dz   dz  | |z	  dz   dz        z  }||z  }- || t	        |       z
  z  S )zFactorial of nonnegative integer n, via "Binary Split Factorial Formula"
    described at http://www.luschny.de/math/factorial/binarysplitfact.html

    r   )reversedrange
bit_lengthr   r   )r   innerouteris       r   py_factorialr$   `   sx    
 EEeALLN+,!q1u*!1A!5Q!|a7GHH - Q**++r   c                     t        t        |       t        |      z
        }t        | |z
        }||k  s||k  ryd}|j                  ||||      S )zGiven 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fmts          r   ulp_abs_checkr/   k   sZ     GH%45IHsN#I GyG37zz)YAAr   c              #   l  K   t        | d      5 }|D ]  }d|v r|d|j                  d       }|j                         s,|j                  d      \  }}|j                         \  }}}|j                         }|d   }	|dd }
||t	        |      t	        |	      |
f  	 ddd       y# 1 sw Y   yxY ww)zParse 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->r   r   )openindexstripsplitfloat)fnamefplinelhsrhsidfnarg
rhs_piecesexpflagss              r   parse_mtestfilerF   }   s      
eg	&"Dt|-TZZ-.::<zz$'HC))+KBCJQ-CqrNEr5:uSz599  
'	&	&s   B4BB(	B4(B1-B4c           
   #     K   t        | d      5 }|D ]  }|j                  d      s|j                         s%|j                  d      \  }}|j                         \  }}}}|j                         }	|	d   |	d   }}
|	dd }||t	        |      t	        |      t	        |
      t	        |      |f  	 ddd       y# 1 sw Y   yxY ww)	zParse a file with test values

    Empty lines or lines starting with -- are ignored
    yields id, fn, arg_real, arg_imag, exp_real, exp_imag
    r1   r2   r4   r5   r   r      N)r6   
startswithr8   r9   r:   )r;   r<   r=   r>   r?   r@   rA   arg_realarg_imagrC   exp_realexp_imagrE   s                r   parse_testfilerN      s      
eg	&"Dt$DJJLzz$'HC),&BHhJ!+A
1hHqrNEr?E(O?E(O   
'	&	&s   CB!B;2	C;C Cc                    || k(  r;|s8| s6t        j                  d|      t        j                  d|       k7  r	d|  d| dS yd}t        | t              rt        |t              rt        |      }n+t        |t              rt        | t              rt        |       } t        | t              rvt        |t              rft        j
                  |       rt        j
                  |      rd}n9t        j                  |       st        j                  |      rnt        | |||      }|*d}|j                  | |      }|dj                  |      z  }|S y)	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.
    r   z	expected z, got z (zero has wrong sign)Nz	not equalzexpected {!r}, got {!r}z ({}))	mathcopysign
isinstancer:   intisnanisinfr/   r'   )r(   r)   r*   r+   failurefail_fmtfail_msgs          r   result_checkrY      s    h8}}Q$a(BB"8*F3%7MNNG (E"z#s';Cj	C	Jx$=?(E"z#u'=::hDJJsOGZZ!TZZ_ $Hc7GDG ,??8S1GNN7++r   c                       e Zd Zd Zd Zy)	FloatLikec                     || _         y Nvalueselfr_   s     r   __init__zFloatLike.__init__   	    
r   c                     | j                   S r]   r^   ra   s    r   	__float__zFloatLike.__float__       zzr   N)__name__
__module____qualname__rb   rf    r   r   r[   r[          r   r[   c                       e Zd Zy)IntSubclassNrh   ri   rj   rk   r   r   rn   rn      s    r   rn   c                       e Zd Zd Zd Zy)MyIndexablec                     || _         y r]   r^   r`   s     r   rb   zMyIndexable.__init__   rc   r   c                     | j                   S r]   r^   re   s    r   	__index__zMyIndexable.__index__   rg   r   Nrh   ri   rj   rb   rt   rk   r   r   rq   rq      rl   r   rq   c                       e Zd ZddZy)BadDescrNc                     t         r]   )
ValueError)ra   objobjtypes      r   __get__zBadDescr.__get__   s    r   r]   )rh   ri   rj   r|   rk   r   r   rw   rw      s    r   rw   c                   Z   e Zd ZdRdZd Zd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zed        Zd Z ej$                  ej(                  dk(  xr  ej*                         dv d      d        Zd Zd Zd Zd Zd Zd Zej<                  d        Zd Z d Z!d Z"e ej$                  e#d      d               Z$d Z%d  Z&e ej$                  e#d!      d"               Z'd# Z(d$ Z)d% Z*d& Z+d' Z,d( Z-d) Z.ed*        Z/e ej`                  d+d      d,               Z1d- Z2d. Z3e ej$                  e#d/      ej<                  d0                      Z4 ejj                  d1      d2        Z6e ej$                  e#d/      ej<                   ejj                  d1      d3                             Z7d4 Z8d5 Z9d6 Z:ed7        Z;d8 Z<d9 Z=d: Z>d; Z?d< Z@ed=        ZAd> ZBd? ZCd@ ZDdA ZEdB ZFdC ZG ej                  eIdD      dE        ZJedF        ZKedG        ZLdH ZMdI ZNdJ ZOedK        ZPedL        ZQdM ZRdN ZSdO ZTdP ZUyQ)S	MathTests   c                 h    t        ||||      }|"| j                  dj                  ||             yy)aa  Compare 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{}: {})rY   failr'   )ra   namer)   r(   r*   r+   rV   s          r   ftestzMathTests.ftest   s6     xgw?IIhoodG45 r   c                     | j                  dt        j                  d       | j                  dt        j                  d       | j	                  t        j
                  dt        j                  z         y )Npig-DT!	@egiW
@rH   )r   rP   r   r   assertEqualtaure   s    r   testConstantszMathTests.testConstants  sH    

4"<=

3 :;1TWW9-r   c                 8   | j                  t        t        j                         | j	                  dt        j                  d      t        j
                         | j	                  dt        j                  d      t        j
                  dz         | j	                  dt        j                  d      d       | j                  t        t        j                  t               | j                  t        t        j                  t               | j                  t        t        j                  dt        z          | j                  t        t        j                  dt        z
         | j                  t        j                  t        j                  t                           y )Nzacos(-1)zacos(0)r   rH   zacos(1)r   )assertRaises	TypeErrorrP   acosr   r   ry   INFNINFeps
assertTruerT   NANre   s    r   testAcoszMathTests.testAcos
  s    )TYY/

:tyy}dgg6

9diilDGGAI6

9diilA.*dii5*dii6*diiS9*diic:

499S>23r   c                    | j                  t        t        j                         | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       | j                  t
        t        j                  d       | j                  t
        t        j                  d       | j                  t        j                  t              t               | j                  t
        t        j                  t               | j                  t        j                  t        j                  t                           y )Nzacosh(1)r   r   zacosh(2)rH   g5qB?r   )r   r   rP   acoshr   ry   r   r   r   r   rT   r   re   s    r   	testAcoshzMathTests.testAcosh  s    )TZZ0

:tzz!}a0

:tzz!}.@A*djj!4*djj"5C#.*djj$7

4::c?34r   c                 @   | j                  t        t        j                         | j	                  dt        j                  d      t        j
                   dz         | j	                  dt        j                  d      d       | j	                  dt        j                  d      t        j
                  dz         | j                  t        t        j                  t               | j                  t        t        j                  t               | j                  t        t        j                  dt        z          | j                  t        t        j                  dt        z
         | j                  t        j                  t        j                  t                           y )Nzasin(-1)r   rH   zasin(0)r   zasin(1)r   )r   r   rP   asinr   r   ry   r   r   r   r   rT   r   re   s    r   testAsinzMathTests.testAsin  s    )TYY/

:tyy}twwhqj9

9diilA.

9diilDGGAI6*dii5*dii6*diiS9*diic:

499S>23r   c                 Z   | j                  t        t        j                         | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       | j                  t        j                  t              t               | j                  t        j                  t              t               | j                  t        j                  t        j                  t                           y )	Nzasinh(0)r   zasinh(1)r   g'ya64?z	asinh(-1)r   g'ya64)r   r   rP   asinhr   r   r   r   r   rT   r   re   s    r   	testAsinhzMathTests.testAsinh*  s    )TZZ0

:tzz!}a0

:tzz!}.AB

;

20DEC#.D)40

4::c?34r   c                    | j                  t        t        j                         | j	                  dt        j                  d      t        j
                   dz         | j	                  dt        j                  d      d       | j	                  dt        j                  d      t        j
                  dz         | j	                  dt        j                  t              t        j
                  d	z         | j	                  d
t        j                  t              t        j
                   d	z         | j                  t        j                  t        j                  t                           y )Nzatan(-1)r      zatan(0)r   zatan(1)r   z	atan(inf)rH   z
atan(-inf))r   r   rP   atanr   r   r   r   r   rT   r   re   s    r   testAtanzMathTests.testAtan3  s    )TYY/

:tyy}twwhqj9

9diilA.

9diilDGGAI6

;		#	:

<4477(1*=

499S>23r   c                    | j                  t        t        j                         | j	                  dt        j
                  d      d       | j	                  dt        j
                  d      d       | j	                  dt        j
                  d      d       | j                  t        t        j
                  d	       | j                  t        t        j
                  d
       | j                  t        t        j
                  t               | j                  t        t        j
                  t               | j                  t        j                  t        j
                  t                           y )Nzatanh(0)r   z
atanh(0.5)      ?gz?zatanh(-0.5)      gzr   r   )r   r   rP   r   r   atanhry   r   r   r   rT   r   re   s    r   	testAtanhzMathTests.testAtanh<  s    )TYY/

:tzz!}a0

<C2EF

=$**T"24HI*djj!4*djj"5*djj#6*djj$7

4::c?34r   c                    | j                  t        t        j                         | j	                  dt        j                  dd      t        j
                   dz         | j	                  dt        j                  dd      t        j
                   dz         | j	                  dt        j                  dd      d       | j	                  d	t        j                  dd      t        j
                  dz         | j	                  d
t        j                  dd      t        j
                  dz         | j	                  dt        j                  dd      dt        j
                  z  dz         | j	                  dt        j                  dt              t        j
                         | j	                  dt        j                  dd      t        j
                         | j	                  dt        j                  dd      t        j
                         | j                  t        j                  dd      d       | j                  t        j                  dd      d       | j                  t        j                  dt              d       | j                  t        j                  t        j                  dt                           | j	                  dt        j                  dt              t        j
                          | j	                  dt        j                  dd      t        j
                          | j	                  dt        j                  dd      t        j
                          | j                  t        j                  dd      d       | j                  t        j                  dd      d       | j                  t        j                  dt              d       | j                  t        j                  t        j                  dt                           | j	                  dt        j                  t        t              t        j
                  dz  dz         | j	                  dt        j                  t        d      t        j
                  dz         | j	                  dt        j                  t        d      t        j
                  dz         | j	                  dt        j                  t        d      t        j
                  dz         | j	                  dt        j                  t        d      t        j
                  dz         | j	                  dt        j                  t        t              t        j
                  dz         | j                  t        j                  t        j                  t        t                           | j	                  dt        j                  t        t              t        j
                   dz  dz         | j	                  dt        j                  t        d      t        j
                   dz         | j	                  dt        j                  t        d      t        j
                   dz         | j	                  d t        j                  t        d      t        j
                   dz         | j	                  d!t        j                  t        d      t        j
                   dz         | j	                  d"t        j                  t        t              t        j
                   dz         | j                  t        j                  t        j                  t        t                           | j	                  d#t        j                  dt              t        j
                         | j	                  d$t        j                  dd      t        j
                  dz         | j	                  d%t        j                  dd      t        j
                  dz         | j                  t        j                  dt              d       | j                  t        j                  t        j                  dt                           | j	                  d&t        j                  dt              t        j
                          | j	                  d't        j                  dd      t        j
                   dz         | j	                  d(t        j                  dd      t        j
                   dz         | j                  t        j                  dt              d       | j                  t        j                  t        j                  dt                           | j                  t        j                  t        j                  t        t                           | j                  t        j                  t        j                  t        d                   | j                  t        j                  t        j                  t        d                   | j                  t        j                  t        j                  t        d                   | j                  t        j                  t        j                  t        d                   | j                  t        j                  t        j                  t        t                           | j                  t        j                  t        j                  t        t                           y ))Nzatan2(-1, 0)r   r   rH   zatan2(-1, 1)r   r   zatan2(0, 1)zatan2(1, 1)zatan2(1, 0)zatan2(1, -1)   zatan2(0., -inf)        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.))r   r   rP   atan2r   r   r   r   r   r   rT   r   re   s    r   	testAtan2zMathTests.testAtan2G  s   )TZZ0

>4::b!#4twwhqjA

>4::b!#4twwhqjA

=$**Q"2A6

=$**Q"2DGGAI>

=$**Q"2DGGAI>

>4::a#4aikB 	

$djjT&:DGGD

$djjT&:DGGD

#TZZC%8$''BB+R0B,b1B,b1

4::b##678

%tzz#t'<twwhG

%tzz#t'<twwhG

$djjc&:TWWHEC,c2C-s3C-s3

4::c3#789

%tzz#t'<dggaikJ

%tzz#t'<dggaiH

$djjd&;TWWQYG

#TZZS%947719E

$djjc&:DGGAIF

$djjc&:DGGAIF

4::c3#789

&

4(>
1M

&

4(>
K

%tzz$'=xzJ

$djjs&;dggXaZH

%tzz$'<twwhqjI

%tzz$'<twwhqjI

4::dC#89:

%tzz#t'<dggF

$djjc&:DGGAIF

#TZZR%8$''!)DC-r2

4::c3#789

&

4(>I

%tzz$'<twwhqjI

$djjr&:TWWHQJGD#.4

4::dC#89:

4::c4#89:

4::c4#89:

4::c3#789

4::c2#678

4::c3#789

4::c3#789

4::c3#789r   c                 n   | j                  t        t        j                         | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       | j	                  dt        j                  d	      d	       | j	                  d
t        j                  d      d       | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       | j                  t        j                  t              t               | j                  t        j                  t              t               | j                  t        j                  t        j                  t                           y )Nzcbrt(0)r   zcbrt(1)r   zcbrt(8)   rH   z	cbrt(0.0)r   z
cbrt(-0.0)r   z	cbrt(1.2)g333333?ggAE ?z
cbrt(-2.6)ggL]6H zcbrt(27)   r   zcbrt(-1)r   z	cbrt(-27)i)r   r   rP   cbrtr   r   r   r   r   rT   r   re   s    r   testCbrtzMathTests.testCbrt  sU   )TYY/

9diilA.

9diilA.

9diilA.

;		#4

<4$7

;		#0AB

<42DE

:tyy}a0

:tyy}b1

;		#33-4$/

499S>23r   c                 r   | j                  t        t        j                         | j	                  t
        t        t        j                  d                   | j	                  t        j                  d      d       | j	                  t        j                  d      d       | j	                  t        j                  d      d       | j	                  t        j                  d      d       | j	                  t        j                  d      d	       | j	                  t        j                  d
      d	       | j	                  t        j                  d      d       | j	                  t        j                  d      d        G d d      } G d dt              } G d d      } G d d      }| j	                  t        j                   |             d       | j	                  t        j                   |             d       | j	                  t        j                  t        d            d       | j                  t        t        j                   |              | j                  t        t        j                   |               |       }d |_
        | j                  t        t        j                  |       | j                  t        t        j                  |d       | j	                  t        j                  t        d            d       | j	                  t        j                  t        d            d       y )Nr   r         ?      ?rH   r   r         r         r   r   c                       e Zd Zd Zy)$MathTests.testCeil.<locals>.TestCeilc                      yN*   rk   re   s    r   __ceil__z-MathTests.testCeil.<locals>.TestCeil.__ceil__      r   Nrh   ri   rj   r   rk   r   r   TestCeilr         r   r   c                       e Zd Zd Zy)%MathTests.testCeil.<locals>.FloatCeilc                      yr   rk   re   s    r   r   z.MathTests.testCeil.<locals>.FloatCeil.__ceil__  r   r   Nr   rk   r   r   	FloatCeilr     r   r   r   c                       e Zd Zy)&MathTests.testCeil.<locals>.TestNoCeilNro   rk   r   r   
TestNoCeilr         r   r   c                       e Zd Z e       Zy)'MathTests.testCeil.<locals>.TestBadCeilN)rh   ri   rj   rw   r   rk   r   r   TestBadCeilr     s	    zHr   r   r   g     @E@+   c                      | S r]   rk   argss    r   <lambda>z$MathTests.testCeil.<locals>.<lambda>  s    4r   )r   r   rP   ceilr   rS   typer:   r[   ry   r   )ra   r   r   r   r   ts         r   testCeilzMathTests.testCeil  s   )TYY/d499S>233+3+3+4!,4"-4"-3+4!,
	 		 		 		" 	"8:.39;/49T?3R8)TYY
=*dii?L'
)TYY2)TYY159T?3T:9T?3T:r   c                    | j                  t        j                  dd      d       | j                  t        j                  dd      d       | j                  t        j                  dd      d       | j                  t        j                  dd      d       | j                  t        j                  d	d
      d       | j                  t        t        j                         | j                  t        j                  dd      d       | j                  t        j                  dd
      d       | j                  t        j                  t
        d      t
               | j                  t        j                  t
        d
      t               | j                  t        j                  t        d      t
               | j                  t        j                  t        d
      t               | j                  t        j                  dt
              d       | j                  t        j                  dt              d       | j                  t        j                  t
        t
              t
               | j                  t        j                  t
        t              t               | j                  t        j                  t        t
              t
               | j                  t        j                  t        t              t               | j                  t        j                  t        j                  t        d                   | j                  t        j                  t        j                  t        t
                           | j                  t        j                  t        j                  t        t                           | j                  t        j                  t        j                  t        t                           | j                  t        j                  t        j                  t
        t                           | j                  t        t        j                  dt                    d       y )Nr   r   r   r   ir   r         @      @r                @)r   rP   rQ   r   r   r   r   r   rT   r   rU   r&   re   s    r   testCopysignzMathTests.testCopysign  s   q"-s3r2.4r3/6q"-s3r3/6)T]]3r2.3r3/5sB/5sC0$7tR0#6tS148r3/4r40#6sC0#6sD148tS137tT2D9

4==b#9:;

4==c#:;<

4==d#;<=

4==c#:;< 	

4==c#:;<T]]2s34b9r   c                 X   | j                  t        t        j                         | j	                  dt        j                  t        j
                   dz        dt        j                  d             | j	                  dt        j                  d      d       | j	                  dt        j                  t        j
                  dz        dt        j                  d             | j	                  dt        j                  t        j
                        d	       	 | j                  t        j                  t        j                  t                           | j                  t        j                  t        j                  t                           | j                  t        j                  t        j                  t                           y # t        $ rU | j                  t        t        j                  t               | j                  t        t        j                  t               Y w xY w)
Nz
cos(-pi/2)rH   r   r   r+   zcos(0)z	cos(pi/2)zcos(pi)r   )r   r   rP   cosr   r   ulpr   rT   r   r   ry   r   re   s    r   testCoszMathTests.testCos  sB   )TXX.

<477(1*!5q$((1+
N

8TXXa[!,

; 3Q
L

9dhhtww/4	:OODJJtxx}56OODJJtxx~67 	

488C=12  	:j$((C8j$((D9	:s   A6G AH)(H)win32)ARMARM64zEWindows UCRT is off by 2 ULP this test requires accuracy within 1 ULPc                 F   | j                  t        t        j                         | j	                  dt        j                  d      d       | j	                  dt        j                  d      dt        j                  d      dz  z  z
  d       | j                  t        j                  t              t               | j                  t        j                  t              t               | j                  t        j                  t        j                  t                           y )Nzcosh(0)r   r   zcosh(2)-2*cosh(1)**2rH   r   )r   r   rP   coshr   r   r   r   r   rT   r   re   s    r   testCoshzMathTests.testCosh  s     	)TYY/

9diilA.

)499Q<$))A,/8I+I2N3-4#.

499S>23r   c                    | j                  t        t        j                         | j	                  dt        j                  t        j
                        d       | j	                  dt        j                  t        j
                  dz        d       | j	                  dt        j                  t        j
                   dz        d       | j	                  d	t        j                  d
      d
       y )Nzdegrees(pi)g     f@zdegrees(pi/2)rH   g     V@zdegrees(-pi/4)r   g     Fz
degrees(0)r   )r   r   rP   degreesr   r   re   s    r   testDegreeszMathTests.testDegrees  s    )T\\2

=$,,tww"7?

?DLL$;TB

#T\\477(1*%=uE

<a!4r   c                    | j                  t        t        j                         | j	                  dt        j                  d      dt        j
                  z         | j	                  dt        j                  d      d       | j	                  dt        j                  d      t        j
                         | j                  t        j                  t              t               | j                  t        j                  t              d       | j                  t        j                  t        j                  t                           | j                  t        t        j                  d       y )	Nzexp(-1)r   r   zexp(0)r   zexp(1)r   @B )r   r   rP   rD   r   r   r   r   r   r   rT   r   OverflowErrorre   s    r   testExpzMathTests.testExp  s    )TXX.

9dhhrlAdffH5

8TXXa[!,

8TXXa[$&&1#,$,

488C=12-7;r   c                    | j                  t        t        j                         | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       | j	                  d	t        j                  d
      d       | j                  t        j                  t              t               | j                  t        j                  t              d       | j                  t        j                  t        j                  t                           | j                  t        t        j                  d       y )Nzexp2(-1)r   r   zexp2(0)r   r   zexp2(1)rH   z	exp2(2.3)r   g){Ĳ@r   r   )r   r   rP   exp2r   r   r   r   r   rT   r   r   re   s    r   testExp2zMathTests.testExp2  s    )TYY/

:tyy}c2

9diilA.

9diilA.

;		#0AB3-4"-

499S>23-G<r   c                 0   | j                  t        t        j                         | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       y )Nzfabs(-1)r   r   zfabs(0)r   zfabs(1))r   r   rP   fabsr   re   s    r   testFabszMathTests.testFabs  s^    )TYY/

:tyy}a0

9diilA.

9diilA.r   c                    | j                  t        j                  d      d       d}t        dd      D ]Z  }||z  }| j                  t        j                  |      |       | j                  t        j                  |      t	        |             \ | j                  t        t        j                  d       | j                  t        t        j                  ddz          y )Nr   r     r   
   d   )r   rP   	factorialr   r$   r   ry   )ra   totalr#   s      r   testFactorialzMathTests.testFactorial  s    *A.q$AQJET^^A.6T^^A.Q@   	*dnnb9*dnnr3wh?r   c                 V   | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t        t        j                  t	        j
                  d             | j                  t        t        j                  t	        j
                  d             | j                  t        t        j                  d       y )N      @g@r   }Ô%I5z5.2)r   r   rP   r   decimalDecimalre   s    r   testFactorialNonIntegersz"MathTests.testFactorialNonIntegers"  s    )T^^S9)T^^S9)T^^T:)T^^V<)T^^W__S5IJ)T^^W__U5KL)T^^S9r   c                     | j                  t        t        j                  ddz         | j                  t        t        j                  d       y )Nr   r   }Ô%IT)r   r   rP   r   r   re   s    r   testFactorialHugeInputsz!MathTests.testFactorialHugeInputs,  s4     	-SA)T^^U;r   c                    | j                  t        t        j                         | j	                  t
        t        t        j                  d                   | j	                  t        j                  d      d       | j	                  t        j                  d      d       | j	                  t        j                  d      d       | j	                  t        j                  d      d       | j	                  t        j                  d      d       | j	                  t        j                  d	      d
        G d d      } G d dt              } G d d      } G d d      }| j	                  t        j                   |             d       | j	                  t        j                   |             d       | j	                  t        j                  t        d            d       | j                  t        t        j                   |              | j                  t        t        j                   |               |       }d |_
        | j                  t        t        j                  |       | j                  t        t        j                  |d       | j	                  t        j                  t        d            d       | j	                  t        j                  t        d            d       y )Nr   r   r   r   r   r   r   r   r   c                       e Zd Zd Zy)&MathTests.testFloor.<locals>.TestFloorc                      yr   rk   re   s    r   	__floor__z0MathTests.testFloor.<locals>.TestFloor.__floor__A  r   r   Nrh   ri   rj   r  rk   r   r   	TestFloorr
  @  r   r   r  c                       e Zd Zd Zy)'MathTests.testFloor.<locals>.FloatFloorc                      yr   rk   re   s    r   r  z1MathTests.testFloor.<locals>.FloatFloor.__floor__D  r   r   Nr  rk   r   r   
FloatFloorr  C  r   r   r  c                       e Zd Zy)(MathTests.testFloor.<locals>.TestNoFloorNro   rk   r   r   TestNoFloorr  F  r   r   r  c                       e Zd Z e       Zy))MathTests.testFloor.<locals>.TestBadFloorN)rh   ri   rj   rw   r  rk   r   r   TestBadFloorr  H  	     
Ir   r  r   g33333D@)   c                      | S r]   rk   r   s    r   r   z%MathTests.testFloor.<locals>.<lambda>Q  s    Dr   )r   r   rP   floorr   rS   r   r:   r[   ry   r  )ra   r  r  r  r  r   s         r   	testFloorzMathTests.testFloor3  s   )TZZ0d4::c?34C!,C!,C!,D)2.D)2.D)2.
	 		 		 		# 	#IK0"5JL126IdO4b9)TZZ?*djj,.AM()TZZ3)TZZA6IdO4d;IdO4d;r   c                 $   | j                  t        t        j                         | j	                  dt        j                  dd      d       | j	                  dt        j                  dd      d       | j	                  dt        j                  dd      d	       | j	                  d
t        j                  dd      d       | j	                  dt        j                  dd      d       | j	                  dt        j                  dd      d       | j                  t        j                  t        j                  t        d	                   | j                  t        j                  t        j                  d	t                           | j                  t        j                  t        j                  t        t                           | j                  t        t        j                  d	d       | j                  t        t        j                  t        d	       | j                  t        t        j                  t        d	       | j                  t        t        j                  t        d       | j                  t        j                  dt              d       | j                  t        j                  dt              d       | j                  t        j                  dt              d       | j                  t        j                  dt              d       | j                  t        j                  dd      d       | j                  t        j                  dt              d       | j                  t        t        j                  t        t               y )Nzfmod(10, 1)r   r   r   zfmod(10, 0.5)r   zfmod(10, 1.5)r   r   zfmod(-10, 1)r   zfmod(-10, 0.5)zfmod(-10, 1.5)r   r         )r   r   rP   fmodr   r   rT   r   ry   r   r   r   re   s    r   testFmodzMathTests.testFmodX  s4   )TYY/

=$))B"2C8

?DIIb#$6<

?DIIb#$6<

>499S!#4d;

#TYYsC%8$?

#TYYsC%8$?

499S"#567

499R#567

499S##678*diiR8*diib9*diir:*diib93,c24-t43-s34.53,c23-s3*diic:r   c                 |     j                  t        t        j                          fd} |dt        j                  d      d        |dt        j                  d      d        |dt        j                  d	      d
        |dt        j                  d      d        j	                  t        j                  t
              d   t
                j	                  t        j                  t              d   t                j                  t        j                  t        j                  t              d                y )Nc                     ||c\  }}\  }}t        ||z
        t        kD  s||k7  rj                  | d|d|       y y Nz
 returned z, expected r&   r   r   )r   resultr(   mantrD   emanteexpra   s          r   	testfrexpz&MathTests.testFrexp.<locals>.testfrexpr  sJ    )/&KT3%4:$t		3 4 )4r   z	frexp(-1)r   )r   r   zfrexp(0)r   r   r   zfrexp(1)r   )r   r   zfrexp(2)rH   )r   rH   )
r   r   rP   frexpr   r   r   r   rT   r   )ra   r+  s   ` r   	testFrexpzMathTests.testFrexpo  s    )TZZ0	4 	+tzz"~y9*djjmV4*djjmX6*djjmX6C+S1D)!,d3

4::c?1#567r   z2fsum is not exact on machines with double roundingc                    ddl m} |j                  |j                  z
  f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g ddft	        dd      D cg c]  }d|z  	 c}t
        j                  d      ft	        dd      D cg c]
  }d|z  |z   c}t
        j                  d      fg ddfg ddft	        ddd      D cg c]  }d|z  d|dz   z  z
  d|dz   z  z    c}dgz   t
        j                  d       fg}t	        d      D cg c]  }d!|z  	 }}|j                  t	        d"      D cg c]  }||dz      ||   z
   c}|d"    gz   |d    f       t        |      D ]0  \  }\  }}	 t        j                  |      }	| j                  	|       2 dd%lm}
m}m} t	        d"      D ]  }g d&d'z  }d}t	        d(      D ],  } |d |
             d)z  |z
  }||z  }|j                  |       .  ||        ||      }| j                   ||      t        j                  |              | j                  t        j                  dt        j$                  g      t        j$                         | j'                  t        j(                  t        j                  t        j*                  dg                   | j                  t        j                  d*t-        d      d+dd,t-        d      d-g      d       | j/                  t        t        j                  d.d.g       | j/                  t        t        j                  t        j$                  t        j$                   g       | j/                  t0        t        j                  d/g       | j/                  t0        t        j                  d       | j/                  t        t        j                  d'd"z  g       d0 }| j/                  t2        t        j                   |              y c c}w c c}w c c}w c c}w c c}w # t        $ r | j                  d#|||fz         Y t        $ r | j                  d$|||fz         Y w xY w)1Nr   )
float_infoc           	         d\  }}| D ][  }t        j                  |      \  }}t        t        j                  |	            |	z
  }}||kD  r|||z
  z  }|}n|||z
  z  }||z  }] t	        t        t        t        |                  dz
  	z
  |z
        }|dkD  r1d|dz
  z  }|d|z  z  t        ||z  xr |d|z  dz
  z        z   }||z  }t        j                  ||      S )a  Full precision summation.  Compute sum(iterable) without any
            intermediate accumulation of error.  Based on the 'lsum' function
            at https://code.activestate.com/recipes/393090-binary-floating-point-summation-accurate-to-full-p/

            r,  rH   r   r   r   )	rP   r-  rS   ldexpmaxlenbinr&   bool)
iterabletmanttexpr   r(  rD   tailhetinymant_digs
           r   msumz MathTests.testFsum.<locals>.msum  s     KE4 JJqM	c

4 :;S8^c#:d3h&EDSX%D  s3s5z?+A-8%$,GDax$q&M!A#eai.IEAaCEM)JJ::eT**r   r   )r  r   r   0.++d~QJr   d~Qr?  )r  r   r   r?  r@  r   rA  )      @Cr   g      g?C)rB  r         9g     @C)g     @Cr   rC  g     @C)g?Cr   g      <g?Cr   i  r   z0x1.df11f45f4e61ap+2r   z-0x1.62a2af1bd3624p-1)r	   r   缉ؗҜ<g7yAC)g7yACg?g7yAgi  rH   r   2   4   g      z0x1.5555555555555p+970g333333?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      rK  r  r   r@  rA  spamc               3      K   d t         wNr   )ZeroDivisionErrorrk   r   r   bad_iterz$MathTests.testFsum.<locals>.bad_iter  s     I##s   )sysr0  r=  min_expr   r:   fromhexappend	enumeraterP   fsumr   r   ry   r   rH  rI  rJ  r   r   rT   r   r[   r   r   rQ  )ra   r0  r>  r   test_valuesr#   termsvalsr(   actualrH  rI  rJ  jsvrR  r<  r=  s                    @@r   testFsumzMathTests.testFsum  s    	#&&""X-	+8 IUCL<fE:FC'5&4+\:);7!!TN+NqbdN+]]124"'4.1.QsQhqj.1]]235 34=sC7<UC7KL7K!b!eb1R4j 2":-7KL[]]346!, "'t-Aa-,1$K8KqU1Q3Z%("K8U4[L>I1XI
 	
 $-[#9AhI4 VX. $: 	21tA82=DA3Z!VX&!+a/QA   DMT
AT$Z49  	C?3TXX>

499dhh_#=>?E9S>66$()D/5$B CDJ	L-VV4DE*dii$((TXXI1FG)TYY9)TYY2-RXJ?	$ 	+TYY
Cs ,1
 M .8 ! I		 256$4GH I I		 256$4GH IIs6   PPPP;P$:P)) Q/Q/.Q/c                     t         j                  }| j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                   |dd      d	       | j                   |dd
      d	       | j                   |dd      d       d}d}dD ]  }||z  }||z  }| j                   |||      |       | j                   |||      |       | j                   || |      |       | j                   |||       |       | j                   |||       |       | j                   || |      |       | j                   || |       |       | j                   || |       |        | j                   |       d       | j                   |d      d       | j                   |d
      d       | j                   |ddd      d       | j                   |ddd      d       | j                  t        |d       | j                  t        |dd       | j                  t        |dd       | j                  t        |ddd       | j                   |t        d      t        d            d	       y )Nr   r   r   rK     x   T          j9W    P)}    "o  `T"-    l   8P9cC/[N
S9bXl	   9@{wM275k )	 l   Z'^%#>;*Q!/61^f            ^@      U@)rP   gcdr   r   r   rq   )ra   rp  r   ycabs          r   testGcdzMathTests.testGcd  s   hhQA&QA&RQ'QA&QQ'QA&QQ'S"q)S"r*R+98:;=	? O4VAAAAASAY*SAY*S!QZ+SQBZ+SQBZ+S!QZ+S!aR[!,S!aR[!,V 	"S3'TC(S"c*A.S!R!,)S%0)S%4)S#t4)S#q$7[-{2?Dr   c                 p   ddl m} ddlm} t        j
                  }t        j                  t        j                  t	        j                  d      t	        j                  d      t	        j                  d      f}t        t        |      dz         D ]@  }| j                   ||d |  t	        j                  t        d |d | D                           B | j                   |d	d
      d       | j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                   |dt!        d            d       | j                   |t!        d      d      d       | j                   | |d       |d            d       | j                   | |dd       |dd             |dd             | j                   |ddddd      d       | j                   |dd      d       | j                   |d      d       | j                   |       d       | j                  dt	        j"                  d |d                   | j                   |ddd       |ddd             | j%                  t&              5   |d       d d d        | j%                  t&              5   |ddd        d d d        d!t(        j*                  j,                  dz   z  }| j%                  t.        t0        f      5   |d|       d d d        | j                   |t2              t2               | j                   |dt2              t2               | j                   |d!t2              t2               | j                   |d"t2              t2               | j                   |t4        t2              t2               | j                   |t2        t4              t2               | j                   |t6        t4              t2               | j                   |t4        t6              t2               | j                   |t2         t2              t2               | j                   |t2         t2               t2               | j                   |d!t2               t2               | j9                  t	        j:                   |t4                           | j9                  t	        j:                   |dt4                           | j9                  t	        j:                   |t4        d!                   | j9                  t	        j:                   |d!t4                           | j9                  t	        j:                   |t4        t4                           | j9                  t	        j:                   |t4                           t<        d#z  }t        d      D ]D  }| j9                  t	        j>                   ||g|z   |t	        j                  |      z               F t        d      D ]=  }	t@        d|	z  z  }
| j                  t	        j
                  d$|
z  d%|
z        d|
z         ?  | j$                  t&        t        j
                  gdgd&z  d'  y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)(Nr   r  Fractionr         @g @r   c              3   &   K   | ]	  }|d z    yw)rH   Nrk   ).0r^  s     r   	<genexpr>z&MathTests.testHypot.<locals>.<genexpr>)  s     5HqadHs   g      (@r         *@rf  r      g      ?r   g      ?r   rj  TFr         %      %@r   r   r   r   r   皙?string皙@r   r  r   r   r      rN  )!r  r  	fractionsry  rP   hypotr   r   sqrtgammasinr   r4  assertAlmostEqualsumr   r[   rQ   r   r   rS  r0  
max_10_expry   r   r   r   r   r   rT   	FLOAT_MAXisclose	FLOAT_MIN)ra   r  ry  r  r   r#   int_too_big_for_float	fourthmaxr   rD   scales              r   	testHypotzMathTests.testHypot  s    #&

 vvtww		#

3#Ns4y{#A""tBQx 		#5D!H556 $ 	tS)40r1r*tR$/r4$/tYs^4d;y~t4d;wr{GAJ7<xB/!RA8BPRCSTtUD$=sC 	sC#.ut,#&MM#uT{+	
 	#sC #sC 	
 y)AJ *y)#x% * "s~~'@'@1'D E
M:;!*+ < 	sS)q#,r3-sC#.sC#.sC#.tS)3/sD)3/tS)3/tcT*C0rC4#. 	

5:./

5C=12

5b>23

5S>23

5c?34

5:./ O	rAOODLL)Q)@)2TYYq\)AC D 
 9Cs
*ETZZ%591U7C  	)TZZEC58EfEQ *))) <;s$   
Z<Z

Z+ZZ(+Z5z7hypot() loses accuracy on machines with double roundingc           	         t         j                  }t        j                  }t        j                  d      }dD ]  \  }}t
        j                  |      }t
        j                  |      }| j                  ||||      5  t        j                  |      5  t         ||      dz   ||      dz  z   j                               }d d d        | j                   |||             d d d         y # 1 sw Y   -xY w# 1 sw Y   xY w)N  )prec))z0x1.10e89518dca48p+29z0x1.1970f7565b7efp+30)z0x1.10106eb4b44a2p+29z0x1.ef0596cdc97f8p+29)z0x1.459c058e20bb7p+30z0x1.993ca009b9178p+29)z0x1.378371ae67c0cp+30z0x1.fbe6619854b4cp+29)z0x1.f4cd0574fb97ap+29z0x1.50fe31669340ep+30)z0x1.494b2cdd3d446p+29z0x1.212a5367b4c7cp+29)z0x1.f84e649f1e46dp+29z0x1.1fa56bef8eec4p+30)z0x1.2e817edd3d6fap+30z0x1.eb0814f1e9602p+29)z0x1.0d3a6e3d04245p+29z0x1.32a62fea52352p+30)z0x1.888e19611bfc5p+29z0x1.52b8e70b24353p+29)z0x1.538816d48a13fp+29z0x1.7967c5ca43e16p+29)z0x1.57b47b7234530p+29z0x1.74e2c7040e772p+29)z0x1.821b685e9b168p+30z0x1.677dc1c1e3dc6p+29)z0x1.9e8247f67097bp+29z0x1.24bd2dc4f4baep+29)z0x1.b73b59e0cb5f9p+29z0x1.da899ab784a97p+28)z0x1.94a8d2842a7cfp+30z0x1.326a51d4d8d8ap+30)z0x1.e930b9cd99035p+29z0x1.5a1030e18dff9p+30)z0x1.1592bbb0e4690p+29z0x1.a9c337b33fb9ap+29)z0x1.1243a50751fd4p+29z0x1.a5a10175622d9p+29)z0x1.57a8596e74722p+30z0x1.42d1af9d04da9p+30)z0x1.ee7dbd9565899p+29z0x1.7ab4d6fc6e4b4p+29)z0x1.5c6bfbec5c4dcp+30z0x1.02511184b4970p+30)z0x1.59dcebba995cap+30z0x1.50ca7e7c38854p+29)z0x1.768cdd94cf5aap+29z0x1.9cfdc5571d38ep+29)z0x1.dcf137d60262ep+29z0x1.1101621990b3ep+30)z0x1.3a2d006e288b0p+30z0x1.e9a240914326cp+29)z0x1.62a32f7f53c61p+29z0x1.47eb6cd72684fp+29)z0x1.d3bcb60748ef2p+29z0x1.3f13c4056312cp+30)z0x1.282bdb82f17f3p+30z0x1.640ba4c4eed3ap+30)z0x1.89d8c423ea0c6p+29z0x1.d35dcfe902bc3p+29)hxhyr   rq  rH   )rP   r  r  r  Contextr:   rU  subTestlocalcontextr  r   )	ra   r  r  high_precisionr  r  r   rq  zs	            r   testHypotAccuracyzMathTests.testHypotAccuracyn  s     

// c2$
FBJ b!Ab!Aa15)).9wqz1}wqz1}<BBDEA :  q!a0 65O$
P :9 65s$   >C;/C/!C;/C84C;;D	c                     ddl m} ddlm} t        j
                  }t        j                  }| j                   |dd      d       | j                   |dd      d       t        d	      D ]  }t        d
      D ]q  }t        d t        |      D              }t        d t        |      D              }| j                   |||       |t        d t        ||      D                           s  | j                   |g dg d      d       | j                   |t        g d      t        g d            d       | j                   |dd      d       | j                   |dd      d       | j                   |t        d      dfd      d       | j                   |dt        d      df      d       | j                   |dt        d      fd      d       | j                   |dd      d       | j                   | |d       |d      f |d       |d      f       |d             | j                   | |dd       |dd      f |dd       |dd      f       |dd             | j                   |dd      d        | j                   |d!d!      d"       | j                   |d#d#      d"       | j                  d$t	        j                  d$ |d%d&                   | j                  d$t	        j                  d$ |d&d%                   | j                   |d'd(       |d)d(              G d* d+t              }	| j                   | |	d      d      d       | j!                  t"              5   |dd,-       d d d        | j!                  t"              5   |d       d d d        | j!                  t"              5   |dd,d.       d d d        | j!                  t"              5   |dd       d d d        | j!                  t"              5   |d/d       d d d        | j!                  t$              5   |d0d1       d d d        | j!                  t$              5   |dd2       d d d        | j!                  t"              5   |d3d4       d d d        | j!                  t"              5   |d5d6       d d d        d7t&        j(                  j*                  d
z   z  }
| j!                  t$        t,        f      5   |d|
fd8       d d d        | j!                  t$        t,        f      5   |d8d|
f       d d d        | j!                  t"              5   |d9d       d d d        | j!                  t"              5   |dgd       d d d         G d: d;      }| j!                  t$              5   |dg |       g       d d d        t        d<      D ]Q  }t/        j.                         t/        j.                         }}| j                   ||f|f      t1        ||z
               S t2        d=d>d"d?t4        t6        g}t9        j:                  |d@A      D ]  }t9        j:                  |d@A      D ]  }t        ||      D cg c]
  \  }}||z
   }}}t=        t?        t        j@                  |            r| j                   |||      t4               et=        t?        t        jB                  |            s| jE                  t	        jB                   |||                     tF        dBz  }t        d      D ]  }|f|z  }d&|z  }| jE                  t	        jH                   |||      |t	        j                  |      z               | jE                  t	        jH                   |||      |t	        j                  |      z                t        d      D ]l  }tJ        d |z  z  }dC|z  d@|z  f}dD}| j                  t	        j
                  ||      d
|z         | j                  t	        j
                  ||      d
|z         n y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w# 1 sw Y   _xY w# 1 sw Y   ExY w# 1 sw Y   +xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w# 1 sw Y   ^xY w# 1 sw Y   3xY wc c}}w )ENr   rw  rx  )r   r   r   )r   r   r   r   r   rH   r   )r   rH   r   	   r   c              3   H   K   | ]  }t        j                  d d        ywr   NrH  uniformr|  ks     r   r}  z%MathTests.testDist.<locals>.<genexpr>       BA&..Q/    "c              3   H   K   | ]  }t        j                  d d        ywr  r  r  s     r   r}  z%MathTests.testDist.<locals>.<genexpr>  r  r  c              3   2   K   | ]  \  }}||z
  d z    yw)r   Nrk   )r|  pxqxs      r   r}  z%MathTests.testDist.<locals>.<genexpr>  s     FI&"bb2g#-Is   )      ,@r   )r   r   r~  )   r   )rH   r  r  r   )   r   r   r  r  )rH   i)r  r   rH   rj  )TTFFTT)TFTFFFr   )     *@g      )@      
r   rk   r   )r   )r   )r   r   r   )r   r   r   )r   r   r   c                       e Zd Zy)MathTests.testDist.<locals>.TNro   rk   r   r   Tr    r   r   r  )r   r   rm  pq)rK  r   r  )r  r  r  )r   rH   r   r   )r   rm  rK  )r   r   rm  rK  )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rN  )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   abcxyzr   )rH   r   r   c                       e Zd Z e       Zy)$MathTests.testDist.<locals>.BadFloatN)rh   ri   rj   rw   rf   rk   r   r   BadFloatr    r  r   r     r  r   r  r   repeatr   r   )r   r   )&r  r  r  ry  rP   distr  r   r   tupler  r  zipiterr[   rQ   r   r   ry   rS  r0  r  r   rH  r&   r   r   r   	itertoolsproductanymaprU   rT   r   r  r  r  )ra   DFr  r  r#   r]  r  r  r  r  r  valuesr  r  diffsr  r   rD   r  s                       r   testDistzMathTests.testDist  sF   (+yyyy 	o/?@#Fi4c: qA1XBqBBBqBB&&AJFC1IFFG   	o/?@#Fd?3T:J5KLcR 	k;7>gw/4y~q17;R@g	#';<bAr9S>2G<bAh0"5quadmadAbE];QrUCqRy!Ar(3a2h"b	5JK2r	$DFH	
 	224	 	b"s+MM#tGV45	
 	MM#tFG45	
 	),),	
	 	a	lZ93? y)9	* *y)O *y)Iy1 *y)AJ *y)%y1 *z*y) +z*L) +y)$g. *y) * "s~~'@'@1'D E
M:;!*+V4 <
M:;!234 <y)qM *y)!aL *	# 	# z*!xzl# + rA==?FMMOqAT1$-s1q5z: 
 tS$S9""6!4A&&va8/21ay9yVRby9s4::u-.$$T!QZ5TZZ/0OODJJtAqz$:; 9 5 O	rAq A
AOODLLaY15MNOOODLLaY15MNO	  9Cs
*E5!E'"AATYYq!_ag6TYYq!_ag6 y *)))))))))****)))) <;;;)))) +* :s   4a	aa*
a+
a88
b
b
b-
b,:b9)c
c9c +c-;c:
aaa(+a58bbbb),b69ccc c*-c7c                     | j                  t              5  t        j                  ddgg d       d d d        y # 1 sw Y   y xY w)Nr   rH   )r   r   r   )r   ry   rP   r  re   s    r   test_math_dist_leakzMathTests.test_math_dist_leak.  s.    z*IIq!fi( +**s	   :Ac           	         t        t        d            t        t        dd            z   t        dd      D cg c]  }t        dd      D ]
  }d|z  |z     c}}z   d	d
z  ddz  gz   }|D ]  }| j                  |      5  t        j                  |      }| j                  t        |      t               | j                  ||z  |       | j                  ||dz   |dz   z         d d d         | j                  t              5  t        j                  d       d d d        t        j                  d      }| j                  t        |      t               | j                  |d       t        j                  d      }| j                  t        |      t               | j                  |d        G d dt              }t        j                   |d            }| j                  t        |      t               | j                  |d       | j                  t              5  t        j                   |d             d d d        ddt        j                  d      dddg}|D ]P  }| j                  |      5  | j                  t               5  t        j                  |       d d d        d d d        R y c c}}w # 1 sw Y   XxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   @xY w# 1 sw Y   xY w)Nr   iX> i(F <   rL  i(   rH   r   i'  r   i  r^   r   r   TFr   c                       e Zd Zd Zd Zy)(MathTests.testIsqrt.<locals>.IntegerLikec                     || _         y r]   r^   r`   s     r   rb   z1MathTests.testIsqrt.<locals>.IntegerLike.__init__Q  s	    "
r   c                     | j                   S r]   r^   re   s    r   rt   z2MathTests.testIsqrt.<locals>.IntegerLike.__index__T  s    zz!r   Nru   rk   r   r   IntegerLiker  P  s    #"r   r  i  r  r   rz  za stringz3.5y              @g      Y@r   )listr   r  rP   isqrtassertIsr   rS   assertLessEqual
assertLessr   ry   r   objectr  r  r   )ra   r   r#   rY  r_   r^  r  
bad_valuess           r   	testIsqrtzMathTests.testIsqrt3  sa    t5|456!&r3HAsBAq!taxxHI $wD!" 	 !EE*JJu%d1gs+$$QqS%0!ac{3	 +* ! z*JJrN + JJtd1gs#AJJud1gs#A	"& 	" JJ{4()d1gs#Bz*JJ{2' +
 W__U3T4

  EE*&&y1JJu% 2 +*  W I
 +* +*. +* 21 +*sN    J4A%J:KK5K,K !K,:K	KK K)%K,,K5	c                 0   t         j                  }| j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                   |dd	      d
       | j                   |d	d      d
       | j                   |dd      d       d}d}dD ]  }||z  }||z  }||z  |z  }| j                   |||      |       | j                   |||      |       | j                   || |      |       | j                   |||       |       | j                   |||       |       | j                   || |      |       | j                   || |       |       | j                   || |       |        | j                   |       d       | j                   |d      d       | j                   |d      d       | j                   |dd	d      d       | j                   |ddd	      d       | j                  t        |d       | j                  t        |dd	       | j                  t        |dd       | j                  t        |ddd       | j                   |t        d      t        d	            d
       y )Nr   r   r   rK  rb  rc  iY  rd  re  iH  rg  rh  ri  l    ,`aUx-xB:Vn
Ldbl   me%Y% l   };T^	 )rk  l   |/Kr2 rl  i7  rn  ro  )rP   lcmr   r   r   rq   )ra   r  r   rq  rr  rs  rt  ds           r   test_lcmzMathTests.test_lcmh  s   hhQA&QA&RQ'QA&QQ'QA&QQ'S"s+S"s+R,98:R	T ! (AAAAAA	ASAY*SAY*S!QZ+SQBZ+SQBZ+S!QZ+S!aR[!,S!aR[!,( 	"S3'TC(S"c*E2S!R!,)S%0)S%4)S#t4)S#q$7[-{2?Er   c           	      	   | j                  t        t        j                         | j                  t        t        j                  dd       | j	                  dt        j                  dd      d       | j	                  dt        j                  dd      d       | j	                  dt        j                  dd	      d
       | j	                  dt        j                  d	d      d       | j                  t
        t        j                  dd       | j                  t
        t        j                  dd       | j                  t        j                  dd      d       | j                  t        j                  dd      d       | j                  t        j                  t        d      t               | j                  t        j                  t        d      t               | j                  t        j                  t        j                  t        d                   dddddz  fD ]j  }| j                  t        j                  t        |       t               | j                  t        j                  t        |       t               | j                  t        j                  d|       d       | j                  t        j                  d|       d       | j                  t        j                  d|       d       | j                  t        j                  d|       d       | j                  t        j                  t        j                  t        |                    | j                  t
        t        j                  d|       | j                  t
        t        j                  d|       | j                  t        j                  d|      d       | j                  t        j                  d|      d       | j                  t        j                  t        |      t               | j                  t        j                  t        |      t               | j                  t        j                  t        j                  t        |                   m y )Nr   r  z
ldexp(0,1)r   r   z
ldexp(1,1)rH   zldexp(1,-1)r   r   zldexp(-1,1)r  r   r   r   ir   r      i+順     d(	       Fx:^V r   r  )r   r   rP   r2  r   r   r   r   r   r   rT   r   ra   r   s     r   	testLdexpzMathTests.testLdexp  s   )TZZ0)TZZc:

<Aa!4

<Aa!4

=$**Qr"2C8

=$**R"2B7-RA-S'BB126C2C8C,c2D$/6

4::c1#567 R0ATZZaR0#6TZZqb148TZZQB/4TZZaR0#6TZZQB/4TZZaR0#6OODJJtzz#r':;<mTZZQ?mTZZa@TZZA.3TZZQ/5TZZQ/5TZZa0$7OODJJtzz#q'9:; 1r   c                    | j                  t        t        j                         | j                  t        t        j                  ddd       | j	                  dt        j                  dt        j
                  z        d       | j	                  dt        j                  d      d       | j	                  dt        j                  t        j
                        d       | j	                  d	t        j                  d
d      d       | j	                  dt        j                  ddz  d      d       | j	                  dt        j                  ddz  d      d       | j	                  dt        j                  ddz        d       | j                  t        t        j                  d       | j                  t        t        j                  ddz          | j                  t        t        j                  dd       | j                  t        t        j                  t               | j                  t        j                  t              t               | j                  t        j                  t        j                  t                           y )Nr   rH   r   zlog(1/e)r   zlog(1)r   zlog(e)z	log(32,2)rj  r   zlog(10**40, 10)r   r  zlog(10**40, 10**20)r  zlog(10**1000)r   gO+@r   r  )r   r   rP   logr   r   ry   r   r   r   r   rT   r   re   s    r   testLogzMathTests.testLog  s   )TXX.)TXXq!Q7

:txx$&&126

8TXXa[!,

8TXXdff-q1

;A2

$dhhr2vr&:B?

($((2r66*BAF

?DHHRX$6%	'*dhh5*dhhT	:*dhhC8*dhh5#,

488C=12r   c           	         | j                  t        t        j                         dddz  ddz  fD ]C  }| j	                  t        j                  |      t        j                  t        |                   E | j                  t        t        j                  d       | j                  t        j                  t              t               y )NrH   Z   i,  r   )	r   r   rP   log1pr  r:   ry   r   r   r  s     r   	testLog1pzMathTests.testLog1p  s    )TZZ0QUAsF#A""4::a=$**U1X2FG $*djj"5C#.r   c                 ,   | j                  t        t        j                         | j	                  t        j                  d      d       | j	                  t        j                  d      d       | j	                  t        j                  d      d       | j	                  t        j                  ddz        d       | j	                  t        j                  dd	z        d
       | j	                  t        j                  ddz        d       | j                  t
        t        j                  d       | j                  t
        t        j                  t               | j                  t        j                  t        j                  t                           y )Nr   r   rH   r   r   r   i  g     @   g      @i  g     @@r   )
r   r   rP   log2r   ry   r   r   rT   r   re   s    r   testLog2zMathTests.testLog2  s   )TYY/ 	1s+1s+1s+ 	1d7+V41d7+V41d7+V4*dii6*dii6

499S>23r   r   c           	          t        dd      D cg c]+  }t        j                  t        j                  d|            - }}t        dd      D cg c]  }t	        |       }}| j                  ||       y c c}w c c}w )NrE  r  r   )r   rP   r  r2  r:   r   )ra   r   r\  r(   s       r   testLog2ExactzMathTests.testLog2Exact  so    
 :?ud9KL9KA$))DJJsA./9KL&+E4&89&8E!H&89* M9s   0A6A;c                 @   | j                  t        t        j                         | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       | j	                  d	t        j                  dd
z        d       | j                  t
        t        j                  d       | j                  t
        t        j                  dd
z          | j                  t
        t        j                  t               | j                  t        j                  t              t               | j                  t        j                  t        j                  t                           y )Nz
log10(0.1)皙?r   zlog10(1)r   r   z	log10(10)r   zlog10(10**1000)r   g     @@r   )r   r   rP   log10r   ry   r   r   r  r   r   rT   r   re   s    r   	testLog10zMathTests.testLog10  s    )TZZ0

<C"5

:tzz!}a0

;

22

$djjT&:FC*djj$7*djj2t8)<*djj$7#,

4::c?34r   c                 d   t         j                  }t        j                  }t        j
                  }| j                   |t        g d      d      d       | j                   |ddgddg      d       | j                   |g g       d	       | j                   |d
gdg      d
       | j                   |dgd
g      d
       dd |dd       |dd      f |d       |d      fdd |dd      fd |dd      fd |d      ffD ]  }||f||d d d
   ffD ]~  \  }}| j                  ||      5  t        d t        ||d      D              } |||      }| j                  ||       | j                  t        |      t        |             d d d          | j                  t        |       | j                  t        |g        | j                  t        |g g g        | j                  t        |d dg       | j                  t        |dgd        | j                  t        |dgdg       | j                  t        |ddgdg       | j                  t        |dgddg       | j                   |dgdg      d       | j                   |dgdg      d       | j                   |dgdg      d       | j                   |dgdz  dgdz        d       | j                  t        |dd z  gdg       | j                  t        |dgdd z  g       d! }	| j                  t               5   |t#        d       |	d             d d d        | j                  t               5   | |	d      t#        d             d d d        d	d"lm}
 | j                   | |
d      dg      d	       | j                   |dg |
d            d	        G d# d$      }| j                  t               5   |d |       dgg d       d d d        | j                  t               5   |g dd |       dg       d d d        | j                  t              5   |d%dgddg       d d d        | j                  t              5   |ddgd%dg       d d d        | j                   |d&t         j(                  gd'd(g      t         j(                         | j                   |d&t         j(                  gt         j(                  d(g      t         j(                         | j                   |d&t         j(                  gt         j(                  t         j(                  g      t         j(                         | j                   |d&t         j(                   gd'd(g      t         j(                          | j+                  t        j,                   |d&t         j(                  gt         j(                   t         j(                  g                   | j+                  t        j,                   |d&t         j.                  gd'd(g                   | j+                  t        j,                   |d&t         j(                  gt         j.                  d(g                   | j+                  t        j,                   |d&t         j(                  gd)t         j.                  g                   d*}| j                   || d+       y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w),N)r   r  r  r     r         @rz  g      @g     0@r   r   r   )r   g      r   r   r   )r  r      r  c              3   ,   K   | ]  \  }}||z    y wr]   rk   )r|  p_iq_is      r   r}  z(MathTests.testSumProd.<locals>.<genexpr>  s     "T=Sc39=Ss   Tstrictr   r   r  r  r  r   r  i r  l     9V r   c              3   >   K   t        |       D ]  }|  t        wr]   )r   RuntimeError)r   r#   s     r   raise_afterz*MathTests.testSumProd.<locals>.raise_after(  s     1X s   )BasicIterClassc                       e Zd Zd Zd Zy)*MathTests.testSumProd.<locals>.BadMultiplyc                     t         r]   r  ra   others     r   __mul__z2MathTests.testSumProd.<locals>.BadMultiply.__mul__8      ""r   c                     t         r]   r  r  s     r   __rmul__z3MathTests.testSumProd.<locals>.BadMultiply.__rmul__:  r  r   N)rh   ri   rj   r  r  rk   r   r   BadMultiplyr  7  s    ##r   r  r  g333333$@g3333334@gL>@gL4@))r  r  r   )r                           r   )rP   sumprodr  r  r  ry  r   r  r  r  r  r   r   r   ry   r   r  r   test.test_iterr  r   r   rT   r   )ra   r  r  ry  r_  r  r  r(   r\  r  r  r  r   s                r   testSumProdzMathTests.testSumProd  s   ,,//%% 	l!3Y?E#sc3Z8$?R!,"t,b1"t,b1 a^Xa^,S\73<((1a.!!Q 	
A Q!QttW.1\\A\+""TSAd=S"TTH$Q]F$$Xv6$$T(^T&\B	 ,+ /	
$ 	)W-)Wb1)Wb"b9)WdRD9)WrdD9)WsecU; 	*gBx">*gtb"X> 	&A3/8!vh/8&F84f=%>G-2t8*seD-3%"d(D	 |,E"I{1~. -|,KNE"I. - 	2!2QC8!<!nQ&78!<	# 	#
 |,R+Y7 -|,IKM267 - y)UAJB( *y)QGeQZ( * 	$!1D$<@$((K$!1DHHd3CDdhhO$!1DHHdhh3GH$((S$	!2T4LADHH9M

7D$((+;txxi=R#STU

7D$((+;dD\#JKL

7D$((+;dhh=M#NOP

7D$((+;dDHH=M#NOP O$-M ,+> -,,, -,,, *)))sU   -A[#[$[1[>\\,\%[!$[.1[;>\\\"%\/zBsumprod() accuracy not guaranteed on machines with double roundingc                 ,   t         j                  }| j                   |dgdz  dgdz        d       | j                   |dgdz  ddgdz        d       | j                   |ddgdz  dgdz        d       | j                   |g ddgd	z        d
       y )Nr  r   r   r   r  TF)r   g\nTr   g\nr   r   )rP   r  r   )ra   r  s     r   test_sumprod_accuracyzMathTests.test_sumprod_accuracyV  s    
 ,,#aSV4c:#dE]R-?@#F$!3cURZ@#F!<seAgFLr   cpuc                 P   t         j                  }t        j                  }t        j
                  }t        j                  } G fddt               G fddt              }d }d }ddd	d
dddddz  d d      f
ddddz  z  dddz  z  dddz  z  dddddddz  f	dd d!t        d"      t        d"       t        d#      d$d%d& |d'      d(fd)d* |d+       |d,       |d'd-       |d.d/      d0d1d2 d      f
 |d3       |d4       |d5       |d6       |d7       |d7        |d#      d8d9f	d:dddz  z  ddd;d<d=d>fd?d@dAdBdCdDdEd dF      fg	}|D ]U  }	t        dG      D ]E  }
 ||	|
H      D ]6  } ||	|
H      D ]'  }||f}| j                   ||g|  ||g| |       ) 8 G W y )INc                   0    e Zd Z fdZ fdZeZeZd Zy)*MathTests.test_sumprod_stress.<locals>.Intc                 >     t        |       t        |      z         S r]   rS   ra   r  Ints     r   __add__z2MathTests.test_sumprod_stress.<locals>.Int.__add__i      3t9s5z122r   c                 >     t        |       t        |      z        S r]   r%  r&  s     r   r  z2MathTests.test_sumprod_stress.<locals>.Int.__mul__k  r)  r   c                      dt        |        dS )NzInt()r%  re   s    r   __repr__z3MathTests.test_sumprod_stress.<locals>.Int.__repr__o      c$i[**r   Nrh   ri   rj   r(  r  __radd__r  r-  r'  s   r   r'  r#  h      33HH+r   r'  c                   0    e Zd Z fdZ fdZeZeZd Zy)*MathTests.test_sumprod_stress.<locals>.Fltc                 >     t        |       t        |      z         S r]   r%  r&  s     r   r(  z2MathTests.test_sumprod_stress.<locals>.Flt.__add__s  r)  r   c                 >     t        |       t        |      z        S r]   r%  r&  s     r   r  z2MathTests.test_sumprod_stress.<locals>.Flt.__mul__u  r)  r   c                      dt        |        dS )NzFlt(r,  r%  re   s    r   r-  z3MathTests.test_sumprod_stress.<locals>.Flt.__repr__y  r.  r   Nr/  r1  s   r   Fltr4  r  r2  r   r8  c                 F    d}t        | |d      D ]  \  }}|||z  z  } |S )zThis defines the target behavior including exceptions and special values.
            However, it is subject to rounding errors, so float inputs should be exactly
            representable with only a few bits.
            r   Tr  )r  )r  r  r   r  r  s        r   baseline_sumprodz7MathTests.test_sumprod_stress.<locals>.baseline_sumprod|  s3    
 E1T2Ss" 3Lr   c                     	  | | }dt        |      t	        |      fS # t         t        f$ r  t        $ r}t        |      ddfcY d}~S d}~ww xY w)zHMake comparing functions easier. Returns error status, type, and result.NNone)AssertionError	NameError	Exceptionr   repr)funcr   r'  r   s       r   runz*MathTests.test_sumprod_stress.<locals>.run  sZ    -t
 ftF|33	 #I.  -Awf,,-s    AA	A	Ar  r   i  l        l        r  r  rH   P   r   rK  )	      @g      g      @     &@g     y@g      ?      ?r   g            3r  r  r   r   i  i:,  rD  r  g      8r   i  g      @r  r   r   NaNr  r  y      @      @r  r   r  g      z10.5z-2.25r   i   y      @      ?a   iz6.125z12.375z-2.75r   Infrf  g      +@g      pl     g      pg      `g      )g      <g         rG  g      rE  g      g      g     `7@TFr   r   r  )rP   r  r  r  r  r  r  ry  rS   r:   r   r   )ra   r  r  r  ry  r8  r:  rB  poolspoolsizeargs1args2r   r'  s                 @r   test_sumprod_stresszMathTests.test_sumprod_stressa  s   ,,##//%%	+# 	+	+% 	+		4 VUE5%BSVLM1c6\2ag:r!T'z8UNQ383eElU5\M5<4R#'E76?GG,<hr1o#r"M2sCFDWwx0''2BGAJ'%.'%."dLBq$wJ1iZAE6643q6B
" Da$T$7E!(d!; %u~(( 0848/$/  "< 8 ! r   c           	      R  	
 dd l ddlm ddlm ddlm} ddlmm	m
 ddlmmm ddlm}  |dd	      fd
fdd f	d	fd
	
fdd}dd |fdt#        |      D              }| j%                  |d       y )Nr   rx  )starmap)
namedtuple)r  r   r   )choicesr  rJ  )median
DotExample)r   rq  target_sumprod	conditionc           
          t        |       }t        |      }t         j                  t        ||d                  S )NTr  )r  r  mulr  )r   rq  vec1vec2ry  operatorrT  s       r   DotExactzDMathTests.test_sumprod_extended_precision_accuracy.<locals>.DotExact  s:    x#Dx#Dwx||StD-IJKKr   c                 z    d t        t        |       t        t        |            z  t         | |            z  S )Nr   )r  r&   )r   rq  r`  s     r   	ConditionzEMathTests.test_sumprod_extended_precision_accuracy.<locals>.Condition  s1    #c1+s3{;;c(1a.>QQQr   c                 `    || z
  |dz
  z  }t        |      D cg c]
  }| ||z  z    c}S c c}w Nr   )r   )lohir   widthr#   s        r   linspacezDMathTests.test_sumprod_extended_precision_accuracy.<locals>.linspace  s8    "WQ'E,1!H5HqBNH555s   +c                   	 | dk\  sJ | dz  }dg| z  }dg| z  } |      } t        t        |dz              |      }t        |dz        dz   |d<   d|d<   |D cg c]  } dd	       |      z   c}|d
| |D cg c]  } dd	       |      z   c}|d
| t        t        t         |dz  d| |z
                    }t        ||       D ]H  } dd	       |||z
           z  ||<    dd	       |||z
           z   ||      z
  ||   z  ||<   J t        t        ||            }	 |	       t        |	 \  }} || ||       
||            S c c}w c c}w )a   Algorithm 6.1 (GenDot) works as follows. The condition number (5.7) of
            the dot product xT y is proportional to the degree of cancellation. In
            order to achieve a prescribed cancellation, we generate the first half of
            the vectors x and y randomly within a large exponent range. This range is
            chosen according to the anticipated condition number. The second half of x
            and y is then constructed choosing xi randomly with decreasing exponent,
            and calculating yi such that some cancellation occurs. Finally, we permute
            the vectors x, y randomly and calculate the achieved condition number.
            rm  rH   r   )r  r   r   r   r   r   N)r   rS   r  r  roundr  )r   rr  n2r   rq  rt  r   r  r#   pairsrb  r`  rX  rV  r   rh  r  rJ  r  s             r   GenDotzBMathTests.test_sumprod_extended_precision_accuracy.<locals>.GenDot  s    6M6aB	A	AQA c!A#h2.Aq1u:>AaDAbE<=>AqgdC(472A>AcrF<=>AqgdC(472A>AcrF S1cAbD 9:;A2q\tS)D1r6O;!c*T!AF)_<x1~MQRSTQUU! "
 QOEEN;DAqaHQNIaODD ?>s   EE$c                 p    |\  }}}} t        |      |  gz   t        |      dgz         } ||z        S rd  )r  )	resexr   rq  rY  rZ  r   r`  r   s	          r   RelativeErrorzIMathTests.test_sumprod_extended_precision_accuracy.<locals>.RelativeError  sD    .0+Aq.)aSD6)47aS=9AN*++r   c                 b     d|      } | |j                   |j                        } ||      S )Nr   )r   rq  )dotfuncrr  r   rp  ro  rm  rq  s        r   TrialzAMathTests.test_sumprod_extended_precision_accuracy.<locals>.Trial  s/    AB"$$%C b))r   r   r  gꌠ9Y>)Fc              3   N   K   | ]  } t         j                          y wr]   )rP   r  )r|  r#   rt  rr  r   s     r   r}  zEMathTests.test_sumprod_extended_precision_accuracy.<locals>.<genexpr>  s     NAeDLL!Q7s   "%rD  )r_  r  ry  r  rT  collectionsrU  rP   r  r   r   rH  rV  r  rJ  
statisticsrW  r   r  )ra   rU  rW  timesrelative_errrb  r`  rX  ry  rm  rq  rt  rr  rV  r   r   rh  r  r   r_  rJ  rT  r  s        @@@@@@@@@@@@@@@@@@r   (test_sumprod_extended_precision_accuracyz2MathTests.test_sumprod_extended_precision_accuracy  s     	&%*))44%.WX
	L
	R	6$	E $	EL	,
	*
  NuNNe,r   c                 V     j                  t        t        j                          fd} |dt        j                  d      d        |dt        j                  d      d        j	                  t        j                  t
              dt
        f        j	                  t        j                  t              d	t        f       t        j                  t              } j                  t        j                  |d
                 j                  t        j                  |d                y )Nc                     ||c\  }}\  }}t        ||z
        t        kD  st        ||z
        rj                  | d|d|       y y r%  r&  )r   r'  r(   v1v2e1e2ra   s          r   testmodfz$MathTests.testModf.<locals>.testmodf  sN    !'HRhr22b5zC3r"u:		3 4 $.r   z	modf(1.5)r   )r   r   z
modf(-1.5)r   )r   r   r   r   r   r   )
r   r   rP   modfr   r   r   r   r   rT   )ra   r  modf_nans   `  r   testModfzMathTests.testModf  s    )TYY/	4 	diinj9tyy=3#s444,799S>

8A;/0

8A;/0r   c                 %   | j                  t        t        j                         | j	                  dt        j                  dd      d       | j	                  dt        j                  dd      d       | j	                  dt        j                  dd      d       | j	                  dt        j                  dd      d	       | j                  t        j                  t        d      t               | j                  t        j                  t        d      t               | j                  t        j                  dt              d
       | j                  t        j                  dt              d
       | j                  t        j                  t        j                  t        d                   | j                  t        j                  t        j                  dt                           | j                  t        j                  t        j                  dt                           | j                  t        j                  dt              d       | j                  t        t        j                  dd       | j                  t        j                  dt              d       | j                  t        j                  dd      d       | j                  t        j                  dd      d       | j                  t        j                  dd      d       | j                  t        j                  dd      d
       | j                  t        j                  dd      d
       | j                  t        t        j                  dd       | j                  t        t        j                  dd       | j                  t        t        j                  dd       | j                  t        j                  dt              t               | j                  t        j                  t        j                  dt                           | j                  t        j                  t        t              t               | j                  t        j                  t        d      t               | j                  t        j                  t        d      t               | j                  t        j                  t        d      t               | j                  t        j                  t        d      d
       | j                  t        j                  t        d      d
       | j                  t        j                  t        d      d       | j                  t        j                  t        d      d       | j                  t        j                  t        d      d       | j                  t        j                  t        t              d       | j                  t        j                  t        j                  t        t                           | j                  t        j                  dt              d       | j                  t        j                  dd      d       | j                  t        j                  dd      d       | j                  t        j                  dd      d       | j                  t        j                  dd      d
       | j                  t        j                  dd      d
       | j                  t        t        j                  dd       | j                  t        t        j                  dd       | j                  t        t        j                  dd       | j                  t        j                  dt              t               | j                  t        j                  t        j                  dt                           | j                  t        j                  t        t              t               | j                  t        j                  t        d      t               | j                  t        j                  t        d      t               | j                  t        j                  t        d      t               | j                  t        j                  t        d      d
       | j                  t        j                  t        d      d
       | j                  t        j                  t        d      d       | j                  t        j                  t        d      d       | j                  t        j                  t        d      d       | j                  t        j                  t        t              d       | j                  t        j                  t        j                  t        t                           | j                  t        j                  dt              d
       | j                  t        j                  dd      d       | j                  t        t        j                  dd       | j                  t        j                  dd      d
       | j                  t        j                  dd      d
       | j                  t        j                  dd      d
       | j                  t        j                  dd      d
       | j                  t        t        j                  dd       | j                  t        j                  dd      d       | j                  t        j                  dt              d
       | j                  t        j                  t        j                  dt                           | j                  t        j                  d
t              d
       | j                  t        j                  d
d      d
       | j                  t        j                  d
d      d
       | j                  t        j                  d
d      d
       | j                  t        j                  d
d      d
       | j                  t        j                  d
d      d
       | j                  t        j                  d
d      d
       | j                  t        j                  d
d      d
       | j                  t        j                  d
d      d
       | j                  t        j                  d
t              d
       | j                  t        j                  d
t              d
       | j                  t        j                  dd      d
       | j                  t        j                  dd      d
       | j                  t        j                  t        d      d
       | j                  t        j                  dd      d
       | j                  t        j                  dd      d
       | j                  t        j                  t        d      d
       | j                  t        t        j                  dd       | j                  t        t        j                  dd       | j                  t        j                  dt              d       | j                  t        j                  dt              d       | j                  t        j                  dt              t               | j                  t        j                  dt              t               | j                  t        j                  dt              t               | j                  t        j                  dt              t               | j                  t        j                  dt              d       | j                  t        j                  dt              d       | j                  t        j                  dt              t               | j                  t        j                  dt              t               | j                  t        j                  dt              d       | j                  t        j                  dt              d       | j                  t        j                  dt              d       | j                  t        j                  dt              d       | j                  t        j                  dt              t               | j                  t        j                  dt              t               | j	                  dt        j                  dd      d        | j	                  d!t        j                  dd      d"       | j	                  d#t        j                  dd
      d       | j	                  d$t        j                  dd      d
       | j	                  d%t        j                  dd      d
       | j	                  d&t        j                  dd      d'       | j	                  d(t        j                  dd      d)       | j	                  d*t        j                  dd      d+       | j                  t        t        j                  dd'       | j                  t        t        j                  dd	       y ),Nzpow(0,1)r   r   zpow(1,0)zpow(2,1)rH   z	pow(2,-1)r   r   r   r  r   r   r   r   r   g       r   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.r   z
(-2.)**-2.rF  z
(-2.)**-3.g      )r   r   rP   powr   r   r   r   r   rT   r   r   ry   re   s    r   testPowzMathTests.testPow  s   )TXX.

:txx!}a0

:txx!}a0

:txx!}a0

;24#q)3/$*D1$((1c*R0$((1d+b1

488C#345

488As#345

488As#345!S)1--66B 	"c*B/"b)2."c*B/"b)2."b)2."c*B/*dhhC8*dhhD9*dhhC8"d+S1

488B#456 	#s+S1#r*C0#s+S1#r*C0#r*B/#s+R0#s+R0#t,b1#s+R0#t,b1

488C#567 	#s+R0#r*C0#s+R0#r*B/#r*B/#s+R0*dhhS9*dhhT:*dhhS9#t,c2

488C#567 	$,c2$+T2$,c2$+S1$+R0$,b1$,b1$-r2$,c2$-r2

488D##678 	#s+R0#r*C0*dhhS9#r*B/#r*B/#s+R0#s+R0*dhhT:#s+S1#t,b1

488C#567 	"c*B/"b)2."c*B/"b)2."b)2."c*B/"c*B/"d+R0"c*B/"d+R0"c*B/ 	#r*B/$+R0#r*B/#s+R0$,b1#s+R0 	*dhhS9*dhhd; 	#t,b1#t,b1#t,c2#t,c2$-s3$-s3$-r2$-r2 	#s+S1#s+S1#s+R0#s+R0$,b1$,b1$,c2$,c2 	

;s 3T:

;s 3S9

;s 3T:

;s 3S9

<$!5s;

<$!5t<

<$!5t<

<$!5v>*dhhd;*dhhc:r   c                    | j                  t        t        j                         | j	                  dt        j                  d      t        j
                         | j	                  dt        j                  d      t        j
                  dz         | j	                  dt        j                  d      t        j
                   dz         | j	                  d	t        j                  d
      d
       y )Nzradians(180)   zradians(90)r  rH   zradians(-45)ir   z
radians(0)r   )r   r   rP   radiansr   r   re   s    r   testRadianszMathTests.testRadians  s    )T\\2

>4<<#4dgg>

=$,,r"2DGGAI>

>4<<#4twwhqjA

<a!4r   c                     ddl m  fd}g d}|D ]  } j                  |      5  |j                         \  }}}t        j                  |      }t        j                  |      }t        j                  |      }	 ||||	       t        j                  ||      }
 j                  |
j                         |	j                                d d d         t        j                  d      }t        dd      D ]d  }|dk(  r	||z  }t        d	      D ]I  }||z  }t        j                  ||      }
 ||||
       t        j                  | |      }
 || ||
       K f t        d
dddt        t        fD ]T  } j                  t        j                  t        |              j                  t        j                  |t                     V dD ]V  } j                  t        j                  |t              |        j                  t        j                  |t              |       X t        ddd
dt        fD ]  } j                  t               5  t        j                  t        |       d d d         j                  t               5  t        j                  t        |       d d d         j                  t               5  t        j                  |d
       d d d         j                  t               5  t        j                  |d       d d d         y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   exY w# 1 sw Y   xY w)Nr   rx  c                 B    |        |       |      }}}j                  t        |      t        |dz               ||z
  |z  }j                  |t        |             t        |      t        |dz        k(  r"j                  |dz  t        |dz               yy)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.
            rH   N)r  r&   r   rS   )	r   rq  rfxfyfrr   ry  ra   s	          r   validate_specz.MathTests.testRemainder.<locals>.validate_spec  s    
 "!hqk8A;BB  R#bd)4bBAQA'2w#bd)#  1c!A#h/ $r   )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-1074ir  r   r   r   r   r   )r   r   r   r   r   )r  ry  r  r9   r:   rU  rP   	remainderr   hexr   r   r   r   assertIsNaNr   ry   )ra   r  	testcasesr  x_hexy_hexexpected_hexr   rq  r(   r\  tinyr   mr_   ry  s   `              @r   testRemainderzMathTests.testRemainder  s   &	0 9
	v D4(-1ZZ\*ulMM%(MM%( ==6aH-1-   x||~> )(  }}Y'sBAAvDA3ZH1-aF+A.qb!V,  	   3c4s;ET^^C78T^^E378 <
 ,ET^^E37?T^^E48%@ , D$S#6E"":.sE* /"":.tU+ /"":.uc* /"":.ud+ /. 7O )(P /.......s<   B"LL L,=L81ML	 L)	,L5	8M	M	c                    | j                  t        t        j                         | j	                  dt        j                  d      d       | j	                  dt        j                  t        j
                  dz        d       | j	                  dt        j                  t        j
                   dz        d       	 | j                  t        j                  t        j                  t                           | j                  t        j                  t        j                  t                           | j                  t        j                  t        j                  t                           y # t        $ rU | j                  t        t        j                  t               | j                  t        t        j                  t               Y w xY w)Nzsin(0)r   z	sin(pi/2)rH   r   z
sin(-pi/2)r   )r   r   rP   r  r   r   r   rT   r   r   ry   r   re   s    r   testSinzMathTests.testSin5     )TXX.

8TXXa[!,

; 3Q7

<477(1*!5r:	:OODJJtxx}56OODJJtxx~67 	

488C=12  	:j$((C8j$((D9	:   ;A6E- -AG
Gc                    | j                  t        t        j                         | j	                  dt        j                  d      d       | j	                  dt        j                  d      dz  t        j
                  d      dz  z
  d       | j	                  dt        j                  d      t        j                  d      z   d       | j                  t        j                  t              t               | j                  t        j                  t              t               | j                  t        j                  t        j                  t                           y )Nzsinh(0)r   zsinh(1)**2-cosh(1)**2r   rH   r   zsinh(1)+sinh(-1))r   r   rP   sinhr   r   r   r   r   r   rT   r   re   s    r   testSinhzMathTests.testSinhB  s    )TYY/

9diilA.

*DIIaL!ODIIaL!O,KRP

%tyy|DIIbM'A1E3-4$/

499S>23r   c                    | j                  t        t        j                         | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       | j	                  dt        j                  d      d	       | j	                  d
t        j                  d      d       | j	                  dt        j                  d      d       | j	                  dt        j                  d      d       | j                  t        j                  t              t               | j                  t        t        j                  d       | j                  t        t        j                  t               | j                  t        j                  t        j                  t                           y )Nzsqrt(0)r   r   z	sqrt(2.5)r  gS[:XL?z
sqrt(0.25)rF  r   zsqrt(25.25)g     @9@g)#L@zsqrt(1)r   zsqrt(4)r   rH   r   )r   r   rP   r  r   r   r   ry   r   r   rT   r   re   s    r   testSqrtzMathTests.testSqrtK  s"   )TYY/

9diilA.

9diinc2

;		#0BC

<4#6

=$))E"24EF

9diilA.

9diilA.3-*dii4*dii6

499S>23r   c                    | j                  t        t        j                         | j	                  dt        j                  d      d       | j	                  dt        j                  t        j
                  dz        d       | j	                  dt        j                  t        j
                   dz        d       	 | j                  t        j                  t        j                  t                           | j                  t        j                  t        j                  t                           | j                  t        j                  t        j                  t                           y # t        $ rU | j                  t        t        j                  t               | j                  t        t        j                  t               Y w xY w)Nztan(0)r   z	tan(pi/4)r   r   z
tan(-pi/4)r   )r   r   rP   tanr   r   r   rT   r   r   ry   r   re   s    r   testTanzMathTests.testTanY  r  r  c                 X   | j                  t        t        j                         | j	                  dt        j                  d      d       | j	                  dt        j                  d      t        j                  d      z   dt        j
                  d             | j	                  dt        j                  t              d       | j	                  dt        j                  t              d       | j                  t        j                  t        j                  t                           y )	Nztanh(0)r   ztanh(1)+tanh(-1)r   r   r   z	tanh(inf)z
tanh(-inf))r   r   rP   tanhr   r   r   r   r   rT   r   re   s    r   testTanhzMathTests.testTanhf  s    )TYY/

9diilA.

%tyy|DIIbM'A188A; 	 	(

;		#2

<4"5

499S>23r   c                     | j                  t        j                  d      d       | j                  t        j                  dt        j                  d            t        j                  dd             y )Nr   r   )r   rP   r  rQ   re   s    r   testTanhSignzMathTests.testTanhSigno  sM     	3-r499S>:r3/	1r   c                    | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        t        j                  d            t               | j                  t        t        j                  d            t               | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d	      d
        G d d      } G d dt
              } G d d      } G d d      }| j                  t        j                   |             d       | j                  t        j                   |             d       | j                  t        t        j                         | j                  t        t        j                  dd       | j                  t        t        j                  t        d             | j                  t        t        j                   |              | j                  t        t        j                   |              y )Nr   r   r   r   g?gg!r   g-?Yic                       e Zd Zd Zy)'MathTests.test_trunc.<locals>.TestTruncc                      yN   rk   re   s    r   	__trunc__z1MathTests.test_trunc.<locals>.TestTrunc.__trunc__  r   r   Nrh   ri   rj   r  rk   r   r   	TestTruncr    r   r   r  c                       e Zd Zd Zy)(MathTests.test_trunc.<locals>.FloatTruncc                      yr  rk   re   s    r   r  z2MathTests.test_trunc.<locals>.FloatTrunc.__trunc__  r   r   Nr  rk   r   r   
FloatTruncr    r   r   r  c                       e Zd Zy))MathTests.test_trunc.<locals>.TestNoTruncNro   rk   r   r   TestNoTruncr    r   r   r  c                       e Zd Z e       Zy)*MathTests.test_trunc.<locals>.TestBadTruncN)rh   ri   rj   rw   r  rk   r   r   TestBadTruncr    r  r   r  r  rH   g     7@)
r   rP   truncr   rS   r:   r   r   r[   ry   )ra   r  r  r  r  s        r   
test_trunczMathTests.test_truncv  s   A*B,djjm,c2djjo.4C!,D)2.H-q1I.3I.3H-t4	 		 		 		# 	# 	IK0"5JL126)TZZ0)TZZA6)TZZ4A)TZZ?*djj,.Ar   c                 2   | j                  t        j                  d             | j                  t        j                  d             | j                  t        j                  d             | j                  t        j                  d             | j                  t        j                  t	        d                   | j                  t        j                  t	        d                   | j                  t        j                  t	        d                   y )Nr   r   r   r   r   r   r   )r   rP   isfiniteassertFalser:   re   s    r   testIsfinitezMathTests.testIsfinite  s    c*+d+,c*+d+,uU|45uU|45uV}56r   c                    | j                  t        j                  t        d                   | j                  t        j                  t        d                   | j                  t        j                  t        d      dz               | j	                  t        j                  t        d                   | j	                  t        j                  d             | j	                  t        j                  d             y )Nr   z-nanr   r   r   )r   rP   rT   r:   r  re   s    r   	testIsnanzMathTests.testIsnan  s    

5<01

5=12

5<"#456E%L12B(B(r   c                 2   | j                  t        j                  t        d                   | j                  t        j                  t        d                   | j                  t        j                  d             | j                  t        j                  d             | j	                  t        j                  t        d                   | j	                  t        j                  d             | j	                  t        j                  d             y )Nr   r   g      g      r   r   r   )r   rP   rU   r:   r  re   s    r   	testIsinfzMathTests.testIsinf  s    

5<01

5=12

5)*

6*+E%L12B(B(r   c                     | j                  t        j                  t        j                               | j	                  t        j
                  dt        j                        d       y rP  )r   rP   rT   r   r   rQ   re   s    r   test_nan_constantzMathTests.test_nan_constant  s:    

488,-r4884b9r   c                 N   | j                  t        j                  t        j                               | j	                  t        j                  d       | j                  t        j                  t        d             | j                  t        j                   t        d             y )Nr   r   r   )r   rP   rU   r   assertGreaterr   r:   re   s    r   test_inf_constantzMathTests.test_inf_constant  sa    

488,-488S)5<0$((E&M2r   zrequires verbose modec                 d   	 t        j                  d      }dk7  r| j                  d       	 t        j                  d      }| j                  d       	 t        j                  d      }| j                  d       y #  | j                  d       Y zxY w# t        $ r Y Kw xY w# t
        $ r Y y w xY w)	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)rP   rD   r   r   r  ry   ra   r   s     r   test_exceptionszMathTests.test_exceptions  s    	(%A 6IIAB	H$A IIFG	:		$A II895	( II ' (  		  		s.   A< B B# <B	B B #	B/.B/c                    dh}d }t         j                  dk(  r@t        j                         d   }	 t        t	        t
        |j                  d                  }d}g }t        t              D ]  \  }}}}	}
}}|	dk7  s|dk7  r|dv r|
|dk  r||v r't        t        |      }d	|v sd
|v rd}
nd|v rd}
	  ||      }|dv rt        j                  |
|      }
d\  }}t        |
|||      }||j                  ||||      }|j!                  |        |r$| j#                  ddj%                  |      z          y y # t        $ r Y w xY w# t        $ r d}Y t        $ r d}Y w xY w)Ntan0064darwinr   .{}: {}({!r}): {}r   )rectpolar)r   r   invaliddivide-by-zerory   overflowr   )sqrt0002sqrt0003sqrt1001sqrt1023r   r   zFailures in test_testfile:
  
  )rS  platformmac_verr  r  rS   r9   ry   rN   	test_filegetattrrP   r   rQ   rY   r'   rV  r   join)ra   SKIP_ON_TIGERosx_versionversion_txtrW   failuresr@   rA   araiereirE   rA  r'  r*   r+   rV   msgs                      r   test_testfilezMathTests.test_testfile  s    #<<8#"**,Q/K#C[->->s-C$DE &-;I-F)BBBESyB#I&&&;+@&4$DE!%5%>!u$$)b EE]]2r*  &GW"2vw@G//"b"g6COOC S .GV II6kk(+, - c  6  &%  )()s)   (D; 5E
;	EE
E$
E$#E$c                    d}g }t        t              D ]  \  }}}}}t        t        |      }d|v sd|v rd}nd|v rd}	  ||      }	d\  }
}|dk(  rd	}
n$|d
k(  rd}n|dk(  r|dk\  r|dk  rd}
n
|dk  rd}
nd}
t        ||	|
|      }|u|j                  ||||      }|j                  |        |r$| j                  ddj                  |      z          y y # t        $ r d}	Y t
        $ r d}	Y w xY w)Nr  r  r  ry   r  r   r  r  r  lgammagV瞯<erfcr   r   r         $@r   r   zFailures in test_mtestfile:
  r  )rF   math_testcasesr  rP   ry   r   rY   r'   rV  r   r  )ra   rW   r  r@   rA   rB   r(   rE   rA  r)   r*   r+   rV   r  s                 r   test_mtestfilezMathTests.test_mtestfile   sA   %,;N,K(BC54$DE!%5%>'u$*&3i  &GW W} x
  v#* 9 G4Z!G"G"8S'7CG//"b#w7COOC q -Lt II7kk(+, - a  #"  &%&s   CC1$
C10C1c                 n   ddl m} t        j                  }| j	                   |g       d       | j	                   |g d      d       | j	                   |t        t        dd                  d       | j	                   |t        t        t        dd                        d       | j	                   |t        dd	      d	      d
       | j	                   |g d      d       | j	                   |g d      d       | j	                   |g d      d       | j	                   |g d      d       | j	                   |d |dd      g      d        G d d      }| j                  t              5   |d |       g       d d d        | j	                   |g d      d       | j	                   |g d      t        d             | j                  t        |       | j                  t        |d       | j                  t        |g d       | j                  t        |g dd       | j                  t        |ddgd       t        d      t        d       g}| j                  t        ||t        d             | j                  t        |dgdgdgg       | j                  t        |ddig       | j                  t        |ddigdz  ddi       | j                  t        |dgdgdggg        | j	                   |ddgd!      d"       | j	                   |ddgddg      g d#       | j	                   |g ddi      ddi       | j                  t              5   |d	d$gd       d d d        | j	                   |g d%      d       | j	                   |g d&      d       | j	                   |g d'      d       d7d(}t        dd)      }| j	                   ||       ||             t        d*d+      }| j	                   ||       ||             t        d,d-      }| j	                   ||      d       t        dd-      D cg c]  }t        |       }}| j	                   ||       ||             t        d,d+      D cg c]  }t        |       }}| j	                   ||       ||             t        d,d-      D cg c]  }t        |       }}| j                   ||             | j                   |dddt        d.      ddg             | j                   |ddt        d.      ddg             | j                   |dt        d.      ddg             | j                   |dt        d/      t        d.      dg             | j                   |dt        d0      t        d.      dg             | j                   |dt        d.      t        d/      dg             | j                   |dt        d.      t        d0      dg             | j	                   |dddt        d/      d1d2g      t        d0             | j	                   |dddt        d0      d1d2g      t        d/             | j                   |dddt        d/      d1d2g             | j                   |dddt        d0      d1d2g             | j                   |dddt        d/      d1ddg             | j                   |dddt        d0      d1ddg             | j	                  t         |g d3            t               | j	                  t         |g d4            t               | j	                  t         |t        dd)                  t               | j	                  t         |t        dd)      d            t               | j	                  t         |dt!        j"                  d5      dd2dd6g            t         j"                         y # 1 sw Y   xY w# 1 sw Y   xY wc c}w c c}w c c}w )8Nr   rx  r   r   )r   rH   r   i  r   i _7 )r   rH   r   r   r   rd  )r   r   r   r   r   rn  )r   rH   r   r   r   )r   r   r   r   r   r   r   r   c                       e Zd Zd Zy)(MathTests.test_prod.<locals>.BadMultiplyc                     t         r]   r  r  s     r   r  z1MathTests.test_prod.<locals>.BadMultiply.__rmul__u  r  r   N)rh   ri   rj   r  rk   r   r   r  r  t  s    #r   r  r  )r   r           r   r   r  )r   r   r  r   r   r   )rs  rt  rr      a   cr      bababababababab)r   rH   r   rH   r   rH   r   rH   r   rH   r   rH   r  )r   r   rH   r   )r   r   rH   r   )r   rH   r   r   c                     | D ]  }||z  }	 |S r]   rk   )r7  r   elems      r   _naive_prodz(MathTests.test_prod.<locals>._naive_prod  s      !Lr   i'  ir   ir   r   r   r   r   r   )r   rH   r   r   r   rm  )r   r   r   r   r   rm  r   rm  r  )r  ry  rP   prodr   r  r   r  r   r  r:   r   	bytearrayr  r   rS   r  r  )ra   r  r  r  r  r  r7  r   s           r   	test_prodzMathTests.test_prodc  s   +yyb1%b*A.d51:./6d4a
#345t<eArl"5w?o.478%@12E:34e<r1Q7m,c2	# 	# |,#{}%& - 	12E:56eE)T*)T2.)T?;)T?"E)TD$<sCD/9T?3)T63H)TQC!qc?;)TQqE73)TQqE719QqEB)TQC!qc?"E 	q!fD1>Bq!fQF35YZbA/!A7y)"b1 * 	l+Q/l+Q/l+Q/	 E?hX)>?$hX)>?%h+ ',Atn5nE!Hn5hX)>?&+E2&67&6E!H&67hX)>?&+E4&89&8E!H&89h( 	q!Qea;<=q!U5\1a89:q%,1567q%,eQ?@Aq%-ua@ABq%,eQ?@Aq%,fa@ABq!QeR:;U6]Kq!Qfb;<eElKq1U5\2q9:;q1U6]B:;<q!Qeb!Q?@Aq!Qfr1a@AB 	d#567=d#7895Ad5E?34c:d5E?#>?GdAws';Q1a#HIJ 	*_ -,2 *). 679s*   4`#``(`-`2``%c                 	   t         j                  }t         j                  }t        d      D ]`  }|dk  rt        |dz         n|dk  rt        d      n
t        d      D ]-  }| j	                   |||       ||       |||z
        z         / b t        dd      D ]I  }t        d|      D ]8  }| j	                   |||       ||dz
  |dz
        |z   ||dz
  |      z          : K t        dd      D ]S  }| j	                   ||d      d       | j	                   ||d      |       | j	                   |||       ||             U t        d      D ]?  }| j	                   ||       ||             | j	                   ||d        ||             A | j                  t        |dd	       | j                  t        |dt        j                  d	             | j                  t        |dd
       | j                  t        |dd       | j                  t        |t        j                  d      d       | j                  t        |dd       | j                  t        |       | j                  t        |ddd       | j                  t        |       | j                  t        |dd       | j                  t        |ddz   d       | j                  t        |dd       | j                  t        |dddz          | j	                   |dd      d       | j	                   |dddz        d       ddz  }| j	                   ||d      d       | j	                   ||d      |       | j	                   ||d      ||dz
  z         t        j                  d      r| j                  t        |||       dD ]D  \  }}| j	                   |||      d       | j                  t         |||            t               F | j	                   |t!        d      t!        d            d       | j	                   |t#        d      t#        d            d       t        d      D ]r  }| j                  t         |t!        d      t!        |                  t               | j                  t         |t#        d      t#        |                  t               t y )Nr  r   r   rL  r  r   r   r  r   1r  10r   r   rH   r   Tcpython)TT)TF)FFr   )rP   permr   r   r   r   r   r  r  ry   r   check_impl_detailr   r  r   rS   rn   rq   )ra   r  r   r   r  s        r   testPermzMathTests.testPerm  s   yyNN	sA&'#geAElC59USUYV  a!*11q51A!AC W  q#A1a[  aT!a%Q-?!-Cd1q5RSn-TU ! 
 q#AT!QZ+T!QZ+T!QZ16  rAT!Wil3T!T]IaL9  	)T2s3)T2ws/CD)T2s3)T43)T7??4+@!D)T43)T*)T2q!4)T* 	*dB2*dQWHa8*dAr2*dA4x8 	aQ'aD)1-tGaQ'aQ'aQ!A#Y/$$T2mT1a8?DAqT!QZ+MM$tAqz*C0 @ 	k!nk!n=rBk!nk!n=rBqAMM$tKNKNCDcJMM$tKNKNCDcJ r   c                 
   t         j                  }t         j                  }t        d      D ]i  }|dk  rt        |dz         n|dk  rt        d      n
t        d      D ]6  }| j	                   |||       ||       ||       |||z
        z  z         8 k t        dd      D ]F  }t        d|      D ]5  }| j	                   |||       ||dz
  |dz
         ||dz
  |      z          7 H t        d      D ]4  }| j	                   ||d      d       | j	                   |||      d       6 t        dd      D ]7  }| j	                   ||d      |       | j	                   |||dz
        |       9 t        d      D ]8  }t        |dz        D ]%  }| j	                   |||       ||||z
               ' : | j                  t        |dd	       | j                  t        |dt        j                  d	             | j                  t        |dd
       | j                  t        |dd       | j                  t        |t        j                  d      d       | j                  t        |dd       | j                  t        |d       | j                  t        |ddd       | j                  t        |       | j                  t        |dd       | j                  t        |ddz   d       | j                  t        |dd       | j                  t        |dddz          | j	                   |dd      d       | j	                   |dddz        d       ddz  }| j	                   ||d      d       | j	                   ||d      |       | j	                   ||d      ||dz
  z  dz         | j	                   |||      d       | j	                   |||dz
        |       | j	                   |||dz
        ||dz
  z  dz         t        j                  d      r| j                  t        |||dz         dD ]D  \  }}| j	                   |||      d       | j                  t         |||            t               F | j	                   |t!        d      t!        d            d       | j	                   |t#        d      t#        d            d       t        d      D ]r  }| j                  t         |t!        d      t!        |                  t               | j                  t         |t#        d      t#        |                  t               t y )Nr  r   r   rL  r  r   r   rH   r   r  r  r  r   r   r   Tr  r  r   )rP   combr   r   r   r   r   r  r  ry   r   r  r   r  r   rS   rn   rq   )ra   r  r   r   r  s        r   testCombzMathTests.testComb		  s   yyNN	sA&'#geAElC59USUYV  aYq\!!yQ'77.9 : W  q#A1a[  aT!a%Q-?$q1ua.-PQ ! 
 sAT!QZ+T!QZ+  q#AT!QZ+T!QU^Q/ 
 sA16]  aT!QU^< #  	)T2s3)T2ws/CD)T2s3)T43)T7??4+@!D)T43)T2.)T2q!4)T* 	*dB2*dQWHa8*dAr2*dA4x8 	aQ'aD)1-tGaQ'aQ'aQ!A#Y!^4aQ'a1q)a1qAaCyA~6$$T2mT1ad;?DAqT!QZ+MM$tAqz*C0 @ 	k!nk!n=rBk!nk!n=rBqAMM$tKNKNCDcJMM$tKNKNCDcJ r   c                    | j                  t        j                  dt               d       | j                  t        j                  dt              d       | j                  t        j                  dd      d       | j                  t        j                  dd      d       | j                  t        j                  d	t               t        j                  d
             | j                  t        j                  d	t              t        j                  d             | j                  t        j                  d	t         d      t        j                  d
             | j                  t        j                  d	t        d      t        j                  d             | j                  t        j                  d	t         d      t        j                  d             | j                  t        j                  d	t        d      t        j                  d             t        dd      D ]z  }| j                  t        j                  dd|      d       | j                  t        j                  dd|      d       | j                  t        j                  dd|      d       | t        j                  j                  t        j                  j                  z  }| j                  t        j                  dt              |       | j                  t        j                  dt              |       | j                  t        j                  dt               |        | j                  t        j                  dt               |        | j                  t        j                  |d      d       | j                  t        j                  | d      d       | j                  t        j                  |d      d       | j                  t        j                  | d      d       t        j                  j                  }| j                  t        j                  t        d      |       | j                  t        j                  t         d      |        | j                  t        j                  |t              t               | j                  t        j                  | t               t                | j                  t        j                  t        d	             | j                  t        j                  d	t                     | j                  t        j                  t        t                     | j                  d	t        j                  d	t        d             | j                  t               5  t        j                  d	t        d       d d d        y # 1 sw Y   y xY w)Ng      0Cg/Cg     0Cg      Cr   gCg      gr   z0x1.fffffffffffffp-1z0x1.0000000000001p+0r   )stepsr   z0x1.ffffffffffffdp-1z0x1.0000000000003p+0r   r   r   r   r   )r   rP   	nextafterr   r:   rU  r   assertEqualSignrS  r0  minepsilonr3  r  r   r   ry   )ra   r  smallest_subnormallargest_normals       r   test_nextafterzMathTests.test_nextafterO	  s    	(:SDA+	-(:C@+	-(=sC.	0(>D/	1 	cT2'=>	@S1'=>	@cT;'=>	@S:'=>	@cT;'=>	@S:'=>	@ 1a[ET^^CEBCH  d%!H$O  d%!H$O ! !^^//#..2H2HHc24FGc24FGsd36H5HIsd36H5HIT^^,>EtLT^^-?,?FMT^^,>EtLT^^-?,?FM ++S1>Bc2^OD<cB#>E 	S12S12S12dnnS#Q?@z*NN32. +**s   .WWc                 D   | j                  t        j                  d      t        j                  j
                         | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      t        j                  j                  t        j                  j
                  z         | j                  t        j                  t              t        t        j                  t        t               z
         | j                  t        j                  t              t               | j                  t        j                  t        j                               ddddt        fD ]V  }| j                  |      5  | j                  t        j                  |       t        j                  |             d d d        X y # 1 sw Y   cxY w)	Nr   l          l          r   l            g      @r   r  )r   rP   r   rS  r0  r  r  r  r  r   r  r   r  r  s     r   test_ulpzMathTests.test_ulp	  s`   #(>(>?'*C0'*C0'*F3 	#++cnn.D.DD	F),"T^^It%DD	F 	#,$((+, sGWc2A"  1"txx{; #" 3""s   :HH	c                 ,    G d d      }t         j                  t         j                  t         j                  fD ]L  } |       }| j	                  t
              5   |d|       d d d        | j                  t        |dd             N y # 1 sw Y   (xY w)Nc                       e Zd Zd Zy)$MathTests.test_issue39871.<locals>.Fc                     d| _         ddz   y )NTr   r   )	convertedre   s    r   rf   z.MathTests.test_issue39871.<locals>.F.__float__	  s    !%!r   N)rh   ri   rj   rf   rk   r   r   r  r$  	  s    r   r  znot a numberr&  F)rP   r   rQ   r  r   r   r  r  )ra   r  rA  rq  s       r   test_issue39871zMathTests.test_issue39871	  so    	 	 JJt~~=DA""9-^Q' .
 WQU;< >--s   
B

B	c                    | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t        t        j
                  dd       | j                  t        t        j
                  dd       | j                  t        t        j
                  d       | j                  t        t        j
                  ddd       y )NrN  r   r   r   )r   r   rP   rD   erfr   re   s    r   test_input_exceptionszMathTests.test_input_exceptions	  s    )TXXv6)TXXv6)TZZ=)TZZf=)TZZ5)TZZc3?r   c                 p    t        j                  |      s!| j                  dj                  |             y y )NzExpected a NaN, got {!r}.)rP   rT   r   r'   r`   s     r   r  zMathTests.assertIsNaN	  s+    zz% II188?@ !r   c                     | j                  ||       | j                  t        j                  d|      t        j                  d|             y)zSimilar to assertEqual(), but compare also the sign with copysign().

        Function useful to compare signed zeros.
        r   N)r   rP   rQ   )ra   r   rq  s      r   r  zMathTests.assertEqualSign	  s:    
 	AsA.c10EFr   Nr  )Vrh   ri   rj   r   r   r   r   r   r   r   r   r   r   r   r   r   r   unittestskipIfrS  r  machiner   r   r   r   r   r   r  r   cpython_onlyr  r  r"  r.  HAVE_DOUBLE_ROUNDINGr`  ru  r  r  r  r  r  r  r  r  r  r  requires_mac_verr  r   r  r  requires_resourcerR  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  
skipUnlessr   r  r  r  r
  r  r  r  r!  r'  r*  r  r  rk   r   r   r~   r~      s   6.	45	454	5<:|4 %;N : :B3 X__S\\W,W1A1A1A1CGW1W[]4]45<	=/@: < <#<J;.8$ X__)MOmDO mD^(ETOFb X__)NP:1P :1x7B)
3&j*FX<B3$/ 4 4" Wb!$+ % +
5^.B X__)]_M _ M Wu%H &HT X__)]_Wu%Q- & _ 
Q-f1&H;l5 ~, ~,@34434 1 1B@7)):
3 X"9:: ;:> =- =-~ @- @-Dd*L>K@DKL 8/ 8/v < <,= @AGr   r~   c                   ~    e Zd Zej                  Zd Zd Zd Zd Zd Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zy)IsCloseTestsc                 `    | j                   | j                  ||g|i ||d|d       y )N and z should be close!r  )r   r  ra   rs  rt  r   kwargss        r   assertIsClosezIsCloseTests.assertIsClose	  s5    Q;D;F;<=qA 	 	Cr   c                 `    | j                   | j                  ||g|i ||d|d       y )Nr8  z should not be close!r9  )r  r  r:  s        r   assertIsNotClosezIsCloseTests.assertIsNotClose	  s7    a<T<V<ABAF 	 	Hr   c                 F    |D ]  \  }} | j                   ||g|i |  y r]   )r<  ra   examplesr   r;  rs  rt  s         r   assertAllClosezIsCloseTests.assertAllClose	  s,    DAqDq!5d5f5 r   c                 F    |D ]  \  }} | j                   ||g|i |  y r]   )r>  r@  s         r   assertAllNotClosezIsCloseTests.assertAllNotClose	  s,    DAq!D!!!Q888 r   c                     | j                  t              5  | j                  ddd       d d d        | j                  t              5  | j                  dddd       d d d        y # 1 sw Y   =xY w# 1 sw Y   y xY w)Nr   g0.+rel_tolr?  g    _©rG  r+   )r   ry   r<  re   s    r   test_negative_tolerancesz%IsCloseTests.test_negative_tolerances	  sg    z*q!W5 +z*q!VUC +* +***s   A'A3'A03A<c                 4    g d}| j                  |dd       y )N))r   r   )N@irK  );rL  )i90  g    @)r   r   )NF rM  r   rH  rB  )ra   identical_exampless     r   test_identicalzIsCloseTests.test_identical	  s"    0 	.SIr   c                 X    g d}| j                  |d       | j                  |d       y )N))g    חAg   חA)g:0yEgnyE)g	ѭ?gfNӭ?:0yE>rF  &.>rB  rD  )ra   eight_decimal_places_exampless     r   test_eight_decimal_placesz&IsCloseTests.test_eight_decimal_places	  s5    )C% 	94H<dKr   c                 X    g d}| j                  |d       | j                  |d       y )N))rS  r   )g&.r   )gu?j/ʠr   r  rF  rR  r   )rD  rB  )ra   near_zero_exampless     r   test_near_zerozIsCloseTests.test_near_zero	  s4    . 	13?.=r   c                     | j                  t        t               | j                  t        t        d       | j                  t        t               | j                  t        t        d       y )Nr   r   )r<  r   r   re   s    r   test_identical_infinitez$IsCloseTests.test_identical_infinite	  sL    3$3S14&4s3r   c                     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       y )Nr?  r   rM  g?r   )r   r   r   rD  )ra   not_close_exampless     r   test_inf_ninf_nanzIsCloseTests.test_inf_ninf_nan
  sg    "Cj"Fm%sm"Cj"Cj"Dk"Cj"Cj"El$cl	, 	1;LMr   c                 `    g d}| j                  |d       g d}| j                  |d       y )N))r   r   )333333r`  )Ynra  r   rF  ))r   g     ?)g?r   )gZbtigTbtirT  )ra   zero_tolerance_close_examples!zero_tolerance_not_close_exampless      r   test_zero_tolerancez IsCloseTests.test_zero_tolerance
  s?    )=% 	93G-N) 	@#Nr   c                 .    | j                  ddgd       y )N)r  r   )r   r  r  rF  rN  re   s    r   test_asymmetryzIsCloseTests.test_asymmetry!
  s    Wg.<r   c                 X    ddg}| j                  |d       | j                  |d       y )N) )i[i[rR  rF  rS  rT  )ra   integer_exampless     r   test_integerszIsCloseTests.test_integers%
  s:    224 	,d;/>r   c                     ddl m}  |d       |d      f |d       |d      f |d       |d      f |d	       |d
      fg}| j                  |d       | j                  |d       y )Nr   rw  z
1.00000001z1.0z1.00000001e-20z1.0e-20z1.00000001e-100z1.0e-100z1.00000001e20z1.0e20rR  rF  rS  )r  r  rB  rD  )ra   r  decimal_exampless      r   test_decimalszIsCloseTests.test_decimals-
  s    #$\2GENC$%56	8JK$%679LM$_5wx7HIK 	,d;/>r   c                     ddl m}  |dd      dz    |d      f |d       |d      f |dd       |dd      fg}| j                  |d	       | j                  |d
	       y )Nr   rx  r   ri  rh  l       	(qe	 r  rR  rF  rS  )r  ry  rB  rD  )ra   ry  fraction_exampless      r   test_fractionszIsCloseTests.test_fractions8
  sz    & a#a'!5i (9"56i((1f*=>@ 	-t<0$?r   N)rh   ri   rj   rP   r  r<  r>  rB  rD  rI  rP  rV  rY  r[  r^  rd  rf  rk  rn  rq  rk   r   r   r6  r6  	  s^    llGCH69DJL>4N
O=?	?	@r   r6  c                 @    ddl m} |j                   |d             |S )Nr   )DocFileSuitezieee754.txt)doctestrs  addTest)loadertestspatternrs  s       r   
load_testsry  D
  s    $	MM,}-.Lr   r  ):test.supportr   r   testr   r-  r  r  r  rP   osr  rH  r   rS  r   r:   r   r   r   r0  r3  r  r  r  r   rq  r1  rh   argvfile__file__pathdirnamecurdirtest_dirr  r  r  r   r   r   r$   r/   rF   rN   rY   r[   rS   rn   r  rq   rw   TestCaser~   r6  ry  mainrk   r   r   <module>r     s   4       	    
 ElElV}NN	NN	 1A)  z88A;DD77??4 -BIIh(<=GGLL#89	L5H	,B$:40.` 	# 	&  Q#G!! Q#GhFx@8$$ x@v
 zHMMO r   