Hacked By AnonymousFox
B
� f�\ � @ s� d Z ddlmZ ddlZddlZddlZddlZddlZddgZdd� Z dd� Z
ejjZ
ejjZe�d ejejB �ZG d
d� dej�ZdS )z+Fraction, infinite-precision, real numbers.� )�DecimalN�Fraction�gcdc C sf ddl }|�dtd� t| �t kr2t|�kr\n n&|p<| dk rPt�| |� S t�| |�S t| |�S )z�Calculate the Greatest Common Divisor of a and b.
Unless b==0, the result will have the same sign as b (so that when
b is divided by it, the result comes out positive).
r Nz6fractions.gcd() is deprecated. Use math.gcd() instead.� )�warnings�warn�DeprecationWarning�type�int�mathr �_gcd)�a�br � r �./opt/alt/python37/lib64/python3.7/fractions.pyr s c C s x|r|| | } }qW | S )Nr )r
r r r r r s r aC
\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
c s� e Zd ZdZdZdRdd�� fdd�Zed d
� �Zedd� �ZdSdd�Z e
dd� �Ze
dd� �Zdd� Z
dd� Zdd� Zdd� Zeeej�\ZZdd� Zeeej�\ZZdd� Zeeej�\ZZd d!� Zeeej�\ZZ 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,dTd:d;�Z-d<d=� Z.d>d?� Z/d@dA� Z0dBdC� Z1dDdE� Z2dFdG� Z3dHdI� Z4dJdK� Z5dLdM� Z6dNdO� Z7dPdQ� Z8� Z9S )Ur a] This class implements rational numbers.
In the two-argument form of the constructor, Fraction(8, 6) will
produce a rational number equivalent to 4/3. Both arguments must
be Rational. The numerator defaults to 0 and the denominator
defaults to 1 so that Fraction(3) == 3 and Fraction() == 0.
Fractions can also be constructed from:
- numeric strings similar to those accepted by the
float constructor (for example, '-2.3' or '1e10')
- strings of the form '123/456'
- float and Decimal instances
- other Rational instances (including integers)
)�
_numerator�_denominatorr NT)�
_normalizec sR t t| ��| �}|dk�rdt|�tkr6||_d|_|S t|tj �rV|j
|_|j|_|S t|tt
f�rx|�� \|_|_|S t|t��rZt�|�}|dkr�td| ��t|�d�p�d�}|�d�}|r�t|�}nvd}|�d�}|�rdt|� }|| t|� }||9 }|�d �} | �rBt| �} | d
k�r4|d| 9 }n|d| 9 }|�d�dk�rb| }ntd
��nft|�t k�r�t|�k�r�n nn@t|tj ��r�t|tj ��r�|j
|j |j
|j }}ntd��|d
k�r�td| ��|�rBt|�t k�rt|�k�r(n nt�||�}
|d
k �r2|
}
n
t||�}
||
}||
}||_||_|S )a� Constructs a Rational.
Takes a string like '3/2' or '1.5', another Rational instance, a
numerator/denominator pair, or a float.
Examples
--------
>>> Fraction(10, -8)
Fraction(-5, 4)
>>> Fraction(Fraction(1, 7), 5)
Fraction(1, 35)
>>> Fraction(Fraction(1, 7), Fraction(2, 3))
Fraction(3, 14)
>>> Fraction('314')
Fraction(314, 1)
>>> Fraction('-35/4')
Fraction(-35, 4)
>>> Fraction('3.1415') # conversion from numeric string
Fraction(6283, 2000)
>>> Fraction('-47e-2') # string may include a decimal exponent
Fraction(-47, 100)
>>> Fraction(1.47) # direct construction from float (exact conversion)
Fraction(6620291452234629, 4503599627370496)
>>> Fraction(2.25)
Fraction(9, 4)
>>> Fraction(Decimal('1.47'))
Fraction(147, 100)
N� z Invalid literal for Fraction: %rZnum�0�denom�decimal�
�expr Zsign�-z2argument should be a string or a Rational instancez+both arguments should be Rational instanceszFraction(%s, 0))�superr �__new__r r
r r �
isinstance�numbers�Rational� numerator�denominator�floatr �as_integer_ratio�str�_RATIONAL_FORMAT�match�
ValueError�group�len� TypeError�ZeroDivisionErrorr r r )�clsr r! r �self�mr r Zscaler �g)� __class__r r r T sr
$
$
zFraction.__new__c C sD t |tj�r| |�S t |t�s8td| j|t|�jf ��| |�� � S )z�Converts a finite float to a rational number, exactly.
Beware that Fraction.from_float(0.3) != Fraction(3, 10).
z.%s.from_float() only takes floats, not %r (%s))r r �Integralr"