B
    18™\ý  ã               @   sp  d dl mZmZmZ d dlmZ d dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZdZedƒZedƒZedƒZejjZd\ZZee d	kZed
kr¤ejd  ZneZej e¡p¸ejZej  ed¡Z!ej  ed¡Z"dd„ Z#dd„ Z$dd„ Z%dd„ Z&dd„ Z'dd„ Z(dd„ Z)dd„ Z*d)dd „Z+G d!d"„ d"e,ƒZ-G d#d$„ d$ej.ƒZ/G d%d&„ d&ej.ƒZ0d'd(„ Z1ed
krle1ƒ  dS )*é    )Úrun_unittestÚverboseÚrequires_IEEE_754)ÚsupportNgñhãˆµøä>ÚnanÚinfz-inf)g €à7yÃACgÇ):’Ëÿ@g€à7yÃACÚ__main__zmath_testcases.txtzcmath_testcases.txtc             C   s.   t  dt  d| ¡¡d }|dk r*|d  }|S )a›  Convert a non-NaN float x to an integer, in such a way that
    adjacent floats are converted to adjacent integers.  Then
    abs(ulps(x) - ulps(y)) gives the difference in ulps between two
    floats.

    The results from this function will only make sense on platforms
    where native doubles are represented in IEEE 754 binary64 format.

    Note: 0.0 and -0.0 are converted to 0 and -1, respectively.
    z<qz<dr   l            )ÚstructÚunpackÚpack)ÚxÚn© r   úR/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Lib/test/test_math.pyÚto_ulps#   s    
r   c             C   s’   t t| ƒƒ} t | ¡s t | ¡r$| S t dt d| ¡¡d }t dt d|d ¡¡d }t |¡r†t dt d|d ¡¡d }| | S ||  S dS )a  Return the value of the least significant bit of a
    float x, such that the first float bigger than x is x+ulp(x).
    Then, given an expected result x and a tolerance of n ulps,
    the result y should be such that abs(y-x) <= n * ulp(x).
    The results from this function will only make sense on platforms
    where native doubles are represented in IEEE 754 binary64 format.
    z<qz<dr   é   N)ÚabsÚfloatÚmathÚisnanÚisinfr	   r
   r   )r   r   Zx_nextZx_prevr   r   r   Úulp4   s    
r   c             C   s   | rdt | | d @ ƒ S dS )zANumber of '1' bits in binary expansion of a nonnnegative integer.r   r   )Úcount_set_bits)r   r   r   r   r   a   s    r   c             C   sD   ||  d? }|sdS |dkr | S | | dB }t | |ƒt ||ƒ S dS )z„Product of integers in range(start, stop, 2), computed recursively.
    start and stop should both be odd, with start <= stop.

    r   N)Úpartial_product)ÚstartÚstopZ
numfactorsZmidr   r   r   r   e   s    r   c             C   sd   d }}xJt t|  ¡ ƒƒD ]6}|t| |d ? d dB | |? d dB ƒ9 }||9 }qW || t| ƒ > S )z™Factorial of nonnegative integer n, via "Binary Split Factorial Formula"
    described at http://www.luschny.de/math/factorial/binarysplitfact.html

    r   )ÚreversedÚrangeÚ
bit_lengthr   r   )r   ÚinnerZouterÚir   r   r   Úpy_factorials   s
    *r!   c             C   sL   t t| ƒt|ƒ ƒ}t | | ƒ}||ks0||kr4dS d}| ||||¡S dS )zôGiven finite floats `expected` and `got`, check that they're
    approximately equal to within the given number of ulps or the
    given absolute tolerance, whichever is bigger.

    Returns None on success and an error message on failure.
    NzAerror = {:.3g} ({:d} ulps); permitted error = {:.3g} or {:d} ulps)r   r   Úformat)ÚexpectedÚgotÚulp_tolÚabs_tolZ	ulp_errorZ	abs_errorÚfmtr   r   r   Úulp_abs_check~   s    r(   c          	   c   sš   t | ƒˆ}x€|D ]x}d|kr.|d| d¡… }| ¡ s8q| d¡\}}| ¡ \}}}| ¡ }|d }	|dd… }
||t|ƒt|	ƒ|
fV  qW W dQ R X dS )zÏParse a file with test values

    -- starts a comment
    blank lines, or lines containing only a comment, are ignored
    other lines are expected to have the form
      id fn arg -> expected [flag]*

    z--Nz->r   r   )ÚopenÚindexÚstripÚsplitr   )ÚfnameÚfpÚlineÚlhsÚrhsÚidÚfnÚargÚ
rhs_piecesÚexpÚflagsr   r   r   Úparse_mtestfile   s    	

r8   c          	   c   s¢   t | ƒ}xˆ|D ]€}| d¡s| ¡ s(q| d¡\}}| ¡ \}}}}| ¡ }	|	d |	d  }
}|	dd… }||t|ƒt|ƒt|
ƒt|ƒ|fV  qW W dQ R X dS )z“Parse a file with test values

    Empty lines or lines starting with -- are ignored
    yields id, fn, arg_real, arg_imag, exp_real, exp_imag
    z--z->r   r   é   N)r)   Ú
startswithr+   r,   r   )r-   r.   r/   r0   r1   r2   r3   Zarg_realZarg_imagr5   Zexp_realZexp_imagr7   r   r   r   Úparse_testfileª   s    

r;   é   ç        c             C   sÎ   || krdS d}t | tƒr.t |tƒr.t|ƒ}nt |tƒrJt | tƒrJt| ƒ} t | tƒrœt |tƒrœt | ¡rxt |¡rxd}n$t | ¡sœt |¡rŽnt| |||ƒ}|dk	rÆd}| | |¡}|d |¡7 }|S dS dS )aœ  Compare arguments expected and got, as floats, if either
    is a float, using a tolerance expressed in multiples of
    ulp(expected) or absolutely (if given and greater).

    As a convenience, when neither argument is a float, and for
    non-finite floats, exact equality is demanded. Also, nan==nan
    as far as this function is concerned.

    Returns None on success and an error message on failure.
    Nz	not equalzexpected {!r}, got {!r}z ({}))Ú
isinstancer   Úintr   r   r   r(   r"   )r#   r$   r%   r&   ÚfailureÚfail_fmtZfail_msgr   r   r   Úresult_checkÂ   s&    
rB   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚMyIndexablec             C   s
   || _ d S )N)Úvalue)ÚselfrD   r   r   r   Ú__init__ñ   s    zMyIndexable.__init__c             C   s   | j S )N)rD   )rE   r   r   r   Ú	__index__ô   s    zMyIndexable.__index__N)Ú__name__Ú
__module__Ú__qualname__rF   rG   r   r   r   r   rC   ð   s   rC   c               @   s  e Zd Zdndd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zedd„ ƒZdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zejd%d&„ ƒZd'd(„ Zd)d*„ Zd+d,„ Zee ed-¡d.d/„ ƒƒZd0d1„ Zd2d3„ Z d4d5„ Z!d6d7„ Z"d8d9„ Z#ed:d;„ ƒZ$ee %d<d¡d=d>„ ƒƒZ&d?d@„ Z'dAdB„ Z(dCdD„ Z)dEdF„ Z*edGdH„ ƒZ+dIdJ„ Z,dKdL„ Z-dMdN„ Z.dOdP„ Z/dQdR„ Z0ee e1 2dS¡dTkdU¡dVdW„ ƒƒZ3dXdY„ Z4dZd[„ Z5d\d]„ Z6d^d_„ Z7ed`da„ ƒZ8edbdc„ ƒZ9e :e;dd¡dedf„ ƒZ<edgdh„ ƒZ=edidj„ ƒZ>dkdl„ Z?dmS )oÚ	MathTestsr<   ç        c             C   s,   t ||||ƒ}|dk	r(|  d ||¡¡ dS )aa  Compare arguments expected and got, as floats, if either
        is a float, using a tolerance expressed in multiples of
        ulp(expected) or absolutely, whichever is greater.

        As a convenience, when neither argument is a float, and for
        non-finite floats, exact equality is demanded. Also, nan==nan
        in this function.
        Nz{}: {})rB   Úfailr"   )rE   Únamer$   r#   r%   r&   r@   r   r   r   Úftestù   s    	zMathTests.ftestc             C   s8   |   dtjd¡ |   dtjd¡ |  tjdtj ¡ d S )NÚpig-DTû!	@ÚegiW‹
¿@r9   )rO   r   rP   rQ   ÚassertEqualÚtau)rE   r   r   r   ÚtestConstants  s    zMathTests.testConstantsc             C   s´   |   ttj¡ |  dt d¡tj¡ |  dt d¡tjd ¡ |  dt d¡d¡ |   ttjt¡ |   ttjt¡ |   ttjdt	 ¡ |   ttjdt	 ¡ |  
t t t¡¡¡ d S )Nzacos(-1)éÿÿÿÿzacos(0)r   r9   zacos(1)r   )ÚassertRaisesÚ	TypeErrorr   ÚacosrO   rP   Ú
ValueErrorÚINFÚNINFÚepsÚ
assertTruer   ÚNAN)rE   r   r   r   ÚtestAcos  s    zMathTests.testAcosc             C   s’   |   ttj¡ |  dt d¡d¡ |  dt d¡d¡ |   ttjd¡ |   ttjd¡ |  t t¡t¡ |   ttjt¡ |  	t 
t t¡¡¡ d S )Nzacosh(1)r   r   zacosh(2)r9   g5˜qBõ?rU   )rV   rW   r   ÚacoshrO   rY   rR   rZ   r[   r]   r   r^   )rE   r   r   r   Ú	testAcosh  s    zMathTests.testAcoshc             C   sº   |   ttj¡ |  dt d¡tj d ¡ |  dt d¡d¡ |  dt d¡tjd ¡ |   ttjt¡ |   ttjt¡ |   ttjdt	 ¡ |   ttjdt	 ¡ |  
t t t¡¡¡ d S )Nzasin(-1)rU   r9   zasin(0)r   zasin(1)r   )rV   rW   r   ÚasinrO   rP   rY   rZ   r[   r\   r]   r   r^   )rE   r   r   r   ÚtestAsin!  s    zMathTests.testAsinc             C   sˆ   |   ttj¡ |  dt d¡d¡ |  dt d¡d¡ |  dt d¡d¡ |  t t¡t¡ |  t t¡t¡ |  t 	t t
¡¡¡ d S )	Nzasinh(0)r   zasinh(1)r   g'Ôya64ì?z	asinh(-1)rU   g'Ôya64ì¿)rV   rW   r   ÚasinhrO   rR   rZ   r[   r]   r   r^   )rE   r   r   r   Ú	testAsinh,  s    zMathTests.testAsinhc             C   s¨   |   ttj¡ |  dt d¡tj d ¡ |  dt d¡d¡ |  dt d¡tjd ¡ |  dt t¡tjd	 ¡ |  d
t t¡tj d	 ¡ |  t 	t t
¡¡¡ d S )Nzatan(-1)rU   é   zatan(0)r   zatan(1)r   z	atan(inf)r9   z
atan(-inf))rV   rW   r   ÚatanrO   rP   rZ   r[   r]   r   r^   )rE   r   r   r   ÚtestAtan5  s    zMathTests.testAtanc             C   s¤   |   ttj¡ |  dt d¡d¡ |  dt d¡d¡ |  dt d¡d¡ |   ttjd	¡ |   ttjd
¡ |   ttjt¡ |   ttjt¡ |  	t 
t t¡¡¡ d S )Nzatanh(0)r   z
atanh(0.5)g      à?g­zê“á?zatanh(-0.5)g      à¿g­zê“á¿r   rU   )rV   rW   r   rg   rO   ÚatanhrY   rZ   r[   r]   r   r^   )rE   r   r   r   Ú	testAtanh>  s    zMathTests.testAtanhc             C   s  |   ttj¡ |  dt dd¡tj d ¡ |  dt dd¡tj d ¡ |  dt dd¡d¡ |  d	t dd¡tjd ¡ |  d
t dd¡tjd ¡ |  dt dt¡tj¡ |  dt dd¡tj¡ |  dt dd¡tj¡ |  t dd¡d¡ |  t dd¡d¡ |  t dt¡d¡ |  	t 
t dt¡¡¡ |  dt dt¡tj ¡ |  dt dd¡tj ¡ |  dt dd¡tj ¡ |  t dd¡d¡ |  t dd¡d¡ |  t dt¡d¡ |  	t 
t dt¡¡¡ |  dt tt¡tjd d ¡ |  dt td¡tjd ¡ |  dt td¡tjd ¡ |  dt td¡tjd ¡ |  dt td¡tjd ¡ |  dt tt¡tjd ¡ |  	t 
t tt¡¡¡ |  dt tt¡tj d d ¡ |  dt td¡tj d ¡ |  dt td¡tj d ¡ |  dt td¡tj d ¡ |  d t td¡tj d ¡ |  d!t tt¡tj d ¡ |  	t 
t tt¡¡¡ |  d"t dt¡tj¡ |  d#t dd¡tjd ¡ |  d$t dd¡tjd ¡ |  t dt¡d¡ |  	t 
t dt¡¡¡ |  d%t dt¡tj ¡ |  d&t dd¡tj d ¡ |  d't dd¡tj d ¡ |  t dt¡d¡ |  	t 
t dt¡¡¡ |  	t 
t tt¡¡¡ |  	t 
t td¡¡¡ |  	t 
t td¡¡¡ |  	t 
t td¡¡¡ |  	t 
t td¡¡¡ |  	t 
t tt¡¡¡ |  	t 
t tt¡¡¡ d S )(Nzatan2(-1, 0)rU   r   r9   zatan2(-1, 1)r   rf   zatan2(0, 1)zatan2(1, 1)zatan2(1, 0)zatan2(0., -inf)g        zatan2(0., -2.3)gffffffÀzatan2(0., -0.)g       €gffffff@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.))rV   rW   r   Úatan2rO   rP   r[   rR   rZ   r]   r   r^   )rE   r   r   r   Ú	testAtan2I  sf     "zMathTests.testAtan2c             C   s  |   ttj¡ |  ttt d¡ƒ¡ |  dt d¡d¡ |  dt d¡d¡ |  dt d¡d¡ |  d	t d
¡d¡ |  dt d¡d¡ |  dt d¡d¡ G dd„ dƒ}G dd„ dƒ}|  dt |ƒ ¡d¡ |   ttj|ƒ ¡ |ƒ }dd„ |_|   ttj|¡ |   ttj|d¡ d S )Ng      à?z	ceil(0.5)r   z	ceil(1.0)g      ð?z	ceil(1.5)g      ø?r9   z
ceil(-0.5)g      à¿r   z
ceil(-1.0)g      ð¿rU   z
ceil(-1.5)g      ø¿c               @   s   e Zd Zdd„ ZdS )z$MathTests.testCeil.<locals>.TestCeilc             S   s   dS )Né*   r   )rE   r   r   r   Ú__ceil__”  s    z-MathTests.testCeil.<locals>.TestCeil.__ceil__N)rH   rI   rJ   ro   r   r   r   r   ÚTestCeil“  s   rp   c               @   s   e Zd ZdS )z&MathTests.testCeil.<locals>.TestNoCeilN)rH   rI   rJ   r   r   r   r   Ú
TestNoCeil–  s   rq   zceil(TestCeil())rn   c              W   s   | S )Nr   )Úargsr   r   r   Ú<lambda>œ  ó    z$MathTests.testCeil.<locals>.<lambda>)	rV   rW   r   ÚceilrR   r?   ÚtyperO   ro   )rE   rp   rq   Útr   r   r   ÚtestCeil†  s     
zMathTests.testCeilc             C   sö  |   t dd¡d¡ |   t dd¡d¡ |   t dd¡d¡ |   t dd¡d¡ |   t d	d
¡d¡ |  ttj¡ |   t dd¡d¡ |   t dd
¡d¡ |   t td¡t¡ |   t td
¡t¡ |   t td¡t¡ |   t td
¡t¡ |   t dt¡d¡ |   t dt¡d¡ |   t tt¡t¡ |   t tt¡t¡ |   t tt¡t¡ |   t tt¡t¡ |  t t t	d¡¡¡ |  t t t	t¡¡¡ |  t t t	t¡¡¡ |  t t t	t	¡¡¡ |  t 
t tt	¡¡¡ |   tt dt	¡ƒd¡ d S )Nr   rn   g      ð?g        iÖÿÿÿg      ð¿rk   g      @g      @g       €g      Àg       @)rR   r   ÚcopysignrV   rW   rZ   r[   r]   r   r^   r   r   )rE   r   r   r   ÚtestCopysign   s0    zMathTests.testCopysignc             C   sþ   |   ttj¡ | jdt tj d ¡dtdƒd |  dt d¡d¡ | jdt tjd ¡dtdƒd |  dt tj¡d	¡ y0|  t t t	¡¡¡ |  t t t
¡¡¡ W n4 tk
râ   |   ttjt	¡ |   ttjt
¡ Y nX |  t t t¡¡¡ d S )
Nz
cos(-pi/2)r9   r   r   )r&   zcos(0)z	cos(pi/2)zcos(pi)rU   )rV   rW   r   ÚcosrO   rP   r   r]   r   rZ   r[   rY   r^   )rE   r   r   r   ÚtestCosÂ  s    $"zMathTests.testCosc             C   s†   |   ttj¡ |  dt d¡d¡ |  dt d¡dt d¡d   d¡ |  t t¡t¡ |  t t¡t¡ |  t 	t t
¡¡¡ d S )Nzcosh(0)r   r   zcosh(2)-2*cosh(1)**2r9   rU   )rV   rW   r   ÚcoshrO   rR   rZ   r[   r]   r   r^   )rE   r   r   r   ÚtestCoshÐ  s    &zMathTests.testCoshc             C   sr   |   ttj¡ |  dt tj¡d¡ |  dt tjd ¡d¡ |  dt tj d ¡d¡ |  d	t d
¡d
¡ d S )Nzdegrees(pi)g     €f@zdegrees(pi/2)r9   g     €V@zdegrees(-pi/4)rf   g     €FÀz
degrees(0)r   )rV   rW   r   ÚdegreesrO   rP   )rE   r   r   r   ÚtestDegreesØ  s
    zMathTests.testDegreesc             C   s    |   ttj¡ |  dt d¡dtj ¡ |  dt d¡d¡ |  dt d¡tj¡ |  t t¡t¡ |  t t¡d¡ |  	t 
t t¡¡¡ |   ttjd¡ d S )	Nzexp(-1)rU   r   zexp(0)r   zexp(1)g        i@B )rV   rW   r   r6   rO   rQ   rR   rZ   r[   r]   r   r^   ÚOverflowError)rE   r   r   r   ÚtestExpß  s    zMathTests.testExpc             C   sN   |   ttj¡ |  dt d¡d¡ |  dt d¡d¡ |  dt d¡d¡ d S )Nzfabs(-1)rU   r   zfabs(0)r   zfabs(1))rV   rW   r   ÚfabsrO   )rE   r   r   r   ÚtestFabsé  s    zMathTests.testFabsc             C   sÞ   |   t d¡d¡ |   t d¡d¡ d}xXtddƒD ]J}||9 }|   t |¡|¡ |   t t|ƒ¡|¡ |   t |¡t|ƒ¡ q4W |  ttjd¡ |  ttjd¡ |  ttjdd  ¡ |  ttjd	¡ |  ttjtj¡ d S )
Nr   r   g        iè  rU   g      ð¿é
   éd   g}Ã”%­I²Ô)	rR   r   Ú	factorialr   r   r!   rV   rY   rP   )rE   Útotalr    r   r   r   ÚtestFactorialï  s    zMathTests.testFactorialc             C   s(   |   ttjdd ¡ |   ttjd¡ d S )Nr…   r†   g}Ã”%­I²T)rV   r   r   r‡   )rE   r   r   r   ÚtestFactorialHugeInputsÿ  s    z!MathTests.testFactorialHugeInputsc             C   s>  |   ttj¡ |  ttt d¡ƒ¡ |  dt d¡d¡ |  dt d¡d¡ |  dt d¡d¡ |  d	t d
¡d¡ |  dt d¡d¡ |  dt d¡d¡ |  dt d¡d¡ |  dt d¡d¡ G dd„ dƒ}G dd„ dƒ}|  dt |ƒ ¡d¡ |   ttj|ƒ ¡ |ƒ }dd„ |_|   ttj|¡ |   ttj|d¡ d S )Ng      à?z
floor(0.5)r   z
floor(1.0)g      ð?r   z
floor(1.5)g      ø?zfloor(-0.5)g      à¿rU   zfloor(-1.0)g      ð¿zfloor(-1.5)g      ø¿éþÿÿÿzfloor(1.23e167)g‚àNÝ¯ bzfloor(-1.23e167)g‚àNÝ¯ âc               @   s   e Zd Zdd„ ZdS )z&MathTests.testFloor.<locals>.TestFloorc             S   s   dS )Nrn   r   )rE   r   r   r   Ú	__floor__  s    z0MathTests.testFloor.<locals>.TestFloor.__floor__N)rH   rI   rJ   rŒ   r   r   r   r   Ú	TestFloor  s   r   c               @   s   e Zd ZdS )z(MathTests.testFloor.<locals>.TestNoFloorN)rH   rI   rJ   r   r   r   r   ÚTestNoFloor  s   rŽ   zfloor(TestFloor())rn   c              W   s   | S )Nr   )rr   r   r   r   rs      rt   z%MathTests.testFloor.<locals>.<lambda>)	rV   rW   r   ÚfloorrR   r?   rv   rO   rŒ   )rE   r   rŽ   rw   r   r   r   Ú	testFloor  s$    
zMathTests.testFloorc             C   sž  |   ttj¡ |  dt dd¡d¡ |  dt dd¡d¡ |  dt dd¡d	¡ |  d
t dd¡d¡ |  dt dd¡d¡ |  dt dd¡d¡ |  t t td	¡¡¡ |  t t d	t¡¡¡ |  t t tt¡¡¡ |   ttjd	d¡ |   ttjt	d	¡ |   ttjt
d	¡ |   ttjt	d¡ |  t dt	¡d¡ |  t dt	¡d¡ |  t dt
¡d¡ |  t dt
¡d¡ |  t dd¡d¡ |  t dt
¡d¡ d S )Nzfmod(10, 1)r…   r   g        zfmod(10, 0.5)g      à?zfmod(10, 1.5)g      ø?g      ð?zfmod(-10, 1)iöÿÿÿg       €zfmod(-10, 0.5)zfmod(-10, 1.5)g      ð¿g      @g      À)rV   rW   r   ÚfmodrO   r]   r   r^   rY   rZ   r[   rR   )rE   r   r   r   ÚtestFmod$  s(    zMathTests.testFmodc                s¬   ˆ   ttj¡ ‡ fdd„}|dt d¡dƒ |dt d¡dƒ |d	t d
¡dƒ |dt d¡dƒ ˆ  t t¡d t¡ ˆ  t t¡d t¡ ˆ  t t t	¡d ¡¡ d S )Nc                sB   || \}}\}}t || ƒtks*||kr>ˆ  d| ||f ¡ d S )Nz%s returned %r, expected %r)r   r\   rM   )rN   Úresultr#   Úmantr6   ZemantZeexp)rE   r   r   Ú	testfrexp=  s    z&MathTests.testFrexp.<locals>.testfrexpz	frexp(-1)rU   )g      à¿r   zfrexp(0)r   )r   r   zfrexp(1)r   )g      à?r   zfrexp(2)r9   )g      à?r9   )
rV   rW   r   ÚfrexprR   rZ   r[   r]   r   r^   )rE   r•   r   )rE   r   Ú	testFrexp:  s    zMathTests.testFrexpz2fsum is not exact on machines with double roundingc                s>  ddl m} |j‰|jˆ ‰ ‡ ‡fdd„}g dfdgdfdddd	d
ddgd	fdddgdfdddgdfdddgdfdddgdfdd„ tddƒD ƒt d¡fdd„ tddƒD ƒt d¡fd d„ td!ƒD ƒd"g dfd#dd$gd%fd&d'd(d)gdfd*d„ td+d,d-ƒD ƒd.g t d/¡fg}xˆt|ƒD ]|\}\}}yt 	|¡}W nR t
k
r^   |  d0|||f ¡ Y n* tk
r†   |  d1|||f ¡ Y nX |  ||¡ qW dd2lm}m}	m}
 xŠtd!ƒD ]~}d3dd4dd5d6gd7 }d}x8td8ƒD ],}|	d|ƒ ƒd3 | }||7 }| |¡ qÞW |
|ƒ ||ƒ}|  ||ƒt 	|¡¡ q¸W d S )9Nr   )Ú
float_infoc                sÞ   d\}}xb| D ]Z}t  |¡\}}tt  |ˆ¡ƒ|ˆ  }}||krT||| K }|}n||| K }||7 }qW tttt|ƒƒƒd ˆ ˆ | ƒ}|dkrÒd|d > }|d|  t||@ oÄ|d| d @ ƒ }||7 }t  ||¡S )zÓFull precision summation.  Compute sum(iterable) without any
            intermediate accumulation of error.  Based on the 'lsum' function
            at http://code.activestate.com/recipes/393090/

            )r   r   r9   r   r   rk   )	r   r–   r?   ÚldexpÚmaxÚlenÚbinr   Úbool)ÚiterableZtmantZtexpr   r”   r6   ÚtailÚh)ÚetinyÚmant_digr   r   Úmsum_  s    
"(z MathTests.testFsum.<locals>.msumg        g}Ã”%­I²Tg      ð?g}Ã”%­I²Ôg0Žä.ÿ++gšd~ÅQJg      ð¿gšd~ÅQÊg      @Cg      à¿g      ¼gÿÿÿÿÿÿ?Cg      °9g     @Cg     @Cg     @Cgüÿÿÿÿÿ?Cg      à?g      <gýÿÿÿÿÿ?Cc             S   s   g | ]}d | ‘qS )g      ð?r   )Ú.0r   r   r   r   ú
<listcomp>‚  s    z&MathTests.testFsum.<locals>.<listcomp>r   ié  z0x1.df11f45f4e61ap+2c             S   s   g | ]}d | | ‘qS )g      ð¿r   )r¤   r   r   r   r   r¥   „  s    z-0x1.62a2af1bd3624p-1c             S   s    g | ]}d |d  d |  ‘qS )g333333û?r   r   )r¤   r    r   r   r   r¥   †  s    iè  gáïþáÒ-Çïg €à7yÃACg¼‰Ø—²Òœ<g€à7yÃACgÿà7yÃACgÿÿÿÿÿÿï?gÿà7yÃAÃgÿÿÿÿÿÿï¿c             S   s,   g | ]$}d | d |d   d |d   ‘qS )g       @é2   é4   r   )r¤   r   r   r   r   r¥   Š  s    iÎûÿÿiÌ  r9   g      Ðÿz0x1.5555555555555p+970zDtest %d failed: got OverflowError, expected %r for math.fsum(%.100r)zAtest %d failed: got ValueError, expected %r for math.fsum(%.100r))ÚrandomÚgaussÚshuffleé   iùÿÿÿghŠ$.5ú»g#B’¡œ÷;r…   éÈ   )Úsysr˜   r¢   Úmin_expr   r   ÚfromhexÚ	enumerater   Úfsumr   rM   rY   rR   r¨   r©   rª   Úappend)rE   r˜   r£   Ztest_valuesr    Úvalsr#   Úactualr¨   r©   rª   ÚjÚsÚvr   )r¡   r¢   r   ÚtestFsumL  sT    


zMathTests.testFsumc             C   sz  t j}|  |ddƒd¡ |  |ddƒd¡ |  |ddƒd¡ |  |ddƒd¡ |  |ddƒd¡ |  |ddƒd¡ |  |ddƒd¡ |  |ddƒd¡ |  |ddƒd	¡ |  |dd
ƒd	¡ |  |ddƒd¡ d}d}d}|| }|| }|  |||ƒ|¡ |  |||ƒ|¡ |  || |ƒ|¡ |  ||| ƒ|¡ |  ||| ƒ|¡ |  || |ƒ|¡ |  || | ƒ|¡ |  || | ƒ|¡ d}|| }|| }|  |||ƒ|¡ |  |||ƒ|¡ |  || |ƒ|¡ |  ||| ƒ|¡ |  ||| ƒ|¡ |  || |ƒ|¡ |  || | ƒ|¡ |  || | ƒ|¡ |  t|dd¡ |  t|dd¡ |  |tdƒtdƒƒd	¡ d S )Nr   r   rU   r«   iéÿÿÿé   éx   éT   é   iˆÿÿÿl    j9W    P)Ä}l    "oý  `T"-é    iõ	 l   ö8P9cC½/¬[N
Sâ9­b‘Xl	   9@{ÝwMñ2‘75Ök l   Zè¯'^%#—>¿;¹*Q!/61^g      ^@g      U@)r   ÚgcdrR   rV   rW   rC   )rE   r¾   Úcr   ÚyÚaÚbr   r   r   ÚtestGcd§  sP    
zMathTests.testGcdc             C   sÐ   |   ttj¡ |  dt dd¡d¡ |  dt dd¡d¡ |  t tt¡t¡ |  t tt¡t¡ |  t tt¡t¡ |  t tt¡t¡ |   t	tjt
t
¡ |  t t dt¡¡¡ |  t t td¡¡¡ d S )	Nz
hypot(0,0)r   z
hypot(3,4)rk   rf   r<   g      ð?g       À)rV   rW   r   ÚhypotrO   rR   r^   rZ   r[   r   Ú	FLOAT_MAXr]   r   )rE   r   r   r   Ú	testHypotÒ  s    zMathTests.testHypotc          	   C   s@  |   ttj¡ |  dt dd¡d¡ |  dt dd¡d¡ |  dt dd¡d¡ |  d	t dd¡d
¡ |   ttjdd¡ |   ttjdd¡ |  t dd¡d¡ |  t dd¡d¡ |  t td¡t¡ |  t td¡t¡ |  	t 
t td¡¡¡ xFddddd gD ]0}|  t t| ¡t¡ |  t t| ¡t¡ |  t d| ¡d¡ |  t d| ¡d¡ |  t d| ¡d¡ |  t d| ¡d¡ |  	t 
t t| ¡¡¡ |   ttjd|¡ |   ttjd|¡ |  t d|¡d¡ |  t d|¡d¡ |  t t|¡t¡ |  t t|¡t¡ |  	t 
t t|¡¡¡ qW d S )Nz
ldexp(0,1)r   r   z
ldexp(1,1)r9   zldexp(1,-1)rU   g      à?zldexp(-1,1)r‹   g      ð?i@B g      ð¿iÀ½ðÿg        g       €é   i+ÿÿÿi † l    d(	 l      Fµx:^V r…   é(   )rV   rW   r   r™   rO   r   rR   rZ   r[   r]   r   r^   )rE   r   r   r   r   Ú	testLdexpÞ  s6    zMathTests.testLdexpc             C   s  |   ttj¡ |  dt dtj ¡d¡ |  dt d¡d¡ |  dt tj¡d¡ |  dt dd	¡d
¡ |  dt dd d¡d¡ |  dt dd d¡d	¡ |  dt dd ¡d¡ |   ttjd¡ |   ttjdd  ¡ |   ttjt¡ |  t t	¡t	¡ |  
t t t¡¡¡ d S )Nzlog(1/e)r   rU   zlog(1)r   zlog(e)z	log(32,2)r½   r9   r<   zlog(10**40, 10)r…   rÈ   zlog(10**40, 10**20)l      Fµx:^V zlog(10**1000)iè  gO‘+ý¡@g      ø¿)rV   rW   r   ÚlogrO   rQ   rY   r[   rR   rZ   r]   r   r^   )rE   r   r   r   ÚtestLogþ  s    zMathTests.testLogc             C   sl   |   ttj¡ x6ddd dd gD ] }|  t |¡t t|ƒ¡¡ q"W |   ttjd¡ |  t t¡t¡ d S )Nr9   éZ   i,  rU   )	rV   rW   r   Úlog1pÚassertAlmostEqualr   rY   rR   rZ   )rE   r   r   r   r   Ú	testLog1p  s
     zMathTests.testLog1pc             C   sÀ   |   ttj¡ |  t d¡d¡ |  t d¡d¡ |  t d¡d¡ |  t dd ¡d¡ |  t dd	 ¡d
