o
    h                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
mZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZ eG dd de	eZeG d	d
 d
e
eZejZeG dd deZ dS )zReal and complex elements.     )MPQ)DomainElement)public)PythonMPContext_mpf_mpc	_constant)MPZ_ONEfzerofonefinffninffnanround_nearestmpf_mulrepr_dps	int_typesfrom_int
from_floatfrom_strto_rationalc                   @   2   e Zd ZdZdZdd Zedd eZdd Zd	S )
RealElementzAn element of a real domain. Z__mpf__c                 C   
   || _ d S Nr   selfval r   d/home/www/facesmatcher.com/frenv_anti/lib/python3.10/site-packages/sympy/polys/domains/mpelements.py_set_mpf      
zRealElement._set_mpfc                 C      | j S r   r   r   r   r   r    <lambda>       zRealElement.<lambda>c                 C      | j jS r   contextZ_parentr$   r   r   r    parent      zRealElement.parentN)	__name__
__module____qualname____doc__	__slots__r!   property_mpf_r*   r   r   r   r    r          r   c                   @   r   )
ComplexElementz An element of a complex domain. Z__mpc__c                 C   r   r   r5   r   r   r   r    _set_mpc&   r"   zComplexElement._set_mpcc                 C   r#   r   r5   r$   r   r   r    r%   )   r&   zComplexElement.<lambda>c                 C   r'   r   r(   r$   r   r   r    r*   +   r+   zComplexElement.parentN)	r,   r-   r.   r/   r0   r6   r1   Z_mpc_r*   r   r   r   r    r4       r3   r4   c                   @   sb   e Zd ZdddZdd Zdd	 Zd
d Zdd Zedd Z	edd Z
dddZdddZdS )	MPContext5   NFc                 C   sX  |t g| _|d u r| | n| | t| _t| _| jt| jg| j_	| jt| jg| j_	|r3| | j_
n| | j_
t| _| jt| jg| j_	| | j_
| j| j| jg| _d| _d| _|d u r`|  | _n|du rht| _n| || _| | j| _| js|d| _ntd| j | _| t| _| t| _| ttf| _| t| _| t| _ | t!| _"d S )NTFi@B    )#r   _prec_roundingZ	_set_precZ_set_dpsr   Zmpfr4   ZmpcnewZ_ctxdatar)   r   ZconstanttypesZtrap_complexpretty	_make_toltolr
   _convert_tolmake_mpf	tolerance	max_denomintzeror   oneZmake_mpcjr   infr   Zninfr   nan)ctxprecZdpsr?   realr   r   r    __init__3   s@   


zMPContext.__init__c                 C   s    d}dt d| j df}t||S )N)r            r   r9   )r	   rK   r   )rJ   Zhundredepsr   r   r    r>   b   s   
zMPContext._make_tolc                 C   s   |  |  S r   )rA   r>   rJ   r   r   r    make_tolg   s   zMPContext.make_tolc                 C   s`   t |tr	t|S t |trt|S t|dr|jS | j\}}t |tr*t	|||S t
d| )Nr2   zexpected a real number, got %s)
isinstancer   r   floatr   hasattrr2   r:   strr   
ValueError)rJ   r?   rK   roundingr   r   r    r@   j   s   




zMPContext._convert_tolc                 C   s   t dt| )Nzcannot create mpf from )	TypeErrorrepr)rJ   xstringsr   r   r    _convert_fallbackv   s   zMPContext._convert_fallbackc                 C   s
   t | jS r   )r   Z_precrR   r   r   r    _repr_digitsy   s   
zMPContext._repr_digitsc                 C   r#   r   )Z_dpsrR   r   r   r    _str_digits}   s   zMPContext._str_digitsTc                 C   s  t |j\}}t|}|r|| jkr||fS d\}}}}||}	}
	 |	|
 }|||  }|| jkr2qJ|||||  |f\}}}}|
|	||
  }	}
q"| j| | }t||}t|||  |||  }t||}|rl|sp||fS t|| t|| kr|j|jfS |j|jfS )N)r   r9   r9   r   )r   r2   rD   rC   r   abs	numeratordenominator)rJ   slimitpqp0q0p1q1ndaq2knumberbound1bound2r   r   r    r      s.   



zMPContext.to_rationalc           	      C   s   |  |}|d u r|d u r| jp|   }}|d u r |  |}n	|d u r)|  |}t|| }||kr5dS t|}t|}||k rI|| }||kS || }||kS )NT)convertrB   rS   ra   )	rJ   rd   tZrel_epsZabs_epsdiffZabssZabsterrr   r   r    almosteq   s"   

zMPContext.almosteq)r8   NNF)T)NN)r,   r-   r.   rM   r>   rS   r@   r^   r1   r_   r`   r   rx   r   r   r   r    r7   0   s    
/


#r7   N)!r/   Zsympy.external.gmpyr   Z!sympy.polys.domains.domainelementr   Zsympy.utilitiesr   Zmpmath.ctx_mp_pythonr   r   r   r   Zmpmath.libmpr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r4   object__new__r;   r7   r   r   r   r    <module>   s   @