
    z%i                        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ejh                        Z5 G d dejh                        Z6d Z7ed
k(  r ejp                          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     B/home/uftp/.pyenv/versions/3.12.0/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$   `   s}    
 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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.
    Nz	not equalzexpected {!r}, got {!r}z ({}))
isinstancer:   intmathisnanisinfr/   r'   )r(   r)   r*   r+   failurefail_fmtfail_msgs          r   result_checkrX      s     h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]   r`   s    r   	__float__zFloatLike.__float__       zzr   N)__name__
__module____qualname__ra   re    r   r   rZ   rZ          r   rZ   c                       e Zd Zy)IntSubclassNrg   rh   ri   rj   r   r   rm   rm      s    r   rm   c                       e Zd Zd Zd Zy)MyIndexablec                     || _         y r\   r]   r_   s     r   ra   zMyIndexable.__init__   rb   r   c                     | j                   S r\   r]   rd   s    r   	__index__zMyIndexable.__index__   rf   r   Nrg   rh   ri   ra   rs   rj   r   r   rp   rp      rk   r   rp   c                   T   e Zd ZdQd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 ZTyP)R	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{}: {})rX   failr'   )r`   namer)   r(   r*   r+   rU   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{   rR   r}   r~   assertEqualtaurd   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	TypeErrorrR   acosr{   r}   
ValueErrorINFNINFeps
assertTruerS   NANrd   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   rR   acoshr{   r   r   r   r   r   rS   r   rd   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   rR   asinr{   r}   r   r   r   r   r   rS   r   rd   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   rR   asinhr{   r   r   r   r   rS   r   rd   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   rR   atanr{   r}   r   r   r   rS   r   rd   s    r   testAtanzMathTests.testAtan,  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   rR   r   r{   atanhr   r   r   r   rS   r   rd   s    r   	testAtanhzMathTests.testAtanh5  s    )TYY/

:tzz!}a0

<C2EF

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

4::c?34r   c                 2   | 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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(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   rR   atan2r{   r}   r   r   r   r   rS   r   rd   s    r   	testAtan2zMathTests.testAtan2@  s   )TZZ0

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

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

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

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

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

$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   rR   cbrtr{   r   r   r   r   rS   r   rd   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      }| j	                  t        j                   |             d       | j	                  t        j                   |             d       | j	                  t        j                  t        d            d       | j                  t        t        j                   |               |       }d |_	        | j                  t        t        j                  |       | j                  t        t        j                  |d       y )Nr   r         ?      ?rH   r   r         r         r   r   c                       e Zd Zd Zy)$MathTests.testCeil.<locals>.TestCeilc                      yN*   rj   rd   s    r   __ceil__z-MathTests.testCeil.<locals>.TestCeil.__ceil__      r   Nrg   rh   ri   r   rj   r   r   TestCeilr         r   r   c                       e Zd Zd Zy)%MathTests.testCeil.<locals>.FloatCeilc                      yr   rj   rd   s    r   r   z.MathTests.testCeil.<locals>.FloatCeil.__ceil__  r   r   Nr   rj   r   r   	FloatCeilr     r   r   r   c                       e Zd Zy)&MathTests.testCeil.<locals>.TestNoCeilNrn   rj   r   r   
TestNoCeilr         r   r   r   g     @E@+   c                      | S r\   rj   argss    r   <lambda>z$MathTests.testCeil.<locals>.<lambda>  s    4 r   )
r   r   rR   ceilr   rQ   typer:   rZ   r   )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
=L'
)TYY2)TYY15r   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   rR   copysignr   r   r   r   r   rS   r   rT   r&   rd   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   rR   cosr{   r}   ulpr   rS   r   r   r   r   rd   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   rR   coshr{   r   r   r   r   rS   r   rd   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   rR   degreesr{   r}   rd   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   rR   rD   r{   r~   r   r   r   r   rS   r   OverflowErrorrd   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   rR   exp2r{   r   r   r   r   rS   r   r   rd   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   rR   fabsr{   rd   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   rR   	factorialr   r$   r   r   )r`   totalr#   s      r   testFactorialzMathTests.testFactorial
  s    *A.q$ 	AAQJET^^A.6T^^A.Q@	A 	*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   rR   r   decimalDecimalrd   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   rR   r   r   rd   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      }| j	                  t        j                   |             d       | j	                  t        j                   |             d       | j	                  t        j                  t        d            d       | j                  t        t        j                   |               |       }d |_	        | j                  t        t        j                  |       | j                  t        t        j                  |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   rj   rd   s    r   	__floor__z0MathTests.testFloor.<locals>.TestFloor.__floor__3  r   r   Nrg   rh   ri   r  rj   r   r   	TestFloorr  2  r   r   r  c                       e Zd Zd Zy)'MathTests.testFloor.<locals>.FloatFloorc                      yr   rj   rd   s    r   r  z1MathTests.testFloor.<locals>.FloatFloor.__floor__6  r   r   Nr  rj   r   r   
FloatFloorr  5  r   r   r	  c                       e Zd Zy)(MathTests.testFloor.<locals>.TestNoFloorNrn   rj   r   r   TestNoFloorr  8  r   r   r  r   g33333D@)   c                      | S r\   rj   r   s    r   r   z%MathTests.testFloor.<locals>.<lambda>@  s    D r   )
r   r   rR   floorr   rQ   r   r:   rZ   r  )r`   r  r	  r  r   s        r   	testFloorzMathTests.testFloor%  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?M()TZZ3)TZZA6r   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       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   rR   fmodr{   r   rS   r   r   r   r   r   rd   s    r   testFmodzMathTests.testFmodD  s   )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3r   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   ry   )rz   resultr(   mantrD   emanteexpr`   s          r   	testfrexpz&MathTests.testFrexp.<locals>.testfrexp]  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   rR   frexpr   r   r   r   rS   r   )r`   r  s   ` r   	testFrexpzMathTests.testFrexpZ  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                 0   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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                  |              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))Nr   )
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 )zFull precision summation.  Compute sum(iterable) without any
            intermediate accumulation of error.  Based on the 'lsum' function
            at http://code.activestate.com/recipes/393090/

            r  rH   r   r   r   )	rR   r   rQ   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.++gd~QJr   gd~Qr2  )      @Cr   g      g?C)r3  r         9g     @C)g     @Cr   r4  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      r<  )sysr#  r0  min_expr   r:   fromhexappend	enumeraterR   fsumr   ry   r   r   r9  r:  r;  )r`   r#  r1  r   test_valuesr#   termsvalsr(   actualr9  r:  r;  jsvr/  r0  s                   @@r   testFsumzMathTests.testFsuml  s    	#&&""X-	+8 IUCL<fE'5&4+\:);7!!TN+qbd+]]124"'4.1QsQhqj1]]235 34=sC7<UC7KL!b!eb1R4j 2":-L[]]346* "'t-Aa--,1$K8qU1Q3Z%("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
	:? ,1
 M .8 ! I		 256$4GH I I		 256$4GH IIs6   H7	H<II6I5I J2JJ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   r<     x   T          j9W    P)}    "o  `T"-    l   8P9cC/[N
S9bXl	   9@{wM275k )	 l   Z'^%#>;*Q!/61^f            ^@      U@)rR   gcdr   r   r   rp   )r`   r[  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[!,	- 	"S3'TC(S"c*A.S!R!,)S%0)S%4)S#t4)S#q$7[-{2?Dr   c                    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d             |dd             | j                   |t!        d      t!        d      t!        d      t!        d            t	        j                  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         ? y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   mxY w) Nr   r   Fractionr         @g @r   c              3   &   K   | ]	  }|d z    yw)rH   Nrj   ).0rI  s     r   	<genexpr>z&MathTests.testHypot.<locals>.<genexpr>  s     5qad5s   g      (@r         *@rQ  rw      rU  r   r         %      %@r   r   r   r   r   皙?string皙@r   r  r   r   )!r   r   	fractionsrd  rR   hypotr~   r}   sqrtgammasinr   r'  assertAlmostEqualsumr   r)  r   r   r   r>  r#  
max_10_expr   r   r   r   r   r   rS   	FLOAT_MAXisclose	FLOAT_MIN)r`   r   rd  rr  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*wr{GAJ7<xB/!RA8BPRCSTtAwQa$q'BDIIaLQ 	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 	DAOODLL)Q)@)2TYYq\)AC D	D
 9 	DCs
*ETZZ%591U7C	DI	 		& 	&	, 	,s$   
X%<X2

X?%X/2X<?Y	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   r\  rH   )rR   rr  r   r   Contextr:   r@  subTestlocalcontextrs  r   )	r`   rr  r   high_precisionr  r  r   r\  zs	            r   testHypotAccuracyzMathTests.testHypotAccuracyB  s     

// c2$
 *	1FBJ b!Ab!Aa15 1)).9 Fwqz1}wqz1}<BBDEAF  q!a01 1O*	1PF F1 1s$   >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                   | |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   |d+d,       d d d        | j                  t"              5   |dd-       d d d        | j                  t               5   |d.d/       d d d        d0t$        j&                  j(                  d
