mirror of
https://github.com/python/cpython.git
synced 2026-01-06 07:22:09 +00:00
Revert "bpo-26680: Incorporate is_integer in all built-in and standard library numeric types (GH-6121)" (GH-22584)
This reverts commit 58a7da9e12.
This commit is contained in:
parent
4f3c25043d
commit
4e0ce82058
16 changed files with 24 additions and 223 deletions
|
|
@ -621,13 +621,6 @@ Decimal objects
|
|||
Return :const:`True` if the argument is either positive or negative
|
||||
infinity and :const:`False` otherwise.
|
||||
|
||||
.. method:: is_integer()
|
||||
|
||||
Return :const:`True` if the argument is a finite integral value and
|
||||
:const:`False` otherwise.
|
||||
|
||||
.. versionadded:: 3.10
|
||||
|
||||
.. method:: is_nan()
|
||||
|
||||
Return :const:`True` if the argument is a (quiet or signaling) NaN and
|
||||
|
|
@ -1222,13 +1215,6 @@ In addition to the three supplied contexts, new contexts can be created with the
|
|||
Returns ``True`` if *x* is infinite; otherwise returns ``False``.
|
||||
|
||||
|
||||
.. method:: is_integer(x)
|
||||
|
||||
Returns ``True`` if *x* is finite and integral; otherwise
|
||||
returns ``False``.
|
||||
|
||||
.. versionadded:: 3.10
|
||||
|
||||
.. method:: is_nan(x)
|
||||
|
||||
Returns ``True`` if *x* is a qNaN or sNaN; otherwise returns ``False``.
|
||||
|
|
|
|||
|
|
@ -49,30 +49,19 @@ The numeric tower
|
|||
numbers.
|
||||
|
||||
In short, those are: a conversion to :class:`float`, :func:`math.trunc`,
|
||||
:func:`round`, :func:`math.floor`, :func:`math.ceil`, :func:`divmod`,
|
||||
:func:`~Real.is_integer`, ``//``, ``%``, ``<``, ``<=``, ``>``, and ``>=``.
|
||||
:func:`round`, :func:`math.floor`, :func:`math.ceil`, :func:`divmod`, ``//``,
|
||||
``%``, ``<``, ``<=``, ``>``, and ``>=``.
|
||||
|
||||
Real also provides defaults for :func:`complex`, :attr:`~Complex.real`,
|
||||
:attr:`~Complex.imag`, and :meth:`~Complex.conjugate`.
|
||||
|
||||
.. method:: is_integer()
|
||||
|
||||
Returns :const:`True` if this number has a finite and integral value,
|
||||
otherwise :const:`False`. This is a default implementation which
|
||||
relies on successful conversion to :class:`int`. It may be overridden
|
||||
in subclasses (such as it is in :class:`float`) for better performance,
|
||||
or to handle special values such as NaN which are not
|
||||
convertible to :class:`int`.
|
||||
|
||||
.. versionadded:: 3.10
|
||||
|
||||
|
||||
.. class:: Rational
|
||||
|
||||
Subtypes :class:`Real` and adds
|
||||
:attr:`~Rational.numerator` and :attr:`~Rational.denominator` properties, which
|
||||
should be in lowest terms. With these, it provides defaults for
|
||||
:func:`float` and :func:`~Real.is_integer`.
|
||||
should be in lowest terms. With these, it provides a default for
|
||||
:func:`float`.
|
||||
|
||||
.. attribute:: numerator
|
||||
|
||||
|
|
@ -86,10 +75,9 @@ The numeric tower
|
|||
.. class:: Integral
|
||||
|
||||
Subtypes :class:`Rational` and adds a conversion to :class:`int`. Provides
|
||||
defaults for :func:`float`, :attr:`~Rational.numerator`,
|
||||
:attr:`~Rational.denominator`, and :func:`~Real.is_integer`. Adds abstract
|
||||
methods for ``**`` and bit-string operations: ``<<``, ``>>``, ``&``, ``^``,
|
||||
``|``, ``~``.
|
||||
defaults for :func:`float`, :attr:`~Rational.numerator`, and
|
||||
:attr:`~Rational.denominator`. Adds abstract methods for ``**`` and
|
||||
bit-string operations: ``<<``, ``>>``, ``&``, ``^``, ``|``, ``~``.
|
||||
|
||||
|
||||
Notes for type implementors
|
||||
|
|
|
|||
|
|
@ -310,10 +310,6 @@ the operations, see :ref:`operator-summary`):
|
|||
+---------------------+---------------------------------+---------+--------------------+
|
||||
| ``x ** y`` | *x* to the power *y* | \(5) | |
|
||||
+---------------------+---------------------------------+---------+--------------------+
|
||||
| ``x.is_integer()`` | ``True`` if *x* has a finite | | :func:`~numbers\ |
|
||||
| | and integral value, otherwise | | .Real.is_integer` |
|
||||
| | ``False``. | | |
|
||||
+---------------------+---------------------------------+---------+--------------------+
|
||||
|
||||
.. index::
|
||||
triple: operations on; numeric; types
|
||||
|
|
@ -587,6 +583,16 @@ class`. float also has the following additional methods.
|
|||
:exc:`OverflowError` on infinities and a :exc:`ValueError` on
|
||||
NaNs.
|
||||
|
||||
.. method:: float.is_integer()
|
||||
|
||||
Return ``True`` if the float instance is finite with integral
|
||||
value, and ``False`` otherwise::
|
||||
|
||||
>>> (-2.0).is_integer()
|
||||
True
|
||||
>>> (3.2).is_integer()
|
||||
False
|
||||
|
||||
Two methods support conversion to
|
||||
and from hexadecimal strings. Since Python's floats are stored
|
||||
internally as binary numbers, converting a float to or from a
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue