I might try table lookup.
sub is_power_of_2 { my $n = shift; 1 == grep { $_ == $n } ( 1 2 4 8 ... ) }
In reply to Re: How can I tell if a number is a power of 2?
by dws
in thread How can I tell if a number is a power of 2?
by larryk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |