o
    1&iF                     @   sD  d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlm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ZedZe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d*d+ Z d,d- Z!d.d/ Z"d0d1 Z#d2d3 Z$d4d5 Z%d6d7 Z&d8d9 Z'd:d; Z(d<d= Z)d>d? Z*dS )@z'
Implement the cmath module functions.
    N)impl_ret_untracked)types)	signature)mathimpl)overloadc                 C   s   |  d|j|jS )NZuno)Zfcmp_unorderedrealimagbuilderz r   BC:\wamp64\www\opt\env\Lib\site-packages\numba/np/math/cmathimpl.pyis_nan   s   r   c                 C       |  t| |jt| |jS N)or_r   is_infr   r   r	   r   r   r   r         r   c                 C   r   r   )and_r   	is_finiter   r   r	   r   r   r   r      r   r   c                 C   8   |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    
   
r"   c                 C   r   r   )r   r   r   r   r   r   r   r   r   isinf_float_impl(   r#   r$   c                 C   r   r   )r   r   r   r   r   r   r   r   r   isfinite_float_impl1   r#   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r-t | r-||  }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)r2   r3   r4   r   r   r   impl_cmath_rect:   s   r6   c                    s    fdd}|S )Nc              	      s   |j \}|\}| j|||d}|j}|j}t||}	t||}
t|jg|jfd t	j
fd  R  }| | ||||	|
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@   rA   r   r?   r   intrinsic_complex_unaryT   s   rB   naninfc           	      C   s   |r!|rt |}t |}t | }t|| || S tttS t | r2|r-t| | S t| |S | dkr\|rWt |}t |}|dkrJ|| 9 }|dkrR|| 9 }t||S t| tS |rvt | }t |}t |}t|| || S d}t||S )zcmath.exp(x + y j)r*   r   )r+   r0   r1   expr/   NANisnan)	r;   r<   r=   r>   csr2   r   r   r   r   r   exp_implk   s8   














rJ   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   
rP   c                 C   s.   |\}}dd }|  ||||}t| |||S )zcmath.log(z, base)c                 S   s   t | t | S r   )cmathrK   )r   baser   r   r   log_base   s   zlog_base_impl.<locals>.log_baser:   r   )r   r
   r   r   r   rR   rS   r!   r   r   r   log_base_impl   s   rU   c                    s$   t | tjsd S d  fdd}|S )NgUk@c                    s    t | } t| j  | j  S )zcmath.log10(z))rQ   rK   r/   r   r   r   ZLN_10r   r   
log10_impl   s   
z$impl_cmath_log10.<locals>.log10_implr&   r   Complex)r   rX   r   rW   r   impl_cmath_log10   s
   r[   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+   rM   r   r   )r;   r   r   r   r4      s   zphase_impl.<locals>.implrY   r;   r4   r   r   r   
phase_impl   s   r]   c                 C      t | tjsd S dd }|S )Nc                 S   s&   | j | j}}t||t||fS r   )r   r   r+   rL   rM   )r;   r2   ir   r   r   r4      s   zpolar_impl.<locals>.implrY   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                    sR  | j }| j}|dkr|dkrtt||S t|r!tt||S t|r+t||S t|rL|dk rAtt|| t||S t|t|| |S t| ksXt| krc|d9 }|d9 }d}nd}|dkrt|t	|| d }|}|d|  }nt| t	|| d }t|d|  }t||}|rt|d |S t||S )zcmath.sqrt(z)r*         ?TFr         ?r7   )
r   r   r/   r-   r+   r.   rG   copysignsqrtrL   )r   rN   rO   scaletr   r   THRESr   r   	sqrt_impl   s6   




zsqrt_impl.<locals>.sqrt_impl)r   r8   Zbitwidthr   ZDBL_MAXFLT_MAXr:   r   )
r   r
   r   r   ZSQRT2ZONE_PLUS_SQRT2Z	theargfltMAXrk   r!   r   ri   r   rk      s   *rk   c                 C   &   dd }|  ||||}t| |||S )Nc                 S   s   t t| j | jS )zcmath.cos(z) = cmath.cosh(z j))rQ   coshr/   r   r   rV   r   r   r   cos_impl  s   zcos_impl.<locals>.cos_implrT   )r   r
   r   r   rp   r!   r   r   r   rp     s   rp   c                 C   r^   )Nc                 S   s   | j }| j}t|r@t|rt|}|}n|dkr"t|}|}nt|t|}t|t|}|dk r;| }t	||S t	t|t
| t|t| S )zcmath.cosh(z)r*   )r   r   r+   r.   rG   r-   re   r0   r1   r/   ro   sinhr   r;   r<   r   r   r   r   r   	cosh_impl  s"   


