[Python-3000] What is numbers.Integral used for?
Guido van Rossum
guido at python.org
Tue Feb 12 04:13:40 CET 2008
On Feb 11, 2008 6:58 PM, Raymond Hettinger <python at rcn.com> wrote:
> During the discussion of PEP 3141, what use cases were envisioned for the Integral type? Were there some examples of concrete implementations other than <type 'int'> or <type 'long'??
I believe numpy defines a whole slew of these of different sizes.
> I'm asking because I'm unclear about what a class is stating about itself when it registers as Integral. I'm not sure that most finite fields would fit into the structure since they all Integrals support logical operations, are convertible into ints via __index__, andy the must support all of the operations defined for Reals.
An earlier version of the PEP talked about fields and all sort of
stuff, but we found nobody cared.
> I looked at the reference for Scheme's numeric tower to find guidance, but it seemed that the notion expressed solely through the "integer?" predicate which behaves differently than our inheritance tower. For example, the spec says (rational? 6/10) ==> #t and (integer? 8/4) ==> #t but in our current implementation Rational(8,4) is not Integral like it is for Scheme.
> Also, Scheme seems apply implement the notions of Exact/Inexact much differently
> than we do: "A number is exact if it was written as an exact constant or was derived from exact numbers using only exact operations." So, while all integers are exact, some floats and decimal constants could also be exact. This matches how exactness is used in the decimal module -- all constants start as exact and operations can return either exact or inexact (and the module signals when this occurs). Our module says Integrals are Exact and makes no further assertions.
I expect that there are separate useful notions of exactness and
inexactness, one solely based on the type, and one based on value.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000