Your IP : 3.12.165.68


Current Path : /opt/alt/python310/lib64/python3.10/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/__pycache__/fractions.cpython-310.opt-2.pyc

o

6��fRn�@sv	ddlmZddlZddlZddlZddlZddlZdgZejj	Z
ejjZe�
dejejB�ZGdd�dej�ZdS)���DecimalN�FractionaC
    \A\s*                      # optional whitespace at the start, then
    (?P<sign>[-+]?)            # an optional sign, then
    (?=\d|\.\d)                # lookahead for digit or .digit
    (?P<num>\d*)               # numerator (possibly empty)
    (?:                        # followed by
       (?:/(?P<denom>\d+))?    # an optional denominator
    |                          # or
       (?:\.(?P<decimal>\d*))? # an optional fractional part
       (?:E(?P<exp>[-+]?\d+))? # and optional exponent
    )
    \s*\Z                      # and optional whitespace to finish
cs�eZdZ	dZdQdd��fdd�Zedd	��Zed
d��Zdd
�ZdRdd�Z	e
dd��Ze
dd��Zdd�Z
dd�Zdd�Zdd�Zeeej�\ZZdd�Zeeej�\ZZdd �Zeeej�\ZZd!d"�Zeeej�\ZZ d#d$�Z!ee!ej"�\Z#Z$d%d&�Z%ee%e&�\Z'Z(d'd(�Z)ee)ej*�\Z+Z,d)d*�Z-d+d,�Z.d-d.�Z/d/d0�Z0d1d2�Z1d3d4�Z2d5d6�Z3d7d8�Z4dSd9d:�Z5d;d<�Z6d=d>�Z7d?d@�Z8dAdB�Z9dCdD�Z:dEdF�Z;dGdH�Z<dIdJ�Z=dKdL�Z>dMdN�Z?dOdP�Z@�ZAS)Tr��
_numerator�_denominatorrNT��
_normalizecs	tt|��|�}|dur�t|�tur||_d|_|St|tj	�r+|j
|_|j|_|St|tt
f�r<|��\|_|_|St|t�r�t�|�}|durPtd|��t|�d�pWd�}|�d�}|ret|�}n8d}|�d�}|r�dt|�}||t|�}||9}|�d�}	|	r�t|	�}	|	d	kr�|d|	9}n|d|	9}|�d
�dkr�|}n3td��t|�tur�t|�ur�nnnt|tj	�r�t|tj	�r�|j
|j|j
|j}}ntd
��|d	kr�td|��|r�t�||�}
|d	kr�|
}
||
}||
}||_||_|S)N�z Invalid literal for Fraction: %rZnum�0�denom�decimal�
�exprZsign�-z2argument should be a string or a Rational instancez+both arguments should be Rational instanceszFraction(%s, 0))�superr�__new__�type�intrr�
isinstance�numbers�Rational�	numerator�denominator�floatr�as_integer_ratio�str�_RATIONAL_FORMAT�match�
ValueError�group�len�	TypeError�ZeroDivisionError�math�gcd)�clsrrr	�self�mrr
Zscaler�g��	__class__��0/opt/alt/python310/lib64/python3.10/fractions.pyr>sx

�



� 
�

�zFraction.__new__cCsF	t|tj�r||�St|t�std|j|t|�jf��||���S)Nz.%s.from_float() only takes floats, not %r (%s))rr�Integralrr"�__name__rr)r&�fr,r,r-�
from_float�s
�zFraction.from_floatcCsX	ddlm}t|tj�r|t|��}nt||�s&td|j|t|�jf��||�	��S)Nrrz2%s.from_decimal() only takes Decimals, not %r (%s))
r
rrrr.rr"r/rr)r&Zdecrr,r,r-�from_decimal�s
��zFraction.from_decimalcCs	|j|jfS�Nr�r'r,r,r-r�szFraction.as_integer_ratio�@Bc
Cs�	|dkr	td��|j|krt|�Sd\}}}}|j|j}}	||}|||}	|	|kr/n||||||	f\}}}}||||}}q |||}
t||
|||
|�}t||�}t||�t||�krm|S|S)Nr
z$max_denominator should be at least 1)rr
r
r)rrrr�abs)
r'Zmax_denominatorZp0Zq0Zp1Zq1�n�d�aZq2�kZbound1Zbound2r,r,r-�limit_denominator�s*
�
zFraction.limit_denominatorcC�|jSr3)r�r9r,r,r-r�zFraction.numeratorcCr<r3)rr=r,r,r-rr>zFraction.denominatorcCs	d|jj|j|jfS)Nz
%s(%s, %s))r+r/rrr4r,r,r-�__repr__s�zFraction.__repr__cCs&	|jdkrt|j�Sd|j|jfS)Nr
z%s/%s)rrrr4r,r,r-�__str__
s

zFraction.__str__csV	��fdd�}d�jd|_�j|_��fdd�}d�jd|_�j|_||fS)NcsLt|ttf�r�||�St|t�r�t|�|�St|t�r$�t|�|�StSr3)rrrr�complex�NotImplemented�r9�b��fallback_operator�monomorphic_operatorr,r-�forwardds


