
    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                 x    	 t        j                  dt        j                  d|             d   }|dk  r|dz    }|S )Nz<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                 4    	 | rdt        | | dz
  z        z   S dS )N   r   )count_set_bits)r   s    r   r   r   N   s$    K,-1~a!a%i((414r   c                 j    	 || z
  dz	  }|sy|dk(  r| S | |z   dz  }t        | |      t        ||      z  S Nr   )partial_product)startstop
numfactorsmids       r   r   r   R   sQ     ,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 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 )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_checkr0   k   s_     GH%45IHsN#I GyG37zz)YAAr   c              #   n  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)Nutf-8encoding--->r   r   )openindexstripsplitfloat)fnamefplinelhsrhsidfnarg
rhs_piecesexpflagss              r   parse_mtestfilerG   }   s      
eg	& :" 	:Dt|-TZZ-.::<zz$'HC))+KBCJQ-CqrNEr5:uSz599	:: : :s   B5BB) 	B5)B2.B5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)Nr2   r3   r5   r6   r   r      )r7   
startswithr9   r:   r;   )r<   r=   r>   r?   r@   rA   rB   arg_realarg_imagrD   exp_realexp_imagrF   s                r   parse_testfilerO      s     
 
eg	& " 	Dt$DJJLzz$'HC),&BHhJ!+A
1hHqrNEr?E(O?E(O 	  s   CB!B<3	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 )Nz	not equalzexpected {!r}, got {!r}z ({}))
isinstancer;   intmathisnanisinfr0   r(   )r)   r*   r+   r,   failurefail_fmtfail_msgs          r   result_checkrY      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^   ra   s    r   	__float__zFloatLike.__float__       zzr   N)__name__
__module____qualname__rb   rf    r   r   r[   r[          r   r[   c                       e Zd Zy)IntSubclassNrh   ri   rj   rk   r   r   rn   rn      s    r   rn   c                       e Zd Zd Zd Zy)MyIndexablec                     || _         y r]   r^   r`   s     r   rb   zMyIndexable.__init__   rc   r   c                     | j                   S r]   r^   re   s    r   	__index__zMyIndexable.__index__   rg   r   Nrh   ri   rj   rb   rt   rk   r   r   rq   rq      rl   r   rq   c                   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                 j    	 t        ||||      }|"| j                  dj                  ||             y y )Nz{}: {})rY   failr(   )ra   namer*   r)   r+   r,   rV   s          r   ftestzMathTests.ftest   s;    	 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
@rI   )r|   rS   r~   r   assertEqualtaure   s    r   testConstantszMathTests.testConstants   sH    

4"<=

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

:tyy}dgg6

9diilDGGAI6

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

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

:tzz!}a0

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

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

:tyy}twwhqj9

9diilA.

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

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

:tzz!}a0

:tzz!}.AB

;

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

4::c?34r   c                    | j                  t        t        j                         | j	                  dt        j                  d      t        j
                   dz         | j	                  dt        j                  d      d       | j	                  dt        j                  d      t        j
                  dz         | j	                  dt        j                  t              t        j
                  d	z         | j	                  d
t        j                  t              t        j
                   d	z         | j                  t        j                  t        j                  t                           y )Nzatan(-1)r      zatan(0)r   zatan(1)r   z	atan(inf)rI   z
atan(-inf))r   r   rS   atanr|   r~   r   r   r   rT   r   re   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   rS   r   r|   atanhr   r   r   r   rT   r   re   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   rI   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   rS   atan2r|   r~   r   r   r   r   rT   r   re   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)   rI   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   rS   cbrtr|   r   r   r   r   rT   r   re   s    r   testCbrtzMathTests.testCbrt}  sU   )TYY/

9diilA.

9diilA.

9diilA.

;		#4

<4$7

;		#0AB

<42DE

:tyy}a0

:tyy}b1

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

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

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

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

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

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

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

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

8TXXa[!,

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

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

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

9diilA.

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

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

=$,,tww"7?

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

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

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

9dhhrlAdffH5

8TXXa[!,

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

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

:tyy}c2

9diilA.

9diilA.

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

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

:tyy}a0

9diilA.

9diilA.r   c                    | j                  t        j                  d      d       d}t        dd      D ]Z  }||z  }| j                  t        j                  |      |       | j                  t        j                  |      t	        |             \ | j                  t        t        j                  d       | j                  t        t        j                  ddz          y )Nr   r     r   
   d   )r   rS   	factorialr    r%   r   r   )ra   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   rS   r   decimalDecimalre   s    r   testFactorialNonIntegersz"MathTests.testFactorialNonIntegers  s    )T^^S9)T^^S9)T^^T:)T^^V<)T^^W__S5IJ)T^^W__U5KL)T^^S9r   c                     | j                  t        t        j                  ddz         | j                  t        t        j                  d       y )Nr   r   }Ô%IT)r   r   rS   r   r   re   s    r   testFactorialHugeInputsz!MathTests.testFactorialHugeInputs  s4     	-SA)T^^U;r   c                    | j                  t        t        j                         | j	                  t
        t        t        j                  d                   | j	                  t        j                  d      d       | j	                  t        j                  d      d       | j	                  t        j                  d      d       | j	                  t        j                  d      d       | j	                  t        j                  d      d       | j	                  t        j                  d	      d
        G d d      } G d dt              } G d d      }| 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   rk   re   s    r   	__floor__z0MathTests.testFloor.<locals>.TestFloor.__floor__3  r   r   Nrh   ri   rj   r  rk   r   r   	TestFloorr  2  r   r   r  c                       e Zd Zd Zy)'MathTests.testFloor.<locals>.FloatFloorc                      yr   rk   re   s    r   r  z1MathTests.testFloor.<locals>.FloatFloor.__floor__6  r   r   Nr  rk   r   r   
FloatFloorr  5  r   r   r
  c                       e Zd Zy)(MathTests.testFloor.<locals>.TestNoFloorNro   rk   r   r   TestNoFloorr  8  r   r   r  r   g33333D@)   c                      | S r]   rk   r   s    r   r   z%MathTests.testFloor.<locals>.<lambda>@  s    D r   )
r   r   rS   floorr   rR   r   r;   r[   r  )ra   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   rS   fmodr|   r   rT   r   r   r   r   r   re   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   rz   )r{   resultr)   mantrE   emanteexpra   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)rI   )r   rI   )
r   r   rS   frexpr   r   r   r   rT   r   )ra   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 )Nr   rI   r   r   r   )	rS   r!  rR   ldexpmaxlenbinr'   bool)
iterabletmanttexpr   r  rE   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~Qr3  )      @Cr   g      g?C)r4  r         9g     @C)g     @Cr   r5  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  rI   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$  r1  min_expr    r;   fromhexappend	enumeraterS   fsumr   rz   r   r   r:  r;  r<  )ra   r$  r2  r   test_valuesr$   termsvalsr)   actualr:  r;  r<  jsvr0  r1  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@)rS   gcdr   r   r   rq   )ra   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)rI   Nrk   ).0rJ  s     r   	<genexpr>z&MathTests.testHypot.<locals>.<genexpr>  s     5qad5s   g      (@r         *@rR  rx      rV  r   r         %      %@r   r   r   r   r   皙?string皙@r   r  r   r   )!r   r   	fractionsre  rS   hypotr   r~   sqrtgammasinr    r(  assertAlmostEqualsumr   r*  r   r   r   r?  r$  
max_10_expr   r   r   r   r   r   rT   	FLOAT_MAXisclose	FLOAT_MIN)ra   r   re  rs  r   r$   int_too_big_for_float	fourthmaxr   rE   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]  rI   )rS   rs  r   r   Contextr;   rA  subTestlocalcontextrt  r   )	ra   rs  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   rc  rd  )r   r   r   )r   r   r   r   r   rI   r   )r   rI   r   	   rx   c              3   H   K   | ]  }t        j                  d d        ywrx   Nr:  uniformrh  ks     r   ri  z%MathTests.testDist.<locals>.<genexpr>       BA&..Q/B    "c              3   H   K   | ]  }t        j                  d d        ywr  r  r  s     r   ri  z%MathTests.testDist.<locals>.<genexpr>  r  r  c              3   2   K   | ]  \  }}||z
  d z    yw)r   Nrk   )rh  pxqxs      r   ri  z%MathTests.testDist.<locals>.<genexpr>  s     F&"bb2g#-Fs   )g      ,@r   )r   r   rj  )   r   )rI   rk  r  r   rI   r  rV  )TTFTF)TFTTFr   )     *@g      )@      
r   rk   r   )r   )r   )r   r   r   )r   r   r   )r   r   r   c                       e Zd Zy)MathTests.testDist.<locals>.TNro   rk   r   r   Tr    r   r   r  )r   rx   rY  pq)r=  r   r  )ro  rp  rq  )r   rI   r   r   )rx   rY  r=  )r   rx   rY  r=  abcxyzr   )rI   r      rl  r   rm  r   repeatr   r   )r   r   )%r   r   rr  re  rS   distrt  r   r    tuplerw  rx  zipiterr   r   r   r   r?  r$  ry  r   r:  r'   r   r   r   	itertoolsproductanymaprU   rT   r   rz  r{  r|  )ra   DFr  rt  r$   rI  r  r  r  r}  valuesr  r  diffsr~  r   rE   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   rI   )r   r   rx   )r   r   rS   r  re   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(   rI   r   i'  r   i  r^   r   r   TFr   c                       e Zd Zd Zd Zy)(MathTests.testIsqrt.<locals>.IntegerLikec                     || _         y r]   r^   r`   s     r   rb   z1MathTests.testIsqrt.<locals>.IntegerLike.__init__  s	    "
r   c                     | j                   S r]   r^   re   s    r   rt   z2MathTests.testIsqrt.<locals>.IntegerLike.__index__  s    zz!r   Nru   rk   r   r   IntegerLiker    s    #"r   r  i  r  r   rf  za stringz3.5y              @g      Y@r   )listr    r  rS   isqrtassertIsr   rR   assertLessEqual
assertLessr   r   r   objectr   r   r   )ra   r   r$   rE  r_   rJ  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=  rN  rO  iY  rP  rQ  iH  rS  rT  rU  l    ,`aUx-xB:Vn
Ldbl   me%Y% l   };T^	 )rW  l   |/Kr2 rX  i7  rZ  r[  )rS   lcmr   r   r   rq   )ra   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)rI   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   rS   r&  r|   r   r   r   r   r   rT   r   ra   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)rV  rI   rx   zlog(10**40, 10)r   r  zlog(10**40, 10**20)r  zlog(10**1000)r   gO+@r   )r   r   rS   logr|   r   r   r   r   r   r   rT   r   re   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 )NrI   Z   i,  r   )	r   r   rS   log1prw  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   rI   r   r   r   i  g     @   g      @i  g     @@r   )
r   r   rS   log2r   r   r   r   rT   r   re   s    r   testLog2zMathTests.testLog2  s   )TYY/ 	1s+1s+1s+ 	1d7+V41d7+V41d7+V4*dii6*dii6

499S>23r   r   c           	          t        dd      D cg c]+  }t        j                  t        j                  d|            - }}t        dd      D cg c]  }t	        |       }}| j                  ||       y c c}w c c}w )Nr7  r  r   )r    rS   r  r&  r;   r   )ra   r   rH  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   rS   log10r|   r   r   r   r  r   r   rT   r   re   s    r   	testLog10zMathTests.testLog10  s    )TZZ0

<C"5

:tzz!}a0

;

22

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

4::c?34r   c                    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         @rf  g      @g     0@r   )r   g      r   rx   r   )r  r      r   r  c              3   ,   K   | ]  \  }}||z    y wr]   rk   )rh  p_iq_is      r   ri  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  ra   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)rh   ri   rj   r  r  rk   r   r   BadMultiplyr    s    ##r   r  r  g333333$@g3333334@gL>@gL4@))r  r  r   )r                           r   )rS   sumprodr   r   rr  re  r   r  r  rx  r  r   r   r   r   r  r    r   r   rT   r   )ra   r  r   re  rK  r  r  r)   rH  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   )rS   r  r   )ra   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]   rR   ra   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  re   s    r   __repr__z3MathTests.test_sumprod_stress.<locals>.Int.__repr__      c$i[**r   Nrh   ri   rj   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  re   s    r   r  z3MathTests.test_sumprod_stress.<locals>.Flt.__repr__)  r  r   Nr  r  s   r   Fltr  "  r  r   r  c                 H    	 d}t        | |d      D ]  \  }}|||z  z  } |S )Nr   Tr  )r  )r  r  r   r  r  s        r   baseline_sumprodz7MathTests.test_sumprod_stress.<locals>.baseline_sumprod,  s=     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)NNone)AssertionError	NameError	Exceptionr   repr)funcr   r  r   s       r   runz*MathTests.test_sumprod_stress.<locals>.run6  s]    V-t
 ftF|33	 #I.  -Awf,,-s    AA
A
Ar  r   i  l        l        r  r  rI   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      @      @rk  r   r  g      z10.5z-2.25r   i   y      @      ?a   iz6.125z12.375z-2.75r   InfrR  g      +@g      pl     g      pg      `g      )g      <g         r(  g      r&  g      g      g     `7@TFrx   r   r  )rS   r  r  r  r   r   rr  re  rR   r;   r    r   )ra   r  r  r   re  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   rd  )starmap)
namedtuple)r  r   r   )choicesr  r<  )median
DotExample)r   r]  target_sumprod	conditionc           
          t        |       }t        |      }t         j                  t        ||d                  S )NTr  )r  rx  mulr  )r   r]  vec1vec2re  operatorr6  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]  rB  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 r   )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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 )	NrI   r   )r  r   r   r   r   r   )r    rR   r  r  roundr  )r   r^  n2r   r]  r`  r   r  r$   pairsrD  rB  r:  r8  r   rI  r  r<  r  s             r   GenDotzBMathTests.test_sumprod_extended_precision_accuracy.<locals>.GenDotx  s    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 r   )r  )	resexr   r]  r;  r<  r   rB  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]   )rS   r  )rh  r$   rU  r^  r   s     r   ri  zEMathTests.test_sumprod_extended_precision_accuracy.<locals>.<genexpr>  s     NAeDLL!Q7Ns   "%r6  )rA  rr  re  r  r6  collectionsr7  rS   r  r   r   r:  r8  r  r<  
