summaryrefslogtreecommitdiffstats
path: root/Lib/test/decimaltestdata/extra.decTest
diff options
context:
space:
mode:
authorRobert Smallshire <robert@smallshire.org.uk>2020-10-01 16:30:08 (GMT)
committerGitHub <noreply@github.com>2020-10-01 16:30:08 (GMT)
commit58a7da9e125422323f79c4ee95ac5549989d8162 (patch)
tree869afbca82bfd7a27dab5d3b6638e2ac203f4519 /Lib/test/decimaltestdata/extra.decTest
parent256e54acdbdb26745d4bbb5cf366454151e42773 (diff)
downloadcpython-58a7da9e125422323f79c4ee95ac5549989d8162.zip
cpython-58a7da9e125422323f79c4ee95ac5549989d8162.tar.gz
cpython-58a7da9e125422323f79c4ee95ac5549989d8162.tar.bz2
bpo-26680: Incorporate is_integer in all built-in and standard library numeric types (GH-6121)
* bpo-26680: Adds support for int.is_integer() for compatibility with float.is_integer(). The int.is_integer() method always returns True. * bpo-26680: Adds a test to ensure that False.is_integer() and True.is_integer() are always True. * bpo-26680: Adds Real.is_integer() with a trivial implementation using conversion to int. This default implementation is intended to reduce the workload for subclass implementers. It is not robust in the presence of infinities or NaNs and may have suboptimal performance for other types. * bpo-26680: Adds Rational.is_integer which returns True if the denominator is one. This implementation assumes the Rational is represented in it's lowest form, as required by the class docstring. * bpo-26680: Adds Integral.is_integer which always returns True. * bpo-26680: Adds tests for Fraction.is_integer called as an instance method. The tests for the Rational abstract base class use an unbound method to sidestep the inability to directly instantiate Rational. These tests check that everything works correct as an instance method. * bpo-26680: Updates documentation for Real.is_integer and built-ins int and float. The call x.is_integer() is now listed in the table of operations which apply to all numeric types except complex, with a reference to the full documentation for Real.is_integer(). Mention of is_integer() has been removed from the section 'Additional Methods on Float'. The documentation for Real.is_integer() describes its purpose, and mentions that it should be overridden for performance reasons, or to handle special values like NaN. * bpo-26680: Adds Decimal.is_integer to the Python and C implementations. The C implementation of Decimal already implements and uses mpd_isinteger internally, we just expose the existing function to Python. The Python implementation uses internal conversion to integer using to_integral_value(). In both cases, the corresponding context methods are also implemented. Tests and documentation are included. * bpo-26680: Updates the ACKS file. * bpo-26680: NEWS entries for int, the numeric ABCs and Decimal. Co-authored-by: Robert Smallshire <rob@sixty-north.com>
Diffstat (limited to 'Lib/test/decimaltestdata/extra.decTest')
-rw-r--r--Lib/test/decimaltestdata/extra.decTest18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/decimaltestdata/extra.decTest b/Lib/test/decimaltestdata/extra.decTest
index b630d8e..2f0719e 100644
--- a/Lib/test/decimaltestdata/extra.decTest
+++ b/Lib/test/decimaltestdata/extra.decTest
@@ -2346,6 +2346,24 @@ bool2096 iszero sNaN -> 0
bool2097 iszero -sNaN -> 0
bool2098 iszero sNaN123 -> 0
bool2099 iszero -sNaN123 -> 0
+bool2100 is_integer -1.0 -> 1
+bool2101 is_integer 0.0 -> 1
+bool2102 is_integer 1.0 -> 1
+bool2103 is_integer 42 -> 1
+bool2104 is_integer 1e2 -> 1
+bool2105 is_integer 1.5 -> 0
+bool2106 is_integer 1e-2 -> 0
+bool2107 is_integer NaN -> 0
+bool2109 is_integer -NaN -> 0
+bool2110 is_integer NaN123 -> 0
+bool2111 is_integer -NaN123 -> 0
+bool2112 is_integer sNaN -> 0
+bool2113 is_integer -sNaN -> 0
+bool2114 is_integer sNaN123 -> 0
+bool2115 is_integer -sNaN123 -> 0
+bool2116 is_integer Infinity -> 0
+bool2117 is_integer -Infinity -> 0
+
------------------------------------------------------------------------
-- The following tests (pwmx0 through pwmx440) are for the --