int/long unification hides bugs

Josiah Carlson jcarlson at uci.edu
Sat Oct 30 04:42:59 EDT 2004


tweedgeezer at hotmail.com (Jeremy Fincher) wrote:
> 
> Andrew Dalke <adalke at mindspring.com> wrote in message news:
> > What's wrong with the example Number wrapper I posted a couple days
> > ago to this thread?
> 
> How long with this take to run?
> 
> >>> a = RangedNumber(2**31, 0, 2**32)
> >>> a ** a

Considering that 2**31 is already a long int, you wouldn't get the
overflow error that is being argued about anyways.  You would eventually
get a MemoryError though, as the answer is, quite literally, 2**(31 +
2**31).

Certainly if one were to implement the standard binary exponentiation
algorithm in Python, it fails quite early due to violating the range
constraint.


> I think our inability to write a RangedNumber that piggybacks on
> Python's integers should be obvious.

I don't quite follow what you mean.  The provided RangedNumber uses
Python integers to store information as attributes of the RangedNumber
instances.


 - Josiah




More information about the Python-list mailing list