¡ |  t dd ¡d¡ |   ttjd¡ |   ttjt¡ |  t t t	¡¡¡ d S )Nr   g        r9   g      ð?rf   g       @iÿ  g     ø@i   g      @iÐ  g     @Ÿ@g      ø¿)
rV   rW   r   Úlog2rR   rY   r[   r]   r   r^   )rE   r   r   r   ÚtestLog2  s    zMathTests.testLog2r…   c             C   s8   dd„ t ddƒD ƒ}dd„ t ddƒD ƒ}|  ||¡ d S )Nc             S   s   g | ]}t  t  d |¡¡‘qS )g      ð?)r   rÐ   r™   )r¤   r   r   r   r   r¥   ,  s    z+MathTests.testLog2Exact.<locals>.<listcomp>iÎûÿÿi   c             S   s   g | ]}t |ƒ‘qS r   )r   )r¤   r   r   r   r   r¥   -  s    )r   rR   )rE   r´   r#   r   r   r   ÚtestLog2Exact'  s    zMathTests.testLog2Exactc             C   sÄ   |   ttj¡ |  dt d¡d¡ |  dt d¡d¡ |  dt d¡d¡ |  d	t dd
 ¡d¡ |   ttjd¡ |   ttjdd
  ¡ |   ttjt¡ |  t t	¡t	¡ |  
