(original) (raw)

As requested on the bug tracker, I've submitted a pull request for is\_integer() support on the other numeric types. https://github.com/python/cpython/pull/6121

These are the tactics I used to implement it:

- float: is\_integer() already exists, so no changes

- int: return True

- Real: return x == int(x). Although Real doesn't explicitly support conversation to int with \_\_int\_\_, it does support conversion to int with \_\_trunc\_\_. The int constructor falls back to using \_\_trunc\_\_.

- Rational (also inherited by Fraction): return x.denominator == 1 as Rational requires that all numbers must be represented in lowest form.

- Integral: return True

- Decimal: expose the existing dec\_mpd\_isinteger C function to Python as is\_integer()