Message105593
Thank you both for the valuable feedback. I'm working on a revised patch that incorporates your many suggestions.
I decided to use an iterative version for two reasons:
- the reference has a note at the bottom in a tiny font suggesting it
- I found it counter-intuitive to implement product() as a recursive function. I had a much easier time matching the code up with the formula when it was implemented iteratively.
I agree that my use of log2() was an ugly hack. ;-) I'll fix that.
Would it be worthwhile to create a pybits.h and .c that defines _Py_FindLastSetBit and _Py_CountSetBits? (with appropriate logic in the .h and configure.in to use system/compiler versions if available)
There are already two implementations of find-last-set-bit in Python:
bits_in_digit() in Objects/longobject.c and hi0bits() in Python/dtoa.c. It would be nice to consolidate them.
(hi0bits counts the leading 0 bits which is a trivial transformation of finding the highest set bit)
I don't know of anyplace else in Python that needs count-set-bits. |
|
Date |
User |
Action |
Args |
2010-05-12 15:36:37 | stutzbach | set | recipients:
+ stutzbach, rhettinger, mark.dickinson, belopolsky, draghuram |
2010-05-12 15:36:37 | stutzbach | set | messageid: <1273678597.41.0.607321997508.issue8692@psf.upfronthosting.co.za> |
2010-05-12 15:36:36 | stutzbach | link | issue8692 messages |
2010-05-12 15:36:34 | stutzbach | create | |
|