in reply to Re: reliable get position of leftmost bit in large integers
in thread reliable get position of leftmost bit in large integers
Works perfect. I only changed the testing-lines for better visability:
for (map 1 << $_, 0 .. 63) { print sprintf("%b", $_- 1 )," : ", sprintf("%b",nextPowerOfTwo( $_- +1 )); } $ perl leftmost_bit.pl 0 : 0 1 : 1 11 : 100 111 : 1000 1111 : 10000 ...
Maybe it's fast enough versus log(),division,log() if inlined. But I am only prototyping the pure Perl version for a C implementation. But it would be nice to have pure Perl as a fallback.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: reliable get position of leftmost bit in large integers
by BrowserUk (Patriarch) on Mar 12, 2015 at 13:13 UTC | |
by wollmers (Scribe) on Mar 12, 2015 at 14:54 UTC |