t t t¡¡¡ d S )Nz
log10(0.1)gš™™™™™¹?rU   zlog10(1)r   r   z	log10(10)r…   zlog10(10**1000)iè  g     @@g      ø¿)rV   rW   r   Úlog10rO   rY   r[   rR   rÊ   rZ   r]   r   r^   )rE   r   r   r   Ú	testLog100  s    zMathTests.testLog10c                s    ˆ   ttj¡ ‡ fdd„}|dt d¡dƒ |dt d¡dƒ ˆ  t t¡d	tf¡ ˆ  t t¡d
tf¡ t t¡}ˆ  t 	|d ¡¡ ˆ  t 	|d ¡¡ d S )Nc                sF   || \}}\}}t || ƒtks.t || ƒrBˆ  d| ||f ¡ d S )Nz%s returned %r, expected %r)r   r\   rM   )rN   r“   r#   Zv1Úv2Ze1Úe2)rE   r   r   Útestmodf?  s    z$MathTests.testModf.<locals>.testmodfz	modf(1.5)g      ø?)g      à?g      ð?z
modf(-1.5)g      ø¿)g      à¿g      ð¿g        g       €r   r   )
rV   rW   r   ÚmodfrR   rZ   r[   r^   r]   r   )rE   r×   Zmodf_nanr   )rE   r   ÚtestModf<  s    
zMathTests.testModfc             C   sî  |   ttj¡ |  dt dd¡d¡ |  dt dd¡d¡ |  dt dd¡d¡ |  dt dd¡d	¡ |  t td¡t¡ |  t td¡t¡ |  t dt¡d
¡ |  t dt¡d
¡ |  t 	t t
d¡¡¡ |  t 	t dt
¡¡¡ |  t 	t dt
¡¡¡ |  t dt
¡d¡ |  t dt¡d¡ |  t dd¡d¡ |  t dd¡d¡ |  t dd¡d¡ |  t dd¡d
¡ |  t dd¡d
¡ |   ttjdd¡ |   ttjdd¡ |   ttjdd¡ |   ttjdt¡ |  t 	t dt
¡¡¡ |  t tt¡t¡ |  t td¡t¡ |  t td¡t¡ |  t td¡t¡ |  t td¡d
¡ |  t td¡d
¡ |  t td¡d¡ |  t td¡d¡ |  t td¡d¡ |  t tt¡d¡ |  t 	t tt
¡¡¡ |  t dt¡d¡ |  t dd¡d¡ |  t dd¡d¡ |  t dd¡d¡ |  t dd¡d
¡ |  t dd¡d
¡ |   ttjdd¡ |   ttjdd¡ |   ttjdd¡ |   ttjdt¡ |  t 	t dt
¡¡¡ |  t tt¡t¡ |  t td¡t¡ |  t td¡t¡ |  t td¡t¡ |  t td¡d
¡ |  t td¡d
¡ |  t td¡d¡ |  t td¡d¡ |  t td¡d¡ |  t tt¡d¡ |  t 	t tt
¡¡¡ |  t dt¡d
¡ |  t dd¡d¡ |   ttjdd¡ |  t dd¡d
¡ |  t dd¡d
¡ |  t dd¡d
¡ |  t dd¡d
¡ |   ttjdd¡ |  t dd¡d¡ |  t dt¡d
¡ |  t 	t dt
¡¡¡ |  t d
t¡d
¡ |  t d
d¡d
¡ |  t d
d¡d
¡ |  t d
d¡d
¡ |  t d
d¡d
¡ |  t d
d¡d
¡ |  t d
d¡d
¡ |  t d
d¡d
¡ |  t d
d¡d
¡ |  t d
t¡d
¡ |  t d
t
¡d
¡ |  t dd¡d
¡ |  t dd¡d
¡ |  t t
d¡d
¡ |  t dd¡d
¡ |  t dd¡d
¡ |  t t
d¡d
¡ |   ttjdd¡ |   ttjdd¡ |  t dt¡d¡ |  t dt¡d¡ |  t dt¡t¡ |  t dt¡t¡ |  t dt¡t¡ |  t dt¡t¡ |  t dt¡d¡ |  t dt¡d¡ |  t dt¡t¡ |  t dt¡t¡ |  t dt¡d¡ |  t dt¡d¡ |  t dt¡d¡ |  t dt¡d¡ |  t dt¡t¡ |  t dt¡t¡ |  dt dd¡d¡ |  d t dd¡d!¡ |  d"t dd
¡d¡ |  d#t dd¡d
¡ |  d$t dd¡d
¡ |  d%t dd¡d&¡ |  d't dd¡d(¡ |  d)t dd¡d*¡ |   ttjdd&¡ |   ttjdd	¡ d S )+Nzpow(0,1)r   r   zpow(1,0)zpow(2,1)r9   z	pow(2,-1)rU   g      à?g      ð?g        g      @gffffff@g       @g       €g       ÀgffffffÀg      Àg      ð¿g      .ÀgÍÌÌÌÌÌÀgffffffþ?gš™™™™™ñ?gÍÌÌÌÌÌì?gš™™™™™¹?gš™™™™™¹¿gÍÌÌÌÌÌì¿gš™™™™™ñ¿gffffffþ¿z	(-2.)**3.g       Àz	(-2.)**2.g      @z	(-2.)**1.z	(-2.)**0.z
(-2.)**-0.z
(-2.)**-1.g      à¿z
(-2.)**-2.g      Ð?z
(-2.)**-3.g      À¿)rV   rW   r   ÚpowrO   rR   rZ   r[   r]   r   r^   rY   )rE   r   r   r   ÚtestPowO  sâ    zMathTests.testPowc             C   sr   |   ttj¡ |  dt d¡tj¡ |  dt d¡tjd ¡ |  dt d¡tj d ¡ |  d	t d
¡d
¡ d S )Nzradians(180)é´   zradians(90)rÌ   r9   zradians(-45)iÓÿÿÿrf   z
radians(0)r   )rV   rW   r   ÚradiansrO   rP   )rE   r   r   r   ÚtestRadiansä  s
    zMathTests.testRadiansc          0      s¤  ddl m‰  ‡ ‡fdd„}ddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4g0}x||D ]t}ˆj|d5^ | ¡ \}}}t |¡}t |¡}t |¡}	||||	ƒ t ||¡}
