bitsize?

Tim Peters tim_one at email.msn.com
Fri Mar 17 07:24:04 CET 2000


[posted & mailed]

[David C. Ullrich]
> ...
> It would be nice if there was a builtin "bitsize" function
> returning the number of bits in a long value. (Ie ceil(log_2(n)),
> more or less).

Yes, it would.  I obtained provisional permission from Guido to trying
adding this as a method on longs (the function is too specialized to justify
polluting the builtins).  Never did the work, though.  On two previous
occasions this came up, two other people volunteered to add this (along with
some other methods on longs), but soon after vanished from the face of
Python's version of Earth.  So the only rational conclusion is that this
idea is cursed!  I may try it again someday -- but need to locate a
reputable exorcist first.

>     A few bugs (features?) in real.py have got me to doing
> a few numeric things using longs. A person really does
> need bitsize() to get an appropriate "initial guess"
> for lots of algorithms. The bitsize function in real.py is
> a magnificent hack,

Yes, actually due to Christian Tismer.

> but it really shouldn't be needed -

Definitely not -- it takes O(log2(N)) time now but should be O(1).  This
screws up the timing behavior for many long-int algorithms.

> something inside Python knows how many bits the long
> is taking, and I don't see what harm it could do to expose
> this information. It's not like I want the address or anything...

Heh heh -- getting the address is easy now.

>     (Speaking of addresses: Does anyone know a valid one
> for Jurjen N.E. Bos, the author of real.py? I have a few that
> don't work if you want to trade.)

Nope.  I had snail-mailed some papers on the constructive reals to him when
he was writing real.py, and we corresponded about it over some number of
months.  Then he vanished!  It's a conspiracy all right, but its nefarious
goals remain clouded.

BTW, Hans Boehm recently (within the last year) ported his version of
infinite-precision reals to Java, and that's available somewhere on the SGI
web site.  "One of these days" I hope to port that to Python.

everyone-please-hold-their-breath-ly y'rs  - tim






More information about the Python-list mailing list