U
    hâËdÇD  ã                   @   s„  d Z ddlZddlZddlmZmZ ddlmZmZ ddl	m
Z
 ddlmZmZ ddlmZ edƒZejZd	d
„ Zdd„ Zdd„ Zeejejƒdd„ ƒZeejejƒdd„ ƒZeejejƒdd„ ƒZeejƒdd„ ƒZdd„ ZedƒZ edƒZ!eej"ejƒedd„ ƒƒZ#eej$ejƒedd„ ƒƒZ%eej$ejejƒdd „ ƒZ&eej'ƒd!d"„ ƒZ(eej)ƒd#d$„ ƒZ*eej+ƒd%d&„ ƒZ,eej-ejƒd'd(„ ƒZ.eej/ejƒd)d*„ ƒZ0eej1ƒd+d,„ ƒZ2eej3ejƒd-d.„ ƒZ4eej5ƒd/d0„ ƒZ6eej7ejƒd1d2„ ƒZ8eej9ƒd3d4„ ƒZ:eej;ejƒd5d6„ ƒZ<eej=ƒd7d8„ ƒZ>eej?ejƒd9d:„ ƒZ@eejAejƒd;d<„ ƒZBeejCejƒd=d>„ ƒZDeejEejƒd?d@„ ƒZFdS )Az'
Implement the cmath module functions.
é    N)ÚRegistryÚimpl_ret_untracked)ÚtypesÚcgutils)Ú	signature)ÚbuiltinsÚmathimpl)ÚoverloadZ	cmathimplc                 C   s   |   d|j|j¡S )NZuno)Zfcmp_unorderedÚrealÚimag©ÚbuilderÚz© r   úP/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/numba/cpython/cmathimpl.pyÚis_nan   s    r   c                 C   s    |   t | |j¡t | |j¡¡S ©N)Úor_r   Úis_infr
   r   r   r   r   r   r      s    ÿr   c                 C   s    |   t | |j¡t | |j¡¡S r   )Úand_r   Ú	is_finiter
   r   r   r   r   r   r      s    ÿr   c                 C   s8   |j \}|\}| j|||d�}t||ƒ}t| ||j|ƒS ©N©Úvalue)ÚargsÚmake_complexr   r   Úreturn_type©Úcontextr   Úsigr   Útypr   r   Úresr   r   r   Úisnan_float_impl   s
    
r"   c                 C   s8   |j \}|\}| j|||d�}t||ƒ}t| ||j|ƒS r   )r   r   r   r   r   r   r   r   r   Úisinf_float_impl'   s
    
r#   c                 C   s8   |j \}|\}| j|||d�}t||ƒ}t| ||j|ƒS r   )r   r   r   r   r   r   r   r   r   Úisfinite_float_impl0   s
    
r$   c                 C   s&   t dd„ | |fD ƒƒr"dd„ }|S d S )Nc                 S   s   g | ]}t |tjƒ‘qS r   )Ú
isinstancer   ÚFloat)Ú.0r    r   r   r   Ú
<listcomp>;   s     z#impl_cmath_rect.<locals>.<listcomp>c                 S   s�   t  |¡s*| st| ƒS t  | ¡r*t| |ƒS t  |¡}t  |¡}|dkrZt  | ¡rZ||  }n|| 9 }|dkr~t  | ¡r~||  }n|| 9 }t||ƒS )Nç        )ÚmathÚisfiniteÚabsÚisinfÚcomplexÚcosÚsin)ÚrÚphir
   r   r   r   r   Úimpl<   s    






zimpl_cmath_rect.<locals>.impl)Úall)r1   r2   r3   r   r   r   Úimpl_cmath_rect9   s    r5   c                    s   ‡ fdd„}|S )Nc              	      sŒ   |j \}|\}| j|||d�}|j}|j}t ||¡}	t ||¡}
t|jf|jfd t	j
fd  žŽ }|  |ˆ ||||	|
f¡}t| |||ƒS )Nr   é   )r   r   r
   r   r   r   r   r   Úunderlying_floatr   ÚbooleanÚcompile_internalr   )r   r   r   r   r    r   r   ÚxÚyÚx_is_finiteÚy_is_finiteZ	inner_sigr!   ©Ú
inner_funcr   r   ÚwrapperU   s    ÿ