ˆ |
 	¡ |	 	¡ ¡ W d Q R X q„W t d6¡}xzt
d7d8ƒD ]l}|dkr$q|| }xNt
d9ƒD ]B}|| }t ||¡}
||||
ƒ t | |¡}
|| ||
ƒ q6W qW x@td:d;d<d=ttgD ]*}ˆ t t|¡¡ ˆ t |t¡¡ q–W x6d>D ].}ˆ t |t¡|¡ ˆ t |t¡|¡ qÊW x¢td=d;d:d?tgD ]Ž}ˆ t¡ t t|¡ W d Q R X ˆ t¡ t t|¡ W d Q R X ˆ t¡ t |d:¡ W d Q R X ˆ t¡ t |d;¡ W d Q R X qW d S )@Nr   )ÚFractionc                s€   ˆ | ƒˆ |ƒˆ |ƒ  }}}ˆ  t|ƒt|d ƒ¡ || | }ˆ |t|ƒ¡ t|ƒt|d ƒkr|ˆ |d t|d ƒ¡ dS )z¨
            Check that r matches remainder(x, y) according to the IEEE 754
            specification. Assumes that x, y and r are finite and y is nonzero.
            r9   N)ÚassertLessEqualr   rR   r?   )r   rÀ   ÚrZfxZfyÚfrr   )rß   rE   r   r   Úvalidate_specï  s    z.MathTests.testRemainder.<locals>.validate_specz-4.0 1 -0.0z-3.8 1  0.8z-3.0 1 -0.0z-2.8 1 -0.8z-2.0 1 -0.0z-1.8 1  0.8z-1.0 1 -0.0z-0.8 1 -0.8z-0.0 1 -0.0z 0.0 1  0.0z 0.8 1  0.8z 1.0 1  0.0z 1.8 1 -0.8z 2.0 1  0.0z 2.8 1  0.8z 3.0 1  0.0z 3.8 1 -0.8z 4.0 1  0.0z&0x0.0p+0 0x1.921fb54442d18p+2 0x0.0p+0z?0x1.921fb54442d18p+0 0x1.921fb54442d18p+2  0x1.921fb54442d18p+0z?0x1.921fb54442d17p+1 0x1.921fb54442d18p+2  0x1.921fb54442d17p+1z?0x1.921fb54442d18p+1 0x1.921fb54442d18p+2  0x1.921fb54442d18p+1z?0x1.921fb54442d19p+1 0x1.921fb54442d18p+2 -0x1.921fb54442d17p+1z?0x1.921fb54442d17p+2 0x1.921fb54442d18p+2 -0x0.0000000000001p+2z00x1.921fb54442d18p+2 0x1.921fb54442d18p+2  0x0p0z?0x1.921fb54442d19p+2 0x1.921fb54442d18p+2  0x0.0000000000001p+2z?0x1.2d97c7f3321d1p+3 0x1.921fb54442d18p+2  0x1.921fb54442d14p+1z?0x1.2d97c7f3321d2p+3 0x1.921fb54442d18p+2 -0x1.921fb54442d18p+1z?0x1.2d97c7f3321d3p+3 0x1.921fb54442d18p+2 -0x1.921fb54442d14p+1z?0x1.921fb54442d17p+3 0x1.921fb54442d18p+2 -0x0.0000000000001p+3z00x1.921fb54442d18p+3 0x1.921fb54442d18p+2  0x0p0z?0x1.921fb54442d19p+3 0x1.921fb54442d18p+2  0x0.0000000000001p+3z?0x1.f6a7a2955385dp+3 0x1.921fb54442d18p+2  0x1.921fb54442d14p+1z?0x1.f6a7a2955385ep+3 0x1.921fb54442d18p+2  0x1.921fb54442d18p+1z?0x1.f6a7a2955385fp+3 0x1.921fb54442d18p+2 -0x1.921fb54442d14p+1z?0x1.1475cc9eedf00p+5 0x1.921fb54442d18p+2  0x1.921fb54442d10p+1z?0x1.1475cc9eedf01p+5 0x1.921fb54442d18p+2 -0x1.921fb54442d10p+1z 1  0.c  0.4z-1  0.c -0.4z 1 -0.c  0.4z-1 -0.c -0.4z 1.4  0.c -0.4z-1.4  0.c  0.4z 1.4 -0.c -0.4z-1.4 -0.c  0.4z$0x1.dp+1023 0x1.4p+1023  0x0.9p+1023z$0x1.ep+1023 0x1.4p+1023 -0x0.ap+1023z$0x1.fp+1023 0x1.4p+1023 -0x0.9p+1023)Úcasez1p-1074içÿÿÿé   r†   g        g       €g       @gffffffÀ)gffffffÀg       €g        gffffff@gffffff@)Ú	fractionsrß   ÚsubTestr,   r   r¯   r   Ú	remainderrR   Úhexr   r^   r[   rZ   ÚassertIsNaNrV   rY   )rE   rã   Z	testcasesrä   Zx_hexZy_hexZexpected_hexr   rÀ   r#   r´   Ztinyr   ÚmrD   r   )rß   rE   r   ÚtestRemainderë  sª    



