Your IP : 3.15.218.44
�
c��fp � �� � d Z ddlmZ ddlZddlZddlZddlZddlZdgZej j
Zej j Z
ej dej ej z � � Z G d� dej � � ZdS )z/Fraction, infinite-precision, rational numbers.� ��DecimalN�Fractiona�
\A\s* # optional whitespace at the start,
(?P<sign>[-+]?) # an optional sign, then
(?=\d|\.\d) # lookahead for digit or .digit
(?P<num>\d*|\d+(_\d+)*) # numerator (possibly empty)
(?: # followed by
(?:/(?P<denom>\d+(_\d+)*))? # an optional denominator
| # or
(?:\.(?P<decimal>\d*|\d+(_\d+)*))? # an optional fractional part
(?:E(?P<exp>[-+]?\d+(_\d+)*))? # and optional exponent
)
\s*\Z # and optional whitespace to finish
c �l � � e Zd ZdZdZd.dd�� fd�Zed� � � Zed � � � Zd
� Z d/d�Z
ed
� � � Zed� � � Z
d� Zd� Zd� Zd� Z eeej � � \ ZZd� Z eeej � � \ ZZd� Z eeej � � \ ZZd� Z eeej � � \ Z Z!d� Z" ee"ej# � � \ Z$Z%d� Z& ee&e'� � \ Z(Z)d� Z* ee*ej+ � � \ Z,Z-d� Z.d� Z/d� Z0d� Z1d� Z2ej3 fd�Z4d� Z5d � Z6d!� Z7d0d"�Z8d#� Z9d$� Z:d%� Z;d&� Z<d'� Z=d(� Z>d)� Z?d*� Z@d+� ZAd,� ZBd-� ZC� xZDS )1r 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 �� �� t t | � � � | � � }|���t |� � t u r||_ d|_ |S t |t j � � r|j
|_ |j |_ |S t |t t f� � r#|� � � \ |_ |_ |S t |t � � �r/t � |� � }|�t% d|z � � �t |� d� � pd� � }|� d� � }|rt |� � }n�d}|� d� � }|rB|� dd � � }d
t+ |� � z }||z t |� � z }||z }|� d� � } | r't | � � } | dk r |d
| z z }n |d
| z z }|� d
� � dk r| }n�t- d� � �t |� � t cxu rt |� � u rn nnbt |t j � � r9t |t j � � r|j
|j z |j
|j z }}nt- d� � �|dk rt/ d|z � � �|r(t1 j ||� � }
|dk r|
}
||
z }||
z }||_ ||_ |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: %r�num�0�denom�decimal�_� �
�expr �sign�-z2argument should be a string or a Rational instancez+both arguments should be Rational instanceszFraction(%s, 0))�superr �__new__�type�intr r �
isinstance�numbers�Rational� numerator�denominator�floatr �as_integer_ratio�str�_RATIONAL_FORMAT�match�
ValueError�group�replace�len� TypeError�ZeroDivisionError�math�gcd)�clsr r r �self�mr r �scaler �g� __class__s ��0/opt/alt/python311/lib64/python3.11/fractions.pyr zFraction.__new__>