Message217795
| Author |
josh.r |
| Recipients |
josh.r, pitrou, vstinner |
| Date |
2014年05月02日.21:16:54 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1399065415.15.0.865384168051.issue21419@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
While you're doing this, might it make sense to add a special case to long_pow so it identifies cases where a (digit-sized) value with an absolute value equal to a power of 2 is being raised to a positive integer exponent, and convert said cases to equivalent left shifts?
Identifying powers of 2 can be done in constant time with no memory overhead for register sized values (see http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2 ); if you've already handled the case for 0, then checking if it's a power of 2 is just:
(v & (v - 1)) == 0
It adds a little complexity, but even just handling 2 alone specially would at least make it so the semi-common case of making a large power of 2 doesn't have significantly different performance using 2 ** (numbits - 1) instead of 1 << (numbits - 1). |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2014年05月02日 21:16:55 | josh.r | set | recipients:
+ josh.r, pitrou, vstinner |
| 2014年05月02日 21:16:55 | josh.r | set | messageid: <1399065415.15.0.865384168051.issue21419@psf.upfronthosting.co.za> |
| 2014年05月02日 21:16:55 | josh.r | link | issue21419 messages |
| 2014年05月02日 21:16:54 | josh.r | create |
|