o
    iD                     @   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 )Nuno)fcmp_unorderedrealimagbuilderz r   T/home/ubuntu/veenaModal/venv/lib/python3.10/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)r4   r5   r6   r   r   r   impl_cmath_rect:   s   r8   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_finite	inner_sigr#   
inner_funcr   r   wrapperU   s   

z(intrinsic_complex_unary.<locals>.wrapperr   )rC   rD   r   rB   r   intrinsic_complex_unaryT   s   rE   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-   r2   r3   expr1   NANisnan)	r=   r>   r?   r@   csr4   r	   r
   r   r   r   exp_implk   s8   














rM   c                 C   s(   t t | |}t || }t||S )zcmath.log(x + y j))r-   loghypotatan2r1   )r=   r>   r?   r@   abr   r   r   log_impl   s   
rS   c                 C   s.   |\}}dd }|  ||||}t| |||S )zcmath.log(z, base)c                 S   s   t | t | S r   )cmathrN   )r   baser   r   r   log_base   s   zlog_base_impl.<locals>.log_baser<   r   )r    r   r!   r   r   rU   rV   r#   r   r   r   log_base_impl   s   rX   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))rT   rN   r1   r	   r
   r   LN_10r   r   
log10_impl   s   
z$impl_cmath_log10.<locals>.log10_implr(   r   Complex)r   r\   r   rZ   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-   rP   r
   r	   )r=   r   r   r   r6      s   zphase_impl.<locals>.implr]   r=   r6   r   r   r   
phase_impl   s   ra   c                 C      t | tjsd S dd }|S )Nc                 S   s&   | j | j}}t||t||fS r   )r	   r
   r-   rO   rP   )r=   r4   ir   r   r   r6      s   zpolar_impl.<locals>.implr]   r`   r   r   r   
polar_impl   s   rd   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         ?r9   )
r	   r
   r1   r/   r-   r0   rJ   copysignsqrtrO   )r   rQ   rR   scaletr	   r
   THRESr   r   	sqrt_impl   s6   




zsqrt_impl.<locals>.sqrt_impl)r   r:   bitwidthr   DBL_MAXFLT_MAXr<   r   )
r    r   r!   r   SQRT2ONE_PLUS_SQRT2	theargfltMAXro   r#   r   rm   r   ro      s   *ro   c                 C   &   dd }|  ||||}t| |||S )Nc                 S   s   t t| j | jS )zcmath.cos(z) = cmath.cosh(z j))rT   coshr1   r
   r	   rY   r   r   r   cos_impl  s   zcos_impl.<locals>.cos_implrW   )r    r   r!   r   ry   r#   r   r   r   ry     s   ry   c                 C   rb   )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-   r0   rJ   r/   ri   r2   r3   r1   rx   sinhr   r=   r>   r	   r
   r   r   r   	cosh_impl  s"   


z"impl_cmath_cosh.<locals>.cosh_implr]   )r   r|   r   r   r   impl_cmath_cosh     r}   c                 C   rw   )Nc                 S   &   t t| j | j}t|j|j S )z#cmath.sin(z) = -j * cmath.sinh(z j))rT   rz   r1   r
   r	   r   r4   r   r   r   sin_impl7     zsin_impl.<locals>.sin_implrW   )r    r   r!   r   r   r#   r   r   r   r   6     r   c                 C   rb   )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-   r0   rJ   r2   r3   r/   r1   rz   rx   r{   r   r   r   	sinh_implD  s    




z"impl_cmath_sinh.<locals>.sinh_implr]   )r   r   r   r   r   impl_cmath_sinh@  s   r   c                 C   rw   )Nc                 S   r   )z#cmath.tan(z) = -j * cmath.tanh(z j))rT   tanhr1   r
   r	   r   r   r   r   tan_impl\  r   ztan_impl.<locals>.tan_implrW   )r    r   r!   r   r   r#   r   r   r   r   [  r   r   c                 C   rb   )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)re   r,          @)
r	   r
   r-   r0   ri   r3   r1   r   tanrx   )
r   r=   r>   r	   r
   txtycxtxtydenomr   r   r   	tanh_implj  s"   




z"impl_cmath_tanh.<locals>.tanh_implr]   )r   r   r   r   r   impl_cmath_tanhf  r~   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)rh   re   r   )r/   r	   r
   r-   rP   ri   rN   rO   r1   rT   rj   asinhr   r	   r
   s1s2LN_4rn   r   r   	acos_impl  s    

zacos_impl.<locals>.acos_implr-   rN   r   rr   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)rh   re   r   )r/   r	   r
   r-   rN   rO   rP   r1   rT   rj   r   r   r   r   r   
acosh_impl  s   "

z$impl_cmath_acosh.<locals>.acosh_impl)r(   r   r^   r-   rN   r   rr   )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)rh   re   )r/   r	   r
   r-   ri   rN   rO   rP   r1   rT   rj   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   rw   )Nc                 S   r   )z%cmath.asin(z) = -j * cmath.asinh(z j))rT   r   r1   r
   r	   r   r   r   r   	asin_impl  r   zasin_impl.<locals>.asin_implrW   )r    r   r!   r   r   r#   r   r   r   r     r   r   c                 C   rw   )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))rT   atanhr1   r
   r	   r-   r0   rJ   r   r   r   r   	atan_impl  s   zatan_impl.<locals>.atan_implrW   )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   r9   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,   TFrh   g      @re   r   r9      rg   g       )r	   r/   r
   r-   rJ   r0   ri   rO   INFrN   rj   rP   log1prI   r1   )r   negateayr	   hr
   sqayzr1PI_12THRES_LARGETHRES_SMALLr   r   
atanh_impl  sD   


 
zatanh_impl.<locals>.atanh_impl)	r-   rN   rj   r   rr   FLT_MINpir<   r   )r    r   r!   r   r   r   r#   r   r   r   r     s   

,r   )+__doc__rT   r-   numba.core.imputilsr   
numba.corer   numba.core.typingr   numba.cpythonr   numba.core.extendingr   r   r   r   r$   r&   r'   r8   rE   floatrI   r   rM   rS   rX   r_   ra   rd   ro   ry   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sN    		
)
=	

