how to get the thighest bit position in big integers?

Terry Reedy tjreedy at udel.edu
Wed Oct 8 13:58:42 EDT 2008


MRAB wrote:
> On Oct 8, 9:56 am, Mark Dickinson <dicki... at gmail.com> wrote:
>> On Oct 7, 5:19 pm, mmgar... at gmx.de wrote:
>>
>>> but I want to make clear that I think that (0).numbits()==-1
>>> is the natural solution. At least for all square-and-multiply-like
>>> algorithms needed in [...]
>> Can you clarify this?  Why is -1 the natural solution? I
>> can see a case for 0, for -infinity (whatever that means),
>> or for raising an exception, but I can't see why -1 would
>> be at all useful or natural.
>>
> [snip]
> Compare it with, say, str.find, which returns the position if found
> (>=0) or -1 if not found.

str.find is an historical anomaly that should not be copied.  It 
was(is?) a wrapper for C's string find function.  C routinely uses -1 to 
mean None for functions statically typed to return ints.  The Python 
version logically should return None and usually does for other functions.




More information about the Python-list mailing list