@@ -49,19 +49,30 @@ The numeric tower
4949 numbers.
5050
5151 In short, those are: a conversion to :class: `float `, :func: `math.trunc `,
52- :func: `round `, :func: `math.floor `, :func: `math.ceil `, :func: `divmod `, `` // ``,
53- ``% ``, ``< ``, ``<= ``, ``> ``, and ``>= ``.
52+ :func: `round `, :func: `math.floor `, :func: `math.ceil `, :func: `divmod `,
53+ :func: ` ~Real.is_integer `, `` // ``, ``% ``, ``< ``, ``<= ``, ``> ``, and ``>= ``.
5454
5555 Real also provides defaults for :func: `complex `, :attr: `~Complex.real `,
5656 :attr: `~Complex.imag `, and :meth: `~Complex.conjugate `.
5757
58+ .. method :: is_integer()
59+
60+ Returns :const: `True ` if this number has a finite and integral value,
61+ otherwise :const: `False `. This is a default implementation which
62+ relies on successful conversion to :class: `int `. It may be overridden
63+ in subclasses (such as it is in :class: `float `) for better performance,
64+ or to handle special values such as NaN which are not
65+ convertible to :class: `int `.
66+
67+ .. versionadded :: 3.10
68+
5869
5970.. class :: Rational
6071
6172 Subtypes :class: `Real ` and adds
6273 :attr: `~Rational.numerator ` and :attr: `~Rational.denominator ` properties, which
63- should be in lowest terms. With these, it provides a default for
64- :func: `float `.
74+ should be in lowest terms. With these, it provides defaults for
75+ :func: `float ` and :func: ` ~Real.is_integer ` .
6576
6677 .. attribute :: numerator
6778
@@ -75,9 +86,10 @@ The numeric tower
7586.. class :: Integral
7687
7788 Subtypes :class: `Rational ` and adds a conversion to :class: `int `. Provides
78- defaults for :func: `float `, :attr: `~Rational.numerator `, and
79- :attr: `~Rational.denominator `. Adds abstract methods for ``** `` and
80- bit-string operations: ``<< ``, ``>> ``, ``& ``, ``^ ``, ``| ``, ``~ ``.
89+ defaults for :func: `float `, :attr: `~Rational.numerator `,
90+ :attr: `~Rational.denominator `, and :func: `~Real.is_integer `. Adds abstract
91+ methods for ``** `` and bit-string operations: ``<< ``, ``>> ``, ``& ``, ``^ ``,
92+ ``| ``, ``~ ``.
8193
8294
8395Notes for type implementors
0 commit comments