z"impl_cmath_cosh.<locals>.cosh_implrY   )r   rs   r   r   r   impl_cmath_cosh     rt   c                 C   rn   )Nc                 S   &   t t| j | j}t|j|j S )z#cmath.sin(z) = -j * cmath.sinh(z j))rQ   rq   r/   r   r   r   r2   r   r   r   sin_impl7     zsin_impl.<locals>.sin_implrT   )r   r
   r   r   rx   r!   r   r   r   rx   6     rx   c                 C   r^   )Nc                 S   s   | j }| j}t|r6t|r|}|}nt|}t|}|dkr'||9 }|dkr1|t|9 }t||S tt|t	| t|t
| S )zcmath.sinh(z)r*   )r   r   r+   r.   rG   r0   r1   r-   r/   rq   ro   rr   r   r   r   	sinh_implD  s    




z"impl_cmath_sinh.<locals>.sinh_implrY   )r   r{   r   r   r   impl_cmath_sinh@  s   r|   c                 C   rn   )Nc                 S   rv   )z#cmath.tan(z) = -j * cmath.tanh(z j))rQ   tanhr/   r   r   rw   r   r   r   tan_impl\  ry   ztan_impl.<locals>.tan_implrT   )r   r
   r   r   r~   r!   r   r   r   r~   [  rz   r~   c                 C   r^   )Nc           
      S   s   | j }| j}t|r)td|}t|rd}ntdtd| }t||S t|}t|}dt	| }|| }d||  }	t|d||   |	 ||	 | | S )zcmath.tanh(z)ra   r*          @)
r   r   r+   r.   re   r1   r/   r}   tanro   )
r   r;   r<   r   r   ZtxtycxZtxtydenomr   r   r   	tanh_implj  s"   




z"impl_cmath_tanh.<locals>.tanh_implrY   )r   r   r   r   r   impl_cmath_tanhf  ru   r   c                    @   t d tjd  fdd}| ||||}t| |||S )N   c              	      s   t | jkst | jkr4t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 )zcmath.acos(z)rd   ra   r   )r-   r   r   r+   rM   re   rK   rL   r/   rQ   rf   asinhr   r   r   s1s2LN_4rj   r   r   	acos_impl  s    

zacos_impl.<locals>.acos_implr+   rK   r   rl   r:   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r,t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 )zcmath.acosh(z)rd   ra   r   )r-   r   r   r+   rK   rL   rM   r/   rQ   rf   r   r   r   r   r   
acosh_impl  s   "

z$impl_cmath_acosh.<locals>.acosh_impl)r&   r   rZ   r+   rK   r   rl   )r   r   r   r   r   impl_cmath_acosh  s   

r   c                    r   )Nr   c              	      s   t | jkst | jkr3t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 )zcmath.asinh(z)rd   ra   )r-   r   r   r+   re   rK   rL   rM   r/   rQ   rf   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   rn   )Nc                 S   rv   )z%cmath.asin(z) = -j * cmath.asinh(z j))rQ   r   r/   r   r   rw   r   r   r   	asin_impl  ry   zasin_impl.<locals>.asin_implrT   )r   r
   r   r   r   r!   r   r   r   r     rz   r   c                 C   rn   )Nc                 S   sL   t t| j | j}t| jrt| jrt|j|jS t|j|j S )z%cmath.atan(z) = -j * cmath.atanh(z j))rQ   atanhr/   r   r   r+   r.   rG   rw   r   r   r   	atan_impl  s   zatan_impl.<locals>.atan_implrT   )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   r7   c              	      s  | j dk rd}|  } nd}t| j}t| j s!| j ks!|krWt| jr/td| j }nt| j r8d}nt| j d | jd }| j d | | }t | j  }n`| j dkr|k r|dkrjt}| j}nMt	t
|t
t|d  }ttd| d | j}n,|| }d	| j  }td| j  || |  d
 }td| j |d	| j   |  d }t| jrt}|rt| | S t||S )zcmath.atanh(z)r*   TFrd   g      @ra   r   r7      rc   g       )r   r-   r   r+   rG   r.   re   rL   INFrK   rf   rM   log1prF   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+   rK   rf   r   rl   ZFLT_MINpir:   r   )r   r
   r   r   r   r   r!   r   r   r   r     s   

,r   )+__doc__rQ   r+   Znumba.core.imputilsr   Z
numba.corer   Znumba.core.typingr   Znumba.cpythonr   Znumba.core.extendingr   r   r   r   r"   r$   r%   r6   rB   floatrF   r   rJ   rP   rU   r[   r]   r`   rk   rp   rt   rx   r|   r~   r   r   r   r   r   r   r   r   r   r   r   <module>   sN    		
)
=	