"


zMathTests.testRemainderc             C   sØ   |   ttj¡ |  dt d¡d¡ |  dt tjd ¡d¡ |  dt tj d ¡d¡ y0|  t t t¡¡¡ |  t t t	¡¡¡ W n4 t
k
r¼   |   t
tjt¡ |   t
tjt	¡ Y nX |  t t t¡¡¡ d S )Nzsin(0)r   z	sin(pi/2)r9   r   z
sin(-pi/2)rU   )rV   rW   r   ÚsinrO   rP   r]   r   rZ   r[   rY   r^   )rE   r   r   r   ÚtestSinl  s    zMathTests.testSinc             C   s¤   |   ttj¡ |  dt d¡d¡ |  dt d¡d t d¡d  d¡ |  dt d¡t d¡ d¡ |  t t¡t¡ |  t t¡t¡ |  	t 
t t¡¡¡ d S )Nzsinh(0)r   zsinh(1)**2-cosh(1)**2r   r9   rU   zsinh(1)+sinh(-1))rV   rW   r   ÚsinhrO   r}   rR   rZ   r[   r]   r   r^   )rE   r   r   r   ÚtestSinhy  s    &zMathTests.testSinhc             C   s–   |   ttj¡ |  dt d¡d¡ |  dt d¡d¡ |  dt d¡d¡ |  t t¡t¡ |   ttjd¡ |   ttjt¡ |  	t 
t t¡¡¡ d S )	Nzsqrt(0)r   zsqrt(1)r   zsqrt(4)rf   r9   rU   )rV   rW   r   ÚsqrtrO   rR   rZ   rY   r[   r]   r   r^   )rE   r   r   r   ÚtestSqrt‚  s    zMathTests.testSqrtc             C   sÐ   |   ttj¡ |  dt d¡d¡ |  dt tjd ¡d¡ |  dt tj d ¡d¡ y0|  t t t¡¡¡ |  t t t	¡¡¡ W n,   |   t
tjt¡ |   t
tjt	¡ Y nX |  t t t¡¡¡ d S )Nztan(0)r   z	tan(pi/4)rf   r   z
tan(-pi/4)rU   )rV   rW   r   ÚtanrO   rP   r]   r   rZ   r[   rY   r^   )rE   r   r   r   ÚtestTanŒ  s    zMathTests.testTanc             C   sŠ   |   ttj¡ |  dt d¡d¡ | jdt d¡t d¡ dtdƒd |  dt t¡d¡ |  dt t¡d¡ |  t 	t t
¡¡¡ d S )	Nztanh(0)r   ztanh(1)+tanh(-1)r   rU   )r&   z	tanh(inf)z
tanh(-inf))rV   rW   r   ÚtanhrO   r   rZ   r[   r]   r   r^   )rE   r   r   r   ÚtestTanh™  s    zMathTests.testTanhÚTANH_PRESERVES_ZERO_SIGNr   z,system tanh() function doesn't copy the signc             C   s8   |   t d¡d¡ |   t dt d¡¡t dd¡¡ d S )Ng       €g      ð?)rR   r   rõ   ry   )rE   r   r   r   ÚtestTanhSign¢  s    zMathTests.testTanhSignc             C   s&  |   t d¡d¡ |   t d¡d¡ |   tt d¡ƒt¡ |   tt d¡ƒt¡ |   t d¡d¡ |   t d¡d¡ |   t d¡d¡ |   t d¡d¡ |   t d¡d¡ |   t d	¡d
¡ G dd„ dtƒ}G dd„ dtƒ}|   t |ƒ ¡d¡ |  ttj¡ |  ttjdd¡ |  ttj|ƒ ¡ d S )Nr   rU   g      ø?g      ø¿gõ…óþÿÿ?gõ…óþÿÿ¿gé!çýÿï¿r   g-²ï?YÀiœÿÿÿc               @   s   e Zd Zdd„ ZdS )z'MathTests.test_trunc.<locals>.TestTruncc             S   s   dS )Né   r   )rE   r   r   r   Ú	__trunc__¸  s    z1MathTests.test_trunc.<locals>.TestTrunc.__trunc__N)rH   rI   rJ   rú   r   r   r   r   Ú	TestTrunc·  s   rû   c               @   s   e Zd ZdS )z)MathTests.test_trunc.<locals>.TestNoTruncN)rH   rI   rJ   r   r   r   r   ÚTestNoTrunc»  s   rü   rù   r9   )rR   r   Útruncrv   r?   ÚobjectrV   rW   )rE   rû   rü   r   r   r   Ú
test_trunc«  s     zMathTests.test_truncc             C   s€   |   t d¡¡ |   t d¡¡ |   t d¡¡ |   t d¡¡ |  t tdƒ¡¡ |  t tdƒ¡¡ |  t tdƒ¡¡ d S )Ng        g       €g      ð?g      ð¿r   r   z-inf)r]   r   ÚisfiniteÚassertFalser   )rE   r   r   r   ÚtestIsfiniteÄ  s    zMathTests.testIsfinitec             C   sx   |   t tdƒ¡¡ |   t tdƒ¡¡ |   t tdƒd ¡¡ |  t tdƒ¡¡ |  t d¡¡ |  t d¡¡ d S )Nr   z-nanr   g        g      ð?)r]   r   r   r   r  )rE   r   r   r   Ú	testIsnanÍ  s    zMathTests.testIsnanc             C   s€   |   t tdƒ¡¡ |   t tdƒ¡¡ |   t d¡¡ |   t d¡¡ |  t tdƒ¡¡ |  t d¡¡ |  t d¡¡ d S )Nr   z-infg      ðg      ðÿr   g        g      ð?)r]   r   r   r   r  )rE   r   r   r   Ú	testIsinfÕ  s    zMathTests.testIsinfc             C   s   |   t tj¡¡ d S )N)r]   r   r   r   )rE   r   r   r   Útest_nan_constantÞ  s    zMathTests.test_nan_constantc             C   sJ   |   t tj¡¡ |  tjd¡ |  tjtdƒ¡ |  tj tdƒ¡ d S )Ng        r   z-inf)r]   r   r   r   ÚassertGreaterrR   r   )rE   r   r   r   Útest_inf_constantâ  s    zMathTests.test_inf_constantzrequires verbose modec             C   s˜   yt  d¡}W n   |  d¡ Y nX |dkr8|  d¡ yt  d¡}W n tk
rZ   Y nX |  d¡ yt  d¡}W n tk
rˆ   Y nX |  d¡ d S )	Ni 6eÄz6underflowing exp() should not have raised an exceptionr   z)underflowing exp() should have returned 0i Êš;z.overflowing exp() didn't trigger OverflowErrorg      ð¿z sqrt(-1) didn't raise ValueError)r   r6   rM   r   rñ   rY   )rE   r   r   r   r   Útest_exceptionsî  s     