z   z  }
| j                  t"        t*        f      5   |d|
fd1       d d d        | j                  t"        t*        f      5   |d1d|
f       d d d        t        d2      D ]Q  }t-        j,                         t-        j,                         }}| j                   ||f|f      t/        ||z
               S t0        d3d4dd5t2        t4        g}t7        j8                  |d67      D ]  }t7        j8                  |d67      D ]  }t        ||      D cg c]
  \  }}||z
   }}}t;        t=        t        j>                  |            r| j                   |||      t2               et;        t=        t        j@                  |            s| jC                  t	        j@                   |||                     tD        d8z  }t        d      D ]  }|f|z  }d!|z  }| jC                  t	        jF                   |||      |t	        j                  |      z               | jC                  t	        jF                   |||      |t	        j                  |      z                t        d      D ]l  }tH        d|z  z  }d9|z  d6|z  f}d:}| 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   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   cxY w# 1 sw Y   !xY w# 1 sw Y   xY wc c}}w );Nr   rb  rc  )r   r   r   )r   r   r   r   r   rH   r   )r   rH   r   	   rw   c              3   H   K   | ]  }t        j                  d d        ywrw   Nr9  uniformrg  ks     r   rh  z%MathTests.testDist.<locals>.<genexpr>       BA&..Q/B    "c              3   H   K   | ]  }t        j                  d d        ywr  r  r  s     r   rh  z%MathTests.testDist.<locals>.<genexpr>  r  r  c              3   2   K   | ]  \  }}||z
  d z    yw)r   Nrj   )rg  pxqxs      r   rh  z%MathTests.testDist.<locals>.<genexpr>  s     F&"bb2g#-Fs   )g      ,@r   )r   r   ri  )   r   )rH   rj  r  r   rH   r  rU  )TTFTF)TFTTFr   )     *@g      )@      
