Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Re (tilly) 1: Power of two round up.

by japhy (Canon)
on Dec 15, 2000 at 23:31 UTC ( #46896=note: print w/replies, xml ) Need Help??

in reply to Re (tilly) 1: Power of two round up.
in thread Power of two round up.

And an even faster WTDI:
sub next_pwr { my ($x,$p) = (@_,2); # default to next_pwr(X,2) my $log = log($x)/log($p); $log = int($log+1) if $log != int($log); return $p**$log; }
You can even add a log() memoization in there:
{ my %LOG = (2 => log(2)); # most common sub next_pwr { my ($x,$p) = (@_,2); # default to next_pwr(X,2) # assertions, etc. die "illegal base: $p" if $p < 2; return 1 if $x == 1; $p = int $p; my $log = ($LOG{$x} ||= log($x)) / ($LOG{$p} ||= log($p)); $log = int($log+1) if $log != int($log); return $p ** $log; } }

japhy -- Perl and Regex Hacker

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://46896]
[Discipulus]: 'unless it rains' => 'a meno che NON piova'
erix is always in favour of code-revolutions
[Lady_Aleena]: Well, right now, I"m looking at modules where I put randomness that aren't in my RolePlaying/Random dir, like RolePlaying:: Character:: Alignment that is mostly about random_alignment than expand_alignment.
[erix]: cute

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2017-05-27 20:32 GMT
Find Nodes?
    Voting Booth?