statisticsr9  r    r  )ra   r7  r9  timesrelative_errrD  rB  r:  re  rN  rR  rU  r^  r8  r   r   rI  r  r   rA  r<  r6  r  s        @@@@@@@@@@@@@@@@@@r   (test_sumprod_extended_precision_accuracyz2MathTests.test_sumprod_extended_precision_accuracy\  s     	&%*))44%.WX
	L
	R	6$	E $	EL	,
	*
  NuNNe,r   c                 V     j                  t        t        j                          fd} |dt        j                  d      d        |dt        j                  d      d        j	                  t        j                  t
              dt
        f        j	                  t        j                  t              d	t        f       t        j                  t              } j                  t        j                  |d
                 j                  t        j                  |d                y )Nc                     ||c\  }}\  }}t        ||z
        t        kD  st        ||z
        rj                  | d|d|       y y r  r  )r{   r  r)   v1v2e1e2ra   s          r   testmodfz$MathTests.testModf.<locals>.testmodf  sN    !'HRhr22b5zC3r"u:		3 4 $.r   z	modf(1.5)r   )r   r   z
modf(-1.5)r   )r   r   r   r   r   r   )
r   r   rS   modfr   r   r   r   r   rT   )ra   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)rI   z	pow(2,-1)r   r   r   r   r   r   r   r   g       r   r  r   g      .ggffffff?ro  ?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   rS   powr|   r   r   r   r   rT   r   r   re   s    r   testPowzMathTests.testPow  s   )TXX.