r   rj   r   )r   )r   )r   r   r   )r   r   r   )r   r   r   c                       e Zd Zy)MathTests.testDist.<locals>.TNrn   rj   r   r   Tr    r   r   r  )r   rw   rX  pq)r<  r   r  )rn  ro  rp  )r   rH   r   r   )rw   rX  r<  )r   rw   rX  r<  abcxyzr   )rH   r      rk  r   rl  r   repeatr   r   )r   r   )%r   r   rq  rd  rR   distrs  r   r   tuplerv  rw  zipiterr   r   r   r   r>  r#  rx  r   r9  r&   r   r   r   	itertoolsproductanymaprT   rS   r   ry  rz  r{  )r`   DFr  rs  r#   rH  r  r  r  r|  valuesr  r  diffsr}  r   rD   r~  s                      r   testDistzMathTests.testDist  s   (+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quadmadAbE];QrUCqRy!Ar(3a2h"b	5JK2r	$>>@c	$
 	224	 	b"s+MM#tGV45	
 	MM#tFG45	
 	),),	
	 	a	lZ93? y) 	+9	*	+y) 	O	y) 	2Iy1	2y) 	AJ	y) 	2%y1	2z* 	*y)	*z* 	*L)	*y) 		 "s~~'@'@1'D E
M:; 	5!*+V4	5
M:; 	5!234	5 r 	;A==?FMMOqAT1$-s1q5z:	;
 tS$S9""6!4 	<A&&va8 </21ay9VRb99s4::u-.$$T!QZ5TZZ/0OODJJtAqz$:;<	< O	r 	PAq A
AOODLLaY15MNOOODLLaY15MNO		P 9 	7Cs
*E5!E'"AATYYq!_ag6TYYq!_ag6	7a	+ 	+	 		2 	2	 		2 	2	* 	*	* 	*	 		5 	5	5 	5 :s~   5\	\$\1+
\>
]9
] 
]%
]2]?^^
\!$\.1\;>]]]"%]/2]<?^	^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   rw   )r   r   rR   r  rd   s    r   test_math_dist_leakzMathTests.test_math_dist_leak  s7    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 <   r=  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   ra   z1MathTests.testIsqrt.<locals>.IntegerLike.__init__  s	    "
r   c                     | j                   S r\   r]   rd   s    r   rs   z2MathTests.testIsqrt.<locals>.IntegerLike.__index__  s    zz!r   Nrt   rj   r   r   IntegerLiker    s    #"r   r  i  r  r   re  za stringz3.5y              @g      Y@r   )listr   r  rR   isqrtassertIsr   rQ   assertLessEqual
assertLessr   r   r   objectr   r   r   )r`   r~   r#   rD  r^   rI  r  
bad_valuess           r   	testIsqrtzMathTests.testIsqrt  s    t5|456!&r3HAsBHAq!taxHxHI $wD!" 	 ! 	4EE* 4JJu%d1gs+$$QqS%0!ac{3	4 4	4 z* 	JJrN	 JJtd1gs#AJJud1gs#A	"& 	" JJ{4()d1gs#Bz* 	(JJ{2'	(
 W__U3T4

   	&EE* &&&y1 &JJu%&& &	&W I
4 4	 	.	( 	(& && &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   r<  rM  rN  iY  rO  rP  iH  rR  rS  rT  l    ,`aUx-xB:Vn
Ldbl   me%Y% l   };T^	 )rV  l   |/Kr2 rW  i7  rY  rZ  )rR   lcmr   r   r   rp   )r`   r  r   r\  r]  r^  r_  ds           r   test_lcmzMathTests.test_lcm,  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	                  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 )Nz
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+i l    d(	       Fx:^V r   r  )r   r   rR   r%  r{   r   r   r   r   r   rS   r   r`   r   s     r   	testLdexpzMathTests.testLdexpX  s   )TZZ0