ÿz(intrinsic_complex_unary.<locals>.wrapperr   )r?   r@   r   r>   r   Úintrinsic_complex_unaryT   s    rA   ÚnanÚinfc           	      C   s  |rD|r8t  |¡}t  |¡}t  | ¡}t|| || ƒS tttƒS n¼t  | ¡rh|r\t| | ƒS t| |ƒS n˜| dkr¾|r²t  |¡}t  |¡}|dkr˜|| 9 }|dkr¨|| 9 }t||ƒS t| tƒS nB|ròt  | ¡}t  |¡}t  |¡}t|| || ƒS d}t||ƒS dS )zcmath.exp(x + y j)r)   r   N)r*   r/   r0   Úexpr.   ÚNANÚisnan)	r:   r;   r<   r=   ÚcÚsr1   r
   r   r   r   r   Úexp_implj   s8    










rI   c                 C   s(   t  t  | |¡¡}t  || ¡}t||ƒS )zcmath.log(x + y j))r*   ÚlogÚhypotÚatan2r.   )r:   r;   r<   r=   ÚaÚbr   r   r   Úlog_impl”   s    rO   c                 C   s.   |\}}dd„ }|   ||||¡}t| |||ƒS )zcmath.log(z, base)c                 S   s   t  | ¡t  |¡ S r   )ÚcmathrJ   )r   Úbaser   r   r   Úlog_base¢   s    zlog_base_impl.<locals>.log_base©r9   r   )r   r   r   r   r   rQ   rR   r!   r   r   r   Úlog_base_impl�   s    rT   c                    s$   t | tjƒsd S d‰ ‡ fdd„}|S )NgUµ»±k@c                    s    t  | ¡} t| jˆ  | jˆ  ƒS )zcmath.log10(z))rP   rJ   r.   r
   r   ©r   ©ZLN_10r   r   Ú
log10_impl°   s    
z$impl_cmath_log10.<locals>.log10_impl©r%   r   ÚComplex)r   rW   r   rV   r   Úimpl_cmath_log10©   s
    rZ   c                 C   s   t | tjƒsdS dd„ }|S )zcmath.phase(x + y j)Nc                 S   s   t  | j| j¡S r   )r*   rL   r   r
   )r:   r   r   r   r3   Á   s    zphase_impl.<locals>.implrX   ©r:   r3   r   r   r   Ú