:txx!}a0

:txx!}a0

:txx!}a0

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

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

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

488As#345!S)1- 	"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  rI   zradians(-45)ir   z
radians(0)r   )r   r   rS   radiansr|   r~   re   s    r   testRadianszMathTests.testRadians\  s    )T\\2

>4<<#4dgg>

=$,,r"2DGGAI>

>4<<#4twwhqjA

<a!4r   c                     ddl m  fd}g d}|D ]  } j                  |      5  |j                         \  }}}t        j                  |      }t        j                  |      }t        j                  |      }	 ||||	       t        j                  ||      }
 j                  |
j                         |	j                                d d d         t        j                  d      }t        dd      D ]d  }|dk(  r	||z  }t        d	      D ]I  }||z  }t        j                  ||      }
 ||||
       t        j                  | |      }
 || ||
       K f t        d
dddt        t        fD ]T  } j                  t        j                  t        |              j                  t        j                  |t                     V dD ]V  } j                  t        j                  |t              |        j                  t        j                  |t              |       X t        ddd
dt        fD ]  } j                  t               5  t        j                  t        |       d d d         j                  t               5  t        j                  t        |       d d d         j                  t               5  t        j                  |d
       d d d         j                  t               5  t        j                  |d       d d d         y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   exY w# 1 sw Y   xY w)Nr   rd  c                 D   	  |        |       |      }}}j                  t        |      t        |dz               ||z
  |z  }j                  |t        |             t        |      t        |dz        k(  r"j                  |dz  t        |dz               y y )NrI   )r  r'   r   rR   )	r   r]  rfxfyfrr   re  ra   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   )rr  re  r  r:   r;   rA  rS   	remainderr   hexr    r   r   r   assertIsNaNr   r   )ra   rt  	testcasesru  x_hexy_hexexpected_hexr   r]  r)   rH  tinyr   mr_   re  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)rI   r   z
sin(-pi/2)r   )r   r   rS   rv  r|   r~   r   rT   r   r   r   r   re   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   rI   r   zsinh(1)+sinh(-1))r   r   rS   sinhr|   r   r   r   r   r   rT   r   re   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   rI   r   )r   r   rS   rt  r|   r   r   r   r   r   rT   r   re   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   rS   tanr|   r~   r   rT   r   r   r   r   re   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   rS   tanhr|   r   r   r   r   rT   r   re   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   rS   r  r   re   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   rk   re   s    r   	__trunc__z1MathTests.test_trunc.<locals>.TestTrunc.__trunc__2  r   r   Nrh   ri   rj   r  rk   r   r   	TestTruncr  1  r   r   r  c                       e Zd Zd Zy)(MathTests.test_trunc.<locals>.FloatTruncc                      yr  rk   re   s    r   r  z2MathTests.test_trunc.<locals>.FloatTrunc.__trunc__5  r   r   Nr  rk   r   r   
FloatTruncr  4  r   r   r  c                       e Zd Zy))MathTests.test_trunc.<locals>.TestNoTruncNro   rk   r   r   TestNoTruncr  7  r   r   r  r  rI   g     7@)	r   rS   truncr   rR   r;   r   r   r[   )ra   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   rS   isfiniteassertFalser;   re   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   rS   rT   r;   r  re   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   rS   rU   r;   r  re   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   rS   rT   r   r   r   re   s    r   test_nan_constantzMathTests.test_nan_constant\  s:    