<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0 	<A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:;	<r   c                 t   | j                  t        t        j                         | 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                  t               | j                  t        j                  t              t               | j                  t        j                  t        j                  t                           y )Nzlog(1/e)r   r   zlog(1)r   zlog(e)z	log(32,2)rU  rH   rw   zlog(10**40, 10)r   r  zlog(10**40, 10**20)r  zlog(10**1000)r   gO+@r   )r   r   rR   logr{   r~   r   r   r   r   r   rS   r   rd   s    r   testLogzMathTests.testLogx  sc   )TXX.

:txx$&&126

8TXXa[!,

8TXXdff-q1

;A2

$dhhr2vr&:B?

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

?DHHRX$6%	'*dhh5*dhhT	:*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   rR   log1prv  r:   r   r   r   r  s     r   	testLog1pzMathTests.testLog1p  s    )TZZ0QUAsF# 	HA""4::a=$**U1X2FG	H*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   rR   log2r   r   r   r   rS   r   rd   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 )Nr6  r  r   )r   rR   r  r%  r:   r   )r`   r   rG  r(   s       r   testLog2ExactzMathTests.testLog2Exact  si    
 :?ud9KLA$))DJJsA./LL&+E4&89E!H9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   rR   log10r{   r   r   r   r  r   r   rS   r   rd   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                    t         j                  }t        j                  }t        j
                  }| j                   |t        g d      d      d       | j                   |ddgddg      d       | j                   |g 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dgdg       | j                  t        |dgddg       d }	| j                  t              5   |t!        d       |	d             d d d        | j                  t              5   | |	d      t!        d             d 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   dx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         @re  g      @g     0@r   )r   g      r   rw   r   )r  r      r   r  c              3   ,   K   | ]  \  }}||z    y wr\   rj   )rg  p_iq_is      r   rh  z(MathTests.testSumProd.<locals>.<genexpr>  s     "Tc39"Ts   Tstrictr   r  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   c                       e Zd Zd Zd Zy)*MathTests.testSumProd.<locals>.BadMultiplyc                     t         r\   r  r`   others     r   __mul__z2MathTests.testSumProd.<locals>.BadMultiply.__mul__      ""r   c                     t         r\   r  r  s     r   __rmul__z3MathTests.testSumProd.<locals>.BadMultiply.__rmul__  r  r   N)rg   rh   ri   r  r  rj   r   r   BadMultiplyr    s    ##r   r  r  g333333$@g3333334@gL>@gL4@))r  r  r   )r                           r   )rR   sumprodr   r   rq  rd  r   r  r  rw  r  r   r   r   r   r  r   r   r   rS   r   )r`   r  r   rd  rJ  r  r  r(   rG  r  r  r   s               r   testSumProdzMathTests.testSumProd  s   ,,//%% 	l!3Y?E#sc3Z8$?R!, a^Xa^,S\73<((1a.!!Q 	
 	CA Q!QttW. C1\\A\+ C""TSAd=S"TTH$Q]F$$Xv6$$T(^T&\B	C CC	C$ 	)W-)Wb1)Wb"b9)WdRD9)WrdD9 	*gBx">*gtb"X>	 |, 	/E"I{1~.	/|, 	/KNE"I.	/	# 	#
 |, 	8R+Y7	8|, 	8IKM267	8 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$-qC C,	/ 	/	/ 	/	8 	8	8 	8	) 	)	) 	)sU   7AV'V"V/V<W	?W*W#V"V,/V9<W	WW #W-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                   |g ddgd	z        d
       y )Nr  r   r   r   r  TF)r   g\nTr   g\nr   r   )rR   r  r   )r`   r  s     r   test_sumprod_accuracyzMathTests.test_sumprod_accuracy  st    
 ,,#aSV4c:#dE]R-?@#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\   rQ   r`   r  Ints     r   __add__z2MathTests.test_sumprod_stress.<locals>.Int.__add__      3t9s5z122r   c                 >     t        |       t        |      z        S r\   r  r  s     r   r  z2MathTests.test_sumprod_stress.<locals>.Int.__mul__  r	  r   c                      dt        |        dS )NzInt()r  rd   s    r   __repr__z3MathTests.test_sumprod_stress.<locals>.Int.__repr__      c$i[**r   Nrg   rh   ri   r  r  __radd__r  r  r  s   r   r  r        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__#  r	  r   c                 >     t        |       t        |      z        S r\   r  r  s     r   r  z2MathTests.test_sumprod_stress.<locals>.Flt.__mul__%  r	  r   c                      dt        |        dS )NzFlt(r  r  rd   s    r   r  z3MathTests.test_sumprod_stress.<locals>.Flt.__repr__)  r  r   Nr  r  s   r   Fltr  "  r  r   r  c                 F    d}t        | |d      D ]  \  }}|||z  z  } |S )zThis defines the target behavior including expections 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,  s8    
 E1T2 #Ss"#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>.run6  sZ    -t
 ftF|33	 #I.  -Awf,,-s    AA	A	Ar  r   i  l        l        r  r  rH   P   r   r<  )	      @g      g      @     &@g     y@g      ?      ?r   g            3r     r   r   i  i:,  r$  r  g      8r   i  g      @r  r   r   NaNr  r  y      @      @rj  r   r  g      z10.5z-2.25r   i   y      @      ?a   iz6.125z12.375z-2.75r   InfrQ  g      +@g      pl     g      pg      `g      )g      <g         r'  g      r%  g      g      g     `7@TFrw   r   r  )rR   r  r  r  r   r   rq  rd  rQ   r:   r   r   )r`   r  r  r   rd  r  r  r"  poolspoolsizeargs1args2r   r  s                 @r   test_sumprod_stresszMathTests.test_sumprod_stress  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$7 E!(d!;  %u~(( 084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   rc  )starmap)
namedtuple)r  r   r   )choicesr  r;  )median
DotExample)r   r\  target_sumprod	conditionc           
          t        |       }t        |      }t         j                  t        ||d                  S )NTr  )r  rw  mulr  )r   r\  vec1vec2rd  operatorr5  s       r   DotExactzDMathTests.test_sumprod_extended_precision_accuracy.<locals>.DotExactl  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   r\  rA  s     r   	ConditionzEMathTests.test_sumprod_extended_precision_accuracy.<locals>.Conditionq  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>.linspacet  s4    "WQ'E,1!H5qBN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.
            rX  rH   r   )r  r   r   r   r   r   N)r   rQ   r  r  roundr  )r   r]  n2r   r\  r_  r~   r  r#   pairsrC  rA  r9  r7  r   rI  r  r;  r  s             r   GenDotzBMathTests.test_sumprod_extended_precision_accuracy.<locals>.GenDotx  s    6MaB	A	AQA c!A#h2.Aq1u:>AaDAbE<=>qgdC(472>AcrF<=>qgdC(472>AcrF S1cAbD 9:;A2q\ VtS)D1r6O;!c*T!AF)_<x1~MQRSTQUU!V
 QOEEN;DAqaHQNIaODD ?>s   EE$c                 p    |\  }}}} t        |      |  gz   t        |      dgz         } ||z        S rE  )r  )	resexr   r\  r:  r;  r   rA  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   r\  )dotfuncr]  r   rQ  rP  rN  rR  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\   )rR   r  )rg  r#   rU  r]  r   s     r   rh  zEMathTests.test_sumprod_extended_precision_accuracy.<locals>.<genexpr>  s     NAeDLL!Q7Ns   "%r5  )r@  rq  rd  r  r5  collectionsr6  rR   r  r   r   r9  r7  r  r;  
