[Python-3000] Updated and simplified PEP 3141: A Type Hierarchyfor Numbers

Terry Reedy tjreedy at udel.edu
Fri Aug 3 01:01:39 CEST 2007


"Jeffrey Yasskin" <jyasskin at gmail.com> wrote in message 
news:5d44f72f0708021153u7ea1f443jfdee3c167b011011 at mail.gmail.com...

|        def __bool__(self):
|            """True if self != 0."""
|            return self != 0

Could this be a Number rather than Complex method?
---------------

| There is no built-in rational type

Floats constitute a bit-size bounded (like ints) set of rationals with 
denominators restricted to powers of two.  Decimal literals and Decimals 
constitute a memory bounded (like longs) set of rationals with denominators 
instead restricted to powers of ten.  I suspect that if both were presented 
as such, new programmers would be less likely to ask if
>>> 1.1
1.1000000000000001
is a bug in Python.

Math.frexp returns a disguised form of (numerator,denominator) (without 
common factor of two removal).  If undisguised functions were added (and 
the same for Decimal), there would be no need, really, for class Real.

If such were done, a .num_denom() method either supplementing or replacing 
.numerator() and .denominator() and returning (num, denom) would have the 
same efficiency justification of int.divmod.

I would like to see a conforming Rat.py class with unrestricted 
denominators.
--------------------

| And finally integers::
|
|    class Integral(Rational):
|        """Integral adds a conversion to int and the bit-string 
operations."""

The bit-string operations are not 'integer' operations.  Rather they are 
'integers represented as powers of two' operations.  While << and >> can be 
interpreted (and implemented) as * and //, the other four are genernally 
meaningless for other representations, such as prime factorization or 
fibonacci base.  The Lib Ref agrees:
   3.4.1 Bit-string Operations on Integer Types
   Plain and long integer types support additional operations that make 
sense
   only for bit-strings
Other integer types should not have to support them to call themselves 
Integral.  So I think at least |, ^, &, and ~ should be removed from 
Integral and put in a subclass thereof.  Possible names are Pow2Int or 
BitStringInt or BitIntegral.
-----------

In short, having read up to the beginning of Exact vs. Inexact Classes, my 
suggestion is to delete the unrealizable 'real' class and add an easily 
realizable non-bit-string integer class.

Terry Jan Reedy





More information about the Python-3000 mailing list