phase_implº   s    r\   c                 C   s   t | tjƒsd S dd„ }|S )Nc                 S   s&   | j | j }}t ||¡t ||¡fS r   )r
   r   r*   rK   rL   )r:   r1   Úir   r   r   r3   Ë   s    zpolar_impl.<locals>.implrX   r[   r   r   r   Ú
polar_implÆ   s    r^   c           
         s`   d}d| }|j d j}|jdkr(tjntj}|| ‰ ‡ fdd„}|  ||||¡}	t| |||	ƒS )NgÍ;fž ö?ç      ð?r   é@   c                    sZ  | j }| j}|dkr*|dkr*tt|ƒ|ƒS t |¡rBtt|ƒ|ƒS t |¡rVt||ƒS t |¡r˜|dk r‚tt|| ƒt ||¡ƒS t|t || |¡ƒS t|ƒˆ ks°t|ƒˆ krÆ|d9 }|d9 }d}nd}|dk�r t |t 	||¡ d ¡}|}|d|  }n8t | t 	||¡ d ¡}t|ƒd|  }t ||¡}|�rLt|d |ƒS t||ƒS dS )	zcmath.sqrt(z)r)   ç      Ð?TFr   ç      à?r6   N)
r
   r   r.   r,   r*   r-   rF   ÚcopysignÚsqrtrK   )r   rM   rN   ÚscaleÚtr
   r   ©ÚTHRESr   r   Ú	sqrt_implà   s6    




zsqrt_impl.<locals>.sqrt_impl)r   r7   Zbitwidthr   ZDBL_MAXÚFLT_MAXr9   r   )
r   r   r   r   ZSQRT2ZONE_PLUS_SQRT2Z	theargfltÚMAXri   r!   r   rg   r   ri   Ñ   s    *ri   c                 C   s&   dd„ }|   ||||¡}t| |||ƒS )Nc                 S   s   t  t| j | jƒ¡S )zcmath.cos(z) = cmath.cosh(z j))rP   Úcoshr.   r   r
   rU   r   r   r   Úcos_impl  s    zcos_impl.<locals>.cos_implrS   )r   r   r   r   rm   r!   r   r   r   rm     s    rm   c                 C   s   t | tjƒsd S dd„ }|S )Nc                 S   sª   | j }| j}t |¡r€t |¡r.t|ƒ}|}n:|dkrDt|ƒ}|}n$t |t |¡¡}t |t |¡¡}|dk rv| }t	||ƒS t	t |¡t 
|¡ t |¡t |¡ ƒS )zcmath.cosh(z)r)   )r
   r   r*   r-   rF   r,   rc   r/   r0   r.   rl   Úsinh©r   r:   r;   r
   r   r   r   r   Ú	cosh_impl  s"    


ÿz"impl_cmath_cosh.<locals>.cosh_implrX   )r   rp   r   r   r   Úimpl_cmath_cosh  s    rq   c                 C   s&   dd„ }|   ||||¡}t| |||ƒS )Nc                 S   s&   t  t| j | jƒ¡}t|j|j ƒS )z#cmath.sin(z) = -j * cmath.sinh(z j))rP   rn   r.   r   r
   ©r   r1   r   r   r   Úsin_impl7  s    zsin_impl.<locals>.sin_implrS   )r   r   r   r   rs   r!   r   r   r   rs   5  s    rs   c                 C   s   t | tjƒsd S dd„ }|S )Nc                 S   s–   | j }| j}t |¡rlt |¡r*|}|}n8t |¡}t |¡}|dkrN||9 }|dkrb|t|ƒ9 }t||ƒS tt |¡t 	|¡ t |¡t 
|¡ ƒS )zcmath.sinh(z)r)   )r
   r   r*   r-   rF   r/   r0   r,   r.   rn   rl   ro   r   r   r   Ú	sinh_implD  s     




ÿz"impl_cmath_sinh.<locals>.sinh_implrX   )r   rt   r   r   r   Úimpl_cmath_sinh?  s    ru   c                 C   s&   dd„ }|   ||||¡}t| |||ƒS )Nc                 S   s&   t  t| j | jƒ¡}t|j|j ƒS )z#cmath.tan(z) = -j * cmath.tanh(z j))rP   Útanhr.   r   r
   rr   r   r   r   Útan_impl\  s    ztan_impl.<locals>.tan_implrS   )r   r   r   r   rw   r!   r   r   r   rw   Z  s    rw   c                 C   s   t | tjƒsd S dd„ }|S )Nc           
      S   s®   | j }| j}t |¡rRt d|¡}t |¡r2d}nt dt d| ¡¡}t||ƒS t |¡}t |¡}dt 	|¡ }|| }d||  }	t|d||   |	 ||	 | | ƒS )zcmath.tanh(z)r_   r)   ç       @)
r
   r   r*   r-   rc   r0   r.   rv   Útanrl   )
r   r:   r;   r
   r   ZtxÚtyZcxZtxtyÚdenomr   r   r   Ú	tanh_implj  s"    




þz"impl_cmath_tanh.<locals>.tanh_implrX   )r   r|   r   r   r   Úimpl_cmath_tanhe  s    r}   c                    s@   t  d¡‰ tjd ‰‡ ‡fdd„}|  ||||¡}t| |||ƒS )Né   c              	      sÚ   t | jƒˆkst | jƒˆkrht t | jƒ| j¡}t t t | jd | jd ¡¡ˆ  | j ¡}t||ƒS t	 
td| j | j ƒ¡}t	 
td| j | jƒ¡}dt |j|j¡ }t |j|j |j|j  ¡}t||ƒS dS )zcmath.acos(z)rb   r_   rx   N)r,   r
   r   r*   rL   rc   rJ   rK   r.   rP   rd   Úasinh©r   r
   r   Ús1Ús2©ÚLN_4rh   r   r   Ú	acos_implˆ  s     þ
zacos_impl.<locals>.acos_impl©r*   rJ   r   rj   r9   r   )r   r   r   r   r…   r!   r   rƒ   r   r…   ƒ  s
    

r…   c                    s6   t | tjƒsd S t d¡‰ tjd ‰‡ ‡fdd„}|S )Nr~   c                    sÈ   t | jƒˆkst | jƒˆkrXt t | jd | jd ¡¡ˆ  }t | j| j¡}t||ƒS t 	t| jd | jƒ¡}t 	t| jd | jƒ¡}t 
|j|j |j|j  ¡}dt |j|j¡ }t||ƒS dS )zcmath.acosh(z)rb   r_   rx   N)r,   r
   r   r*   rJ   rK   rL   r.   rP   rd   r   r€   rƒ   r   r   Ú
acosh_impl¥  s    "
z$impl_cmath_acosh.<locals>.acosh_impl)r%   r   rY   r*   rJ   r   rj   )r   r‡   r   rƒ   r   Úimpl_cmath_acosh�  s    

rˆ   c                    s@   t  d¡‰ tjd ‰‡ ‡fdd„}|  ||||¡}t| |||ƒS )Nr~   c              	      sæ   t | jƒˆkst | jƒˆkrft t t | jd | jd ¡¡ˆ  | j¡}t | jt | jƒ¡}t||ƒS t	 
td| j | j ƒ¡}t	 
td| j | jƒ¡}t |j|j |j|j  ¡}t | j|j|j |j|j  ¡}t||ƒS dS )zcmath.asinh(z)rb   r_   N)r,   r
   r   r*   rc   rJ   rK   rL   r.   rP   rd   r   r€   rƒ   r   r   Ú
asinh_impl¿  s     þ
"zasinh_impl.<locals>.asinh_implr†   )r   r   r   r   r‰   r!   r   rƒ   r   r‰   º  s
    

r‰   c                 C   s&   dd„ }|   ||||¡}t| |||ƒS )Nc                 S   s&   t  t| j | jƒ¡}t|j|j ƒS )z%cmath.asin(z) = -j * cmath.asinh(z j))rP   r   r.   r   r
   rr   r   r   r   Ú	asin_implÔ  s    zasin_impl.<locals>.asin_implrS   )r   r   r   r   rŠ   r!   r   r   r   rŠ   Ò  s    rŠ   c                 C   s&   dd„ }|   ||||¡}t| |||ƒS )Nc                 S   sP   t  t| j | jƒ¡}t | j¡r<t | j¡r<t|j|jƒS t|j|j ƒS dS )z%cmath.atan(z) = -j * cmath.atanh(z j)N)rP   Úatanhr.   r   r
   r*   r-   rF   rr   r   r   r   Ú	atan_implÞ  s    zatan_impl.<locals>.atan_implrS   )r   r   r   r   rŒ   r!   r   r   r   rŒ   Ü  s    	rŒ   c                    s^   t  d¡}t  tjd ¡‰t  tj¡‰t jd ‰ ‡ ‡‡fdd„}|  ||||¡}t| |||ƒS )Nr~   r6   c              	      s¦  | j dk rd}|  } nd}t| jƒ}t | j ¡sB| j ˆksB|ˆkr®t | j¡r^t d| j ¡}n<t | j ¡rpd}n*t | j d | jd ¡}| j d | | }t ˆ | j ¡ }nÄ| j dk�r|ˆk �r|dkrØt}| j}n@t 	t 
|¡t 
t |d¡¡ ¡ }t t d| ¡d | j¡}nX|| }d	| j  }t d| j  || |  ¡d
 }t d| j |d	| j   | ¡ d }t | j¡�r„t}|�r˜t| | ƒS t||ƒS dS )zcmath.atanh(z)r)   TFrb   g      @r_   rx   r6   é   ra   g       ÀN)r
   r,   r   r*   rF   r-   rc   rK   ÚINFrJ   rd   rL   Úlog1prE   r.   )r   ÚnegateZayr
   Úhr   ZsqayZzr1©ZPI_12ZTHRES_LARGEZTHRES_SMALLr   r   Ú
atanh_implñ  sD    

ÿ
 ÿÿzatanh_impl.<locals>.atanh_impl)	r*   rJ   rd   r   rj   ZFLT_MINÚpir9   r   )r   r   r   r   r„   r“   r!   r   r’   r   r“   ê  s    

,r“   )GÚ__doc__rP   r*   Znumba.core.imputilsr   r   Z
numba.corer   r   Znumba.core.typingr   Znumba.cpythonr   r   Znumba.core.extendingr	   ÚregistryÚlowerr   r   r   rF   rY   r"   r-   r#   r+   r$   Úrectr5   rA   ÚfloatrE   rŽ   rD   rI   rJ   rO   rT   Úlog10rZ   Zphaser\   Zpolarr^   rd   ri   r/   rm   rl   rq   r0   rs   rn   ru   ry   rw   rv   r}   Úacosr…   Úacoshrˆ   r   r‰   ÚasinrŠ   ÚatanrŒ   r‹   r“   r   r   r   r   Ú<module>   s~   



(





<


	







	