statisticsr8  r   r  )r`   r6  r8  timesrelative_errrC  rA  r9  rd  rN  rR  rU  r]  r7  r   r   rI  r  r   r@  r;  r5  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  )rz   r  r(   v1v2e1e2r`   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   rR   modfr   r   r   r   r   rS   )r`   rb  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                 t%   | 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        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   g       r   r  r   g      .ggffffff?rn  ?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.r&  z
(-2.)**-3.g      )r   r   rR   powr{   r   r   r   r   rS   r   r   rd   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- 	"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   rR   radiansr{   r}   rd   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   rc  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   rQ   )	r   r\  rfxfyfrr   rd  r`   s	          r   validate_specz.MathTests.testRemainder.<locals>.validate_specg  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   )rq  rd  r  r9   r:   r@  rR   	remainderr   hexr   r   r   r   assertIsNaNr   r   )r`   rt  	testcasesru  x_hexy_hexexpected_hexr   r\  r(   rG  tinyr   mr^   rd  s   `              @r   testRemainderzMathTests.testRemainderc  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; 	9ET^^C78T^^E378	9
 , 	AET^^E37?T^^E48%@	A D$S#6 	,E"":. +sE*+"":. ,tU+,"":. +uc*+"":. ,ud+, ,	,O	? 	?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   rR   ru  r{   r}   r   rS   r   r   r   r   rd   s    r   testSinzMathTests.testSin  s   )TXX.