z-Fraction._operator_fallbacks.<locals>.forward�__csVt|tj�r�||�St|tj�r�t|�t|��St|tj�r)�t|�t|��StSr3)rrrZRealr�ComplexrArB�rDr9rEr,r-�reverseps
z-Fraction._operator_fallbacks.<locals>.reverseZ__r)r/�__doc__)rGrFrHrLr,rEr-�_operator_fallbackssO	
zFraction._operator_fallbacksc
Cs�	|j|j}}|j|j}}t�||�}|dkr(t||||||dd�S||}|||||}t�||�}	|	dkrIt|||dd�St||	|||	dd�S�Nr
Fr�rrr$r%r�
r9rD�na�da�nb�dbr)�s�t�g2r,r,r-�_add��z
Fraction._addc
Cs�	|j|j}}|j|j}}t�||�}|dkr(t||||||dd�S||}|||||}t�||�}	|	dkrIt|||dd�St||	|||	dd�SrOrPrQr,r,r-�_sub�rZz
Fraction._subcCs|	|j|j}}|j|j}}t�||�}|dkr!||}||}t�||�}|dkr3||}||}t||||dd�SrOrP)r9rDrRrSrTrU�g1rXr,r,r-�_mul�sz
Fraction._mulc
Cs�	|j|j}}|j|j}}t�||�}|dkr!||}||}t�||�}|dkr3||}||}||||}}	|	dkrG||	}}	t||	dd�S�Nr
rFrrP)
r9rDrRrSrTrUr\rXr7r8r,r,r-�_div�sz
Fraction._divcCs	|j|j|j|jSr3�rrrCr,r,r-�	_floordivszFraction._floordivcCs<	|j|j}}t|j|||j�\}}|t|||�fSr3)r�divmodrr)r9rDrSrUZdivZn_modr,r,r-�_divmod
szFraction._divmodcCs.	|j|j}}t|j||j|||�Sr3)rrr)r9rDrSrUr,r,r-�_modsz
Fraction._modcCs�	t|tj�rM|jdkrE|j}|dkr t|j||j|dd�S|jdkr4t|j||j|dd�St|j||j|dd�St|�t|�St|�|Sr^)	rrrrrrrrr)r9rDZpowerr,r,r-�__pow__s(

�

��zFraction.__pow__cCs^	|jdkr|jdkr||jSt|tj�rt|j|j�|S|jdkr)||jS|t|�S)Nr
r)	rrrrrrrrrrKr,r,r-�__rpow__:s


zFraction.__rpow__cCs	t|j|jdd�S�NFr�rrrr=r,r,r-�__pos__HszFraction.__pos__cCs	t|j|jdd�Srgrhr=r,r,r-�__neg__LszFraction.__neg__cCs	tt|j�|jdd�Srg)rr6rrr=r,r,r-�__abs__PszFraction.__abs__cCs(	|jdkr|j|jS|j|jS)Nrrr=r,r,r-�	__trunc__Ts
zFraction.__trunc__cCs	|j|jSr3r`r=r,r,r-�	__floor__[szFraction.__floor__cCs	|j|jSr3r`r=r,r,r-�__ceil___szFraction.__ceil__cCs�	|dur.t|j|j�\}}|d|jkr|S|d|jkr"|dS|ddkr*|S|dSdt|�}|dkrAtt||�|�Stt||�|�S)N�r
rr)rbrrr6r�round)r'ZndigitsZfloorZ	remainder�shiftr,r,r-�	__round__dszFraction.__round__cCsf	z	t|jdt�}Wntyt}Ynwttt|j��|�}|jdkr(|n|}|dkr1dS|S)N���r���)�powr�_PyHASH_MODULUSr�_PyHASH_INF�hashr6r)r'ZdinvZhash_�resultr,r,r-�__hash__}s�zFraction.__hash__cCs�	t|�tur|j|ko|jdkSt|tj�r#|j|jko"|j|jkSt|tj	�r1|j
dkr1|j}t|t�rKt
�|�s@t
�|�rDd|kS||�|�kStS)Nr
r�)rrrrrrrrrrJ�imag�realrr$�isnan�isinfr1rBrCr,r,r-�__eq__�s
�
zFraction.__eq__cCsd	t|tj�r||j|j|j|j�St|t�r0t�	|�s#t�
|�r(|d|�S|||�|��StS)Nr{)
rrrrrrrrr$r~rr1rB)r'�other�opr,r,r-�_richcmp�s

�

zFraction._richcmpcC�	|�|tj�Sr3)r��operator�ltrCr,r,r-�__lt__��zFraction.__lt__cCr�r3)r�r��gtrCr,r,r-�__gt__�r�zFraction.__gt__cCr�r3)r�r��lerCr,r,r-�__le__�r�zFraction.__le__cCr�r3)r�r��gerCr,r,r-�__ge__�r�zFraction.__ge__cCs	t|j�Sr3)�boolrr=r,r,r-�__bool__�s
zFraction.__bool__cCs|jt|�ffSr3)r+rr4r,r,r-�
__reduce__�szFraction.__reduce__cC� t|�tkr|S|�|j|j�Sr3�rrr+rrr4r,r,r-�__copy__��zFraction.__copy__cCr�r3r�)r'Zmemor,r,r-�__deepcopy__�r�zFraction.__deepcopy__)rN)r5r3)Br/�
__module__�__qualname__�	__slots__r�classmethodr1r2rr;�propertyrrr?r@rNrYr��add�__add__�__radd__r[�sub�__sub__�__rsub__r]�mul�__mul__�__rmul__r_�truediv�__truediv__�__rtruediv__ra�floordiv�__floordiv__�
__rfloordiv__rcrb�
__divmod__�__rdivmod__rd�mod�__mod__�__rmod__rerfrirjrkrlrmrnrrrzr�r�r�r�r�r�r�r�r�r��
__classcell__r,r,r*r-r&shi


7

0
!)r
rr$rr��re�sys�__all__�	hash_info�modulusrv�infrw�compile�VERBOSE�
IGNORECASErrrr,r,r,r-�<module>s
�

?>