zMathTests.test_exceptionsc          	   C   sp  dh}d }t jdkrNt ¡ d }yttt| d¡ƒƒ}W n tk
rL   Y nX d}g }xútt	ƒD ]î\}}}}	}
}}|	dks`|dkr„q`|dkrŽq`|d k	r¨|dk r¨||kr¨q`t
t|ƒ}d	|ksÂd
|krÈd}
nd|krÔd}
y||ƒ}W n0 tk
rø   d}Y n tk
r   d}Y nX d\}}t|
|||ƒ}|d kr4q`| ||||¡}| |¡ q`W |rl|  dd |¡ ¡ d S )NZtan0064Údarwinr   Ú.z{}: {}({!r}): {}g        )ZrectZpolar)r…   r<   Úinvalidzdivide-by-zerorY   Úoverflowr   )r<   g        zFailures in test_testfile:
  z
  )r­   ÚplatformÚmac_verÚtupleÚmapr?   r,   rY   r;   Ú	test_fileÚgetattrr   r   rB   r"   r²   rM   Újoin)rE   ZSKIP_ON_TIGERZosx_versionÚversion_txtrA   Úfailuresr2   r3   ÚarÚaiZerÚeir7   Úfuncr“   r%   r&   r@   Úmsgr   r   r   Útest_testfile  sL    



zMathTests.test_testfilec          	   C   s2  d}g }xt tƒD ]ü\}}}}}tt|ƒ}d|ks<d|krBd}nd|krNd}y||ƒ}	W n. tk
rr   d}	Y n tk
rˆ   d}	Y nX d\}
}|dkr d	}
n>|d
kr®d}n0|dkrÞ|dkrÞ|dk rÌd}
n|dk rÚd}
nd}
t||	|
|ƒ}|d kröq| ||||¡}| |¡ qW |r.|  	dd 
|¡ ¡ d S )Nz{}: {}({!r}): {}r  zdivide-by-zerorY   r  r   )r<   g        Úgammaé   ÚlgammagVçž¯Ò<Úerfcg        g      ð?r…   g      $@r†   iè  zFailures in test_mtestfile:
  z
  )r8   Úmath_testcasesr  r   rY   r   rB   r"   r²   rM   r  )rE   rA   r  r2   r3   r4   r#   r7   r  r$   r%   r&   r@   r  r   r   r   Útest_mtestfileG  sB    