8TXXa[!,

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

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

488C=12  	:j$((C8j$((D9	:s   ;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   rR   sinhr{   r   r   r   r   r   rS   r   rd   s    r   testSinhzMathTests.testSinh  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)r&  r   zsqrt(25.25)g     @9@g)#L@zsqrt(1)r   zsqrt(4)r   rH   r   )r   r   rR   rs  r{   r   r   r   r   r   rS   r   rd   s    r   testSqrtzMathTests.testSqrt  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 #  | j                  t        t        j                  t               | j                  t        t        j                  t               Y xY w)Nztan(0)r   z	tan(pi/4)r   r   z
tan(-pi/4)r   )r   r   rR   tanr{   r}   r   rS   r   r   r   r   rd   s    r   testTanzMathTests.testTan  s   )TXX.

8TXXa[!,

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

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

488C=12	:j$((C8j$((D9s   ;A6E- -AG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   rR   tanhr{   r   r   r   r   rS   r   rd   s    r   testTanhzMathTests.testTanh  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   rR   r  r   rd   s    r   testTanhSignzMathTests.testTanhSign  sM     	3-r499S>:r3/	1r   c                 N   | 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      }| 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                   |              y )Nr   r   r   r   g?gg!r   g-?Yic                       e Zd Zd Zy)'MathTests.test_trunc.<locals>.TestTruncc                      yN   rj   rd   s    r   	__trunc__z1MathTests.test_trunc.<locals>.TestTrunc.__trunc__2  r   r   Nrg   rh   ri   r  rj   r   r   	TestTruncr  1  r   r   r  c                       e Zd Zd Zy)(MathTests.test_trunc.<locals>.FloatTruncc                      yr  rj   rd   s    r   r  z2MathTests.test_trunc.<locals>.FloatTrunc.__trunc__5  r   r   Nr  rj   r   r   
FloatTruncr  4  r   r   r  c                       e Zd Zy))MathTests.test_trunc.<locals>.TestNoTruncNrn   rj   r   r   TestNoTruncr  7  r   r   r  r  rH   g     7@)	r   rR   truncr   rQ   r:   r   r   rZ   )r`   r  r  r  s       r   
test_trunczMathTests.test_trunc%  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?r   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   rR   isfiniteassertFalser:   rd   s    r   testIsfinitezMathTests.testIsfiniteB  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   rR   rS   r:   r  rd   s    r   	testIsnanzMathTests.testIsnanK  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   rR   rT   r:   r  rd   s    r   	testIsinfzMathTests.testIsinfS  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 )Nr   )r   rR   rS   r   r   r   rd   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   rR   rT   r   assertGreaterr   r:   rd   s    r   test_inf_constantzMathTests.test_inf_constanta  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)rR   rD   ry   r   rs  r   r`   r   s     r   test_exceptionszMathTests.test_exceptionsl  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\  }}t        |
|||      }|g|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   rw   invaliddivide-by-zeror   overflowr   rw   r   zFailures in test_testfile:
  
  )r>  platformmac_verr  r  rQ   r9   r   rN   	test_filegetattrrR   r   rX   r'   rA  ry   join)r`   SKIP_ON_TIGERosx_versionversion_txtrV   failuresr@   rA   araiereirE   r!  r  r*   r+   rU   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  &GW"2vw@G//"b"g6COOC E"	!H II6kk(+, - U  6  &%  )()s)   (D! 5D0!	D-,D-0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  r   r  r   r  rt  r  lgammagV瞯<erfcr   r   r         $@r   r   zFailures in test_mtestfile:
  r  )rF   math_testcasesr  rR   r   r   rX   r'   rA  ry   r  )r`   rV   r  r@   rA   rB   r(   rE   r!  r)   r*   r+   rU   r  s                 r   test_mtestfilezMathTests.test_mtestfile  sE   %,;N,K 8	!(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8	!t II7kk(+, - a  #"  &%&s   CC1$