488,-r4884b9r   c                 N   | j                  t        j                  t        j                               | j	                  t        j                  d       | j                  t        j                  t        d             | j                  t        j                   t        d             y )Nr   r   r   )r   rS   rU   r   assertGreaterr   r;   re   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)rS   rE   rz   r   rt  r   ra   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   rx   invaliddivide-by-zeror   overflowr   rx   r   zFailures in test_testfile:
  
  )r?  platformmac_verr  r  rR   r:   r   rO   	test_filegetattrrS   r   rY   r(   rB  rz   join)ra   SKIP_ON_TIGERosx_versionversion_txtrW   failuresrA   rB   araiereirF   r"  r  r+   r,   rV   msgs                      r   test_testfilezMathTests.test_testfile  s    #<<8#"**,Q/K#C[->->s-C$DE &-;I-F "	!)BBBESyB#I&&&;+@&4$DE!%5%>!u$$)b  &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  ru  r  lgammagV瞯<erfcr   r   r         $@r   r   zFailures in test_mtestfile:
  r  )rG   math_testcasesr  rS   r   r   rY   r(   rB  rz   r  )ra   rW   r  rA   rB   rC   r)   rF   r"  r*   r+   r,   rV   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   rx   )r   rI   r   i  r   i _7 )r   rI   r   r   rx   rP  )r   r   r   r   r   rZ  )r   rI   r   r   r   )r   r   r   r   rx   )r   r           r   r   r  )r   r   r  r   r   r   )r_  r`  r^      a   cr      br   ababababababab)r   rI   r   rI   r   rI   r   rI   r   rI   r   rI   r  )r   r   rI   r   r   )r   r   rI   r   )r   rI   r   r   c                     | D ]  }||z  }	 |S r]   rk   )r+  r   elems      r   _naive_prodz(MathTests.test_prod.<locals>._naive_prod2  s      Lr   i'  ir   ir   r   r   r   r   r   )r   rI   r   r   rx   rY  )r   r   r   r   rx   rY  r   r   rY  )r   )rS   prodr   r  r    r  r;   r   r   	bytearrayrx  r   rR   r   r   )ra   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   rI   r   Tcpython)TT)TF)FFrx   )rS   permr   r    r   r   r   r   r   r   r   check_impl_detailr   r  r   rR   rn   rq   )ra   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   rI   r   r  r  r  r   r   r   Tr  r  rx   )rS   combr   r    r   r   r   r   r   r   r   r  r   r  r   rR   rn   rq   )ra   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+0rx   r   r   r   r   )r   rS   	nextafterr   r;   rA  r    assertEqualSignr?  r$  minepsilonr'  rx  r   r   r   )ra   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   rn  )r   rS   r   r?  r$  r  r  rz  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   )	convertedre   s    r   rf   z.MathTests.test_issue39871.<locals>.F.__float__A	  s    !%!r   N)rh   ri   rj   rf   rk   r   r   r  r  @	  s    r   r  znot a numberr  F)rS   r   r   rv  r   r   r  r  )ra   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}.)rS   rT   rz   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 r  )r   rS   r   )ra   r   r]  s      r   r  zMathTests.assertEqualSignS	  s?    	 	AsA.c10EFr   Nr  )Urh   ri   rj   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_ROUNDINGrL  ra  r  r  r  r  r  r  r  r  r  r  requires_mac_verr  r  r  r   requires_resourcer4  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  rk   r   r   rw   rw      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   rw   c                   ~    e Zd Zej                  Zd Zd Zd Zd Zd Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zy)IsCloseTestsc                 `    | j                   | j                  ||g|i ||d|d       y )N and z should be close!r  )r   r{  ra   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  r{  r  s        r   assertIsNotClosezIsCloseTests.assertIsNotClosec	  s7    a<T<V<ABAF 	 	Hr   c                 F    |D ]  \  }} | j                   ||g|i |  y r]   )r  ra   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_tolr3  g    _©r  r,   )r   r   r  re   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  )ra   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  )ra   eight_decimal_places_exampless     r   test_eight_decimal_placesz&IsCloseTests.test_eight_decimal_places	  s5    )C% 	94H<dKr   c                 X    g d}| j                  |d       | j                  |d       y )N))r&  r   )g&.r   )gu?j/ʠr   rg  r  r%  r   )r  r  )ra   near_zero_exampless     r   test_near_zerozIsCloseTests.test_near_zero	  s4    . 	13?.=r   c                     | j                  t        t               | j                  t        t        d       | j                  t        t               | j                  t        t        d       y )Nr   r   )r  r   r   re   s    r   test_identical_infinitez$IsCloseTests.test_identical_infinite	  sL    3$3S14&4s3r   c                     t         t         ft         dfdt         ft        t         ft         t        ft        t        ft        dfdt        ft        dfdt        fg
}| j                  |d       y )Nr3  r   gg?r   )r   r   r   r  )ra   not_close_exampless     r   test_inf_ninf_nanzIsCloseTests.test_inf_ninf_nan	  sg    "Cj"Fm%sm"Cj"Cj"Dk"Cj"Cj"El$cl	, 	1;LMr   c                 `    g d}| j                  |d       g d}| j                  |d       y )N))r   r   )333333r3  )Ynr4  r   r  ))r   g     ?)g?r   )gZbtigTbtir'  )ra   zero_tolerance_close_examples!zero_tolerance_not_close_exampless      r   test_zero_tolerancez IsCloseTests.test_zero_tolerance	  s?    )=% 	93G-N) 	@#Nr   c                 .    | j                  ddgd       y )N)r  r   )r   r  r  r  r!  re   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'  )ra   integer_exampless     r   test_integerszIsCloseTests.test_integers	  s:    224 	,d;/>r   c                     ddl m}  |d       |d      f |d       |d      f |d       |d      f |d	       |d
      fg}| j                  |d       | j                  |d       y )Nr   rc  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  )ra   r   decimal_exampless      r   test_decimalszIsCloseTests.test_decimals	  s    #$\2GENC$%56	8JK$%679LM$_5wx7HIK 	,d;/>r   c                     ddl m}  |dd      dz    |d      f |d       |d      f |dd       |dd      fg}| j                  |d	       | j                  |d
	       y )Nr   rd  r   r<  r;  l       	(qe	 r  r%  r  r&  )rr  re  r  r  )ra   re  fraction_exampless      r   test_fractionszIsCloseTests.test_fractions	  sz    & a#a'!5i (9"56i((1f*=>@ 	-t<0$?r   N)rh   ri   rj   rS   r{  r  r  r  r  r  r#  r)  r,  r.  r1  r7  r9  r>  rA  rD  rk   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)doctestrF  addTest)loadertestspatternrF  s       r   
load_testsrL  	  s    $	MM,}-.Lr   r  )9test.supportr   r   testr   r   rr  r  r   rS   osr  r:  r   r?  r   r;   r   r   r   r$  r'  rz  r  r|  r   r]  r  rh   argvfile__file__pathdirnamecurdirtest_dirr  r  r  r   r   r   r%   r0   rG   rO   rY   r[   rR   rn   r  rq   TestCaserw   r	  rL  mainrk   r   r   <module>rY     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   