Lines Matching refs:Fraction
17 A Fraction instance can be constructed from a pair of integers, from
20 .. class:: Fraction(numerator=0, denominator=1)
21 Fraction(other_fraction)
22 Fraction(float)
23 Fraction(decimal)
24 Fraction(string)
27 of :class:`numbers.Rational` and returns a new :class:`Fraction` instance
31 :class:`Fraction` instance with the same value. The next two versions accept
33 :class:`Fraction` instance with exactly the same value. Note that due to the
35 argument to ``Fraction(1.1)`` is not exactly equal to 11/10, and so
36 ``Fraction(1.1)`` does *not* return ``Fraction(11, 10)`` as one might expect.
47 accepted by the :class:`Fraction` constructor. In either form the
51 >>> from fractions import Fraction
52 >>> Fraction(16, -10)
53 Fraction(-8, 5)
54 >>> Fraction(123)
55 Fraction(123, 1)
56 >>> Fraction()
57 Fraction(0, 1)
58 >>> Fraction('3/7')
59 Fraction(3, 7)
60 >>> Fraction(' -3/7 ')
61 Fraction(-3, 7)
62 >>> Fraction('1.414213 \t\n')
63 Fraction(1414213, 1000000)
64 >>> Fraction('-.125')
65 Fraction(-1, 8)
66 >>> Fraction('7e-6')
67 Fraction(7, 1000000)
68 >>> Fraction(2.25)
69 Fraction(9, 4)
70 >>> Fraction(1.1)
71 Fraction(2476979795053773, 2251799813685248)
73 >>> Fraction(Decimal('1.1'))
74 Fraction(11, 10)
77 The :class:`Fraction` class inherits from the abstract base class
79 operations from that class. :class:`Fraction` instances are hashable,
81 :class:`Fraction` has the following properties and methods:
84 The :class:`Fraction` constructor now accepts :class:`float` and
90 Numerator of the Fraction in lowest term.
94 Denominator of the Fraction in lowest term.
99 This class method constructs a :class:`Fraction` representing the exact
101 ``Fraction.from_float(0.3)`` is not the same value as ``Fraction(3, 10)``.
106 :class:`Fraction` instance directly from a :class:`float`.
111 This class method constructs a :class:`Fraction` representing the exact
117 :class:`Fraction` instance directly from a :class:`decimal.Decimal`
123 Finds and returns the closest :class:`Fraction` to ``self`` that has
127 >>> from fractions import Fraction
128 >>> Fraction('3.1415926535897932').limit_denominator(1000)
129 Fraction(355, 113)
134 >>> Fraction(cos(pi/3))
135 Fraction(4503599627370497, 9007199254740992)
136 >>> Fraction(cos(pi/3)).limit_denominator()
137 Fraction(1, 2)
138 >>> Fraction(1.1).limit_denominator()
139 Fraction(11, 10)
148 >>> floor(Fraction(355, 113))
163 nearest multiple of ``Fraction(1, 10**ndigits)`` (logically, if