C10C1c                    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                   |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       d2d"}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        d*      t        d(      dg             | j                   |dt        d(      t        d)      dg             | j                   |dt        d(      t        d*      dg             | j                   |dddt        d)      d+d,g      t        d*             | j                   |dddt        d*      d+d,g      t        d)             | j                   |dddt        d)      d+d,g             | j                   |dddt        d*      d+d,g             | j                   |dddt        d)      d+ddg             | j                   |dddt        d*      d+ddg             | j                  t         |g d-            t               | j                  t         |g d.            t               | j                  t         |t	        dd#                  t               | j                  t         |t	        dd#      d/            t               | j                  t         |dt        j                  d0      dd,dd1g            t        j                         y # 1 sw Y   xY wc c}w c c}w c c}w )3Nr   rw   )r   rH   r   i  r   i _7 )r   rH   r   r   rw   rO  )r   r   r   r   r   rY  )r   rH   r   r   r   )r   r   r   r   rw   )r   r           r   r   r  )r   r   r  r   r   r   )r^  r_  r]      a   cr      br   ababababababab)r   rH   r   rH   r   rH   r   rH   r   rH   r   rH   r  )r   r   rH   r   r   )r   r   rH   r   )r   rH   r   r   c                     | D ]  }||z  }	 |S r\   rj   )r*  r   elems      r   _naive_prodz(MathTests.test_prod.<locals>._naive_prod2  s      Lr   i'  ir   ir   r   r   r   r   r   )r   rH   r   r   rw   rX  )r   r   r   r   rw   rX  r   r   rX  )r   )rR   prodr   r  r   r  r:   r   r   	bytearrayrx  r   rQ   r   r   )r`   r  r  r  r*  r   s         r   	test_prodzMathTests.test_prod  s   yyb1%b*A.d51:./6d4a
#345t<eArl"5w?o.478%@12E:34e< 	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5E!H55hX)>?&+E2&67E!H77hX)>?&+E4&89E!H9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 	*m	 	. 679s   ^01^=1_1_0^: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   r=  r  r   r   r  r   1r  10r   r   rH   r   Tcpython)TT)TF)FFrw   )rR   permr   r   r   r   r   r   r   r   r   check_impl_detailr   r  r   rQ   rm   rp   )r`   r  r   r   r  s        r   testPermzMathTests.testPermd  s8   yyNN	s 	CA&'#geAElC59USUY C  a!*11q51A!ACC	C q# 	VA1a[ V  aT!a%Q-?!-Cd1q5RSn-TUV	V
 q# 	7AT!QZ+T!QZ+T!QZ16	7 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? 	1DAqT!QZ+MM$tAqz*C0	1 	k!nk!n=rBk!nk!n=rBq 	KAMM$tKNKNCDcJMM$tKNKNCDcJ	K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   r=  r  r   r   rH   r   r  r  r  r   r   r   Tr  r  rw   )rR   combr   r   r   r   r   r   r   r   r   r  r   r  r   rQ   rm   rp   )r`   r  r   r   r  s        r   testCombzMathTests.testComb  s   yyNN	s 	:A&'#geAElC59USUY :  aYq\!!yQ'77.9 ::	: q# 	RA1a[ R  aT!a%Q-?$q1ua.-PQR	R
 s 	,AT!QZ+T!QZ+	, q# 	0AT!QZ+T!QU^Q/	0
 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;? 	1DAqT!QZ+MM$tAqz*C0	1 	k!nk!n=rBk!nk!n=rBq 	KAMM$tKNKNCDcJMM$tKNKNCDcJ	K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+0rw   r   r   r   r   )r   rR   	nextafterr   r:   r@  r   assertEqualSignr>  r#  minepsilonr&  rx  r   r   r   )r`   r  smallest_subnormallargest_normals       r   test_nextafterzMathTests.test_nextafter  s-    	(:SDA+	-(:C@+	-(=sC.	0(>D/	1 	cT2'=>	@S1'=>	@cT;'=>	@S:'=>	@cT;'=>	@S:'=>	@ 1a[ 	PET^^CEBCH  d%!H$O  d%!H$O	P !^^//#..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   rm  )r   rR   r   r>  r#  r  r  ry  r  r   rx  r   r  r  s     r   test_ulpzMathTests.test_ulp&	  sp   #(>(>?'*C0'*C0'*F3 	#++cnn.D.DD	F),"T^^It%DD	F 	#,$((+, sGWc2 	<A" <  1"txx{;< <	<< <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   )	convertedrd   s    r   re   z.MathTests.test_issue39871.<locals>.F.__float__A	  s    !%!r   N)rg   rh   ri   re   rj   r   r   r  r  @	  s    r   r  znot a numberr  F)rR   r   r   rv  r   r   r  r  )r`   r  r!  r\  s       r   test_issue39871zMathTests.test_issue39871=	  s}    	 	 JJt~~= 	=DA""9- (^Q'(
 WQU;<	=( (s   
B

B	c                 p    t        j                  |      s!| j                  dj                  |             y y )NzExpected a NaN, got {!r}.)rR   rS   ry   r'   r_   s     r   rx  zMathTests.assertIsNaNO	  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   rR   r   )r`   r   r\  s      r   r  zMathTests.assertEqualSignS	  s:    
 	AsA.c10EFr   Nr  )Urg   rh   ri   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   unittestskipIfr>  r  machiner   r   r   r   r   r   r   r   cpython_onlyr   r  r  r!  HAVE_DOUBLE_ROUNDINGrK  r`  r  r  r  r  r  r  r  r  r  r  requires_mac_verr  r  r  r  requires_resourcer3  r[  re  ri  rm  r  r  r  r  r  r  r  r  r  r  r  r  r  
skipUnlessr   r  r  r  r  r  r  r  r  r  rx  r  rj   r   r   rv   rv      s   6.	45	454	5;:z4 6B : :B3 X__S\\W,W1A1A1A1CGW1W[]4]45<	=/@: < <7>4,8$ X__)MO\:O \:|(ETIDV X__)NP:1P :1xo7b)
3&j*FX<@3 / 4 4" Wb!$+ % +
5N.b X__)]_M _ M Wu%H &HT X__)]_Wu%Q- & _ 
Q-f1&G;j5 ~, ~,@34434 1 1@:7)):
3 X"9:: ;:> 6- 6-p @- @-DZ*x>K@DKL 8/ 8/v < <,=$AGr   rv   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   rz  r`   r^  r_  r   kwargss        r   assertIsClosezIsCloseTests.assertIsClose_	  s5    Q;D;F;<=qA 	 	Cr   c                 `    | j                   | j                  ||g|i ||d|d       y )Nr
  z should not be close!r  )r  rz  r  s        r   assertIsNotClosezIsCloseTests.assertIsNotClosec	  s7    a<T<V<ABAF 	 	Hr   c                 F    |D ]  \  }} | j                   ||g|i |  y r\   )r  r`   examplesr   r  r^  r_  s         r   assertAllClosezIsCloseTests.assertAllCloseg	  s1     	6DAqDq!5d5f5	6r   c                 F    |D ]  \  }} | j                   ||g|i |  y r\   )r  r  s         r   assertAllNotClosezIsCloseTests.assertAllNotClosek	  s1     	9DAq!D!!!Q888	9r   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_tolr2  g    _©r  r+   )r   r   r  rd   s    r   test_negative_tolerancesz%IsCloseTests.test_negative_toleranceso	  s~    z* 	6q!W5	6z* 	Dq!VUC	D 	D	6 	6	D 	Ds   A'A3'A03A<c                 4    g d}| j                  |dd       y )N))r   r   )N@ir  );r  )i90  g    @)r   r   )NF r  r   r  r  )r`   identical_exampless     r   test_identicalzIsCloseTests.test_identicalv	  s"    0 	.SIr   c                 X    g d}| j                  |d       | j                  |d       y )N))g    חAg   חA)g:0yEgnyE)g	ѭ?gfNӭ?:0yE>r  &.>r  r  )r`   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))r%  r   )g&.r   )gu?j/ʠr   rg  r  r$  r   )r  r  )r`   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   rd   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 )Nr2  r   gg?r   )r   r   r   r  )r`   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r2  )Ynr3  r   r  ))r   g     ?)g?r   )gZbtigTbtir&  )r`   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  r  r   rd   s    r   test_asymmetryzIsCloseTests.test_asymmetry	  s    Wg.<r   c                 X    ddg}| j                  |d       | j                  |d       y )N) )i[i[r$  r  r%  r&  )r`   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   rb  z