zMathTests.test_mtestfilec             C   s   t  |¡s|  d |¡¡ d S )NzExpected a NaN, got {!r}.)r   r   rM   r"   )rE   rD   r   r   r   rê   Œ  s    
zMathTests.assertIsNaNN)r<   rL   )@rH   rI   rJ   rO   rT   r_   ra   rc   re   rh   rj   rm   rx   r   rz   r|   r~   r€   r‚   r„   r‰   r   Úcpython_onlyrŠ   r   r’   r—   ÚunittestÚskipIfÚHAVE_DOUBLE_ROUNDINGr¸   rÃ   rÆ   rÉ   rË   rÏ   rÑ   Úrequires_mac_verrÒ   rÔ   rÙ   rÛ   rÞ   rì   rî   rð   rò   rô   rö   Ú	sysconfigÚget_config_varrø   rÿ   r  r  r  r  r  Ú
skipUnlessr   r  r  r!  rê   r   r   r   r   rK   ÷   sr   

		="
Y+   	
			 9ErK   c               @   sŠ   e Zd ZejZdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS ) ÚIsCloseTestsc             O   s*   | j | j||f|ž|Žd||f d d S )Nz%s and %s should be close!)r  )r]   Úisclose)rE   rÁ   rÂ   rr   Úkwargsr   r   r   ÚassertIsClose”  s    zIsCloseTests.assertIsClosec             O   s*   | j | j||f|ž|Žd||f d d S )Nz%s and %s should not be close!)r  )r  r+  )rE   rÁ   rÂ   rr   r,  r   r   r   ÚassertIsNotClose˜  s    zIsCloseTests.assertIsNotClosec             O   s*   x$|D ]\}}| j ||f|ž|Ž qW d S )N)r-  )rE   Úexamplesrr   r,  rÁ   rÂ   r   r   r   ÚassertAllCloseœ  s    zIsCloseTests.assertAllClosec             O   s*   x$|D ]\}}| j ||f|ž|Ž qW d S )N)r.  )rE   r/  rr   r,  rÁ   rÂ   r   r   r   ÚassertAllNotClose   s    zIsCloseTests.assertAllNotClosec          	   C   sR   |   t¡ | jdddd W d Q R X |   t¡ | jddddd W d Q R X d S )Nr   g0Žä.ÿ+«)Úrel_tolg0Žä.ÿ++g    _ Â)r2  r&   )rV   rY   r-  )rE   r   r   r   Útest_negative_tolerances¤  s    z%IsCloseTests.test_negative_tolerancesc             C   s$   ddddddg}| j |ddd d S )	N)g       @g       @)g¯N¬¬à¸@ig¯N¬¬à¸@i)g;Öê¨g;Öê¨)i90  g    €È@)g        g       €)iNF iNF g        )r2  r&   )r0  )rE   Zidentical_examplesr   r   r   Útest_identical«  s    zIsCloseTests.test_identicalc             C   s*   dddg}| j |dd | j|dd d S )N)g    „×—Ag   „×—A)g:Œ0âŽyE¾g¸¦nåŽyE¾)g‰	Ñ­ùñ?gfN¸Ó­ùñ?g:Œ0âŽyE>)r2  g•Ö&è.>)r0  r1  )rE   Zeight_decimal_places_examplesr   r   r   Útest_eight_decimal_placesµ  s
    z&IsCloseTests.test_eight_decimal_placesc             C   s*   dddg}| j |dd | j|dd d S )N)g•Ö&è.>g        )g•Ö&è.¾g        )gu”?jç/Ê g        gÍÌÌÌÌÌì?)r2  g:Œ0âŽyE>)r&   )r1  r0  )rE   Znear_zero_examplesr   r   r   Útest_near_zero½  s
    zIsCloseTests.test_near_zeroc             C   s<   |   tt¡ | j ttdd |   tt¡ | j ttdd d S )Ng        )r&   )r-  rZ   r[   )rE   r   r   r   Útest_identical_infiniteÇ  s    z$IsCloseTests.test_identical_infinitec             C   sR   t t ft dfdt ftt ft tfttftdfdtftdfdtfg
}| j|dd d S )Ng0Žä.ÿ++g      ð?g Èë…óÌág÷ÿÿÿÿÿï?)r&   )r^   rZ   r[   r1  )rE   Znot_close_examplesr   r   r   Útest_inf_ninf_nanÎ  s    
zIsCloseTests.test_inf_ninf_nanc             C   s4   dddg}| j |dd dddg}| j|dd d S )	N)g      ð?g      ð?)g333333Àg333333À)gYóøÂn¥gYóøÂn¥g        )r2  )g      ð?g     ð?)g¦ÿÿÿÿÿï?g      ð?)gZb××çtigTb××çti)r0  r1  )rE   Zzero_tolerance_close_examplesZ!zero_tolerance_not_close_examplesr   r   r   Útest_zero_toleranceÝ  s    z IsCloseTests.test_zero_tolerancec             C   s   | j ddgdd d S )N)é	   r…   )r…   r:  gš™™™™™¹?)r2  )r0  )rE   r   r   r   Útest_asymmetryé  s    zIsCloseTests.test_asymmetryc             C   s(   ddg}| j |dd | j|dd d S )N)iáõi áõ)iÍ[iÍ[g:Œ0âŽyE>)r2  g•Ö&è.>)r0  r1  )rE   Zinteger_examplesr   r   r   Útest_integersí  s    zIsCloseTests.test_integersc             C   sh   ddl m} |dƒ|dƒf|dƒ|dƒf|dƒ|dƒf|d	ƒ|d
ƒfg}| j|dd | j|dd d S )Nr   )ÚDecimalz
1.00000001z1.0z1.00000001e-20z1.0e-20z1.00000001e-100z1.0e-100z1.00000001e20z1.0e20g:Œ0âŽyE>)r2  g•Ö&è.>)Údecimalr=  r0  r1  )rE   r=  Zdecimal_examplesr   r   r   Útest_decimalsõ  s    zIsCloseTests.test_decimalsc             C   sd   ddl m} |ddƒd |dƒf|dƒ|dƒf|ddƒ|ddƒfg}| j|dd	 | j|d
d	 d S )Nr   )rß   r   i áõiáõl       „	(qãeù	 l      Fµx:^V g:Œ0âŽyE>)r2  g•Ö&è.>)ræ   rß   r0  r1  )rE   rß   Zfraction_examplesr   r   r   Útest_fractions   s    zIsCloseTests.test_fractionsN)rH   rI   rJ   r   r+  r-  r.  r0  r1  r3  r4  r5  r6  r7  r8  r9  r;  r<  r?  r@  r   r   r   r   r*  ‘  s    

r*  c              C   sN   ddl m}  t ¡ }| t t¡¡ | t t¡¡ | | dƒ¡ t|ƒ d S )Nr   )ÚDocFileSuitezieee754.txt)	ÚdoctestrA  r#  Ú	TestSuiteÚaddTestÚ	makeSuiterK   r*  r   )rA  Úsuiter   r   r   Ú	test_main  s    rG  )r<   r=   )2Ztest.supportr   r   r   Útestr   r#  r   Úosr  r	   r­   r'  r\   r   r^   rZ   r[   r˜   rš   rÅ   r   rÀ   r%  rH   ÚargvÚfileÚ__file__ÚpathÚdirnameÚcurdirZtest_dirr  r   r  r   r   r   r   r!   r(   r8   r;   rB   rþ   rC   ÚTestCaserK   r*  rG  r   r   r   r   Ú<module>   sZ   -
.         #{