1.00000001z1.0z1.00000001e-20z1.0e-20z1.00000001e-100z1.0e-100z1.00000001e20z1.0e20r$  r  r%  )r   r   r  r  )r`   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   rc  r   r;  r:  l       	(qe	 r  r$  r  r%  )rq  rd  r  r  )r`   rd  fraction_exampless      r   test_fractionszIsCloseTests.test_fractions	  sz    & a#a'!5i (9"56i((1f*=>@ 	-t<0$?r   N)rg   rh   ri   rR   rz  r  r  r  r  r  r"  r(  r+  r-  r0  r6  r8  r=  r@  rC  rj   r   r   r  r  \	  s^    llGCH69DJL>4N
O=?	?	@r   r  c                 @    ddl m} |j                   |d             |S )Nr   )DocFileSuitezieee754.txt)doctestrE  addTest)loadertestspatternrE  s       r   
load_testsrK  	  s    $	MM,}-.Lr   r  )9test.supportr   r   testr   r  rq  r  r   rR   osr  r9  r   r>  r   r:   r   r   r   r#  r&  ry  r  r{  r   r\  r  rg   argvfile__file__pathdirnamecurdirtest_dirr  r  r  r   r   r   r$   r/   rF   rN   rX   rZ   rQ   rm   r  rp   TestCaserv   r  rK  mainrj   r   r   <module>rX     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+Z 	# 	& k!G!! k!G\Cx@8$$ x@v
 zHMMO r   