On 8/7/06, Simon Kr÷šer <SimonKroeger / gmx.de> wrote:
> Rick DeNatale wrote:

> > My original intention was to benchmark the various suggestions, but
> > since you can get the wrong answers with arbitrarily fast code, I
> > don't think that it matters much.
>
> Hmm, what about:
>
> def next_power_of_2(n)
>   throw 'eeek' if n < 0
>   return 1 if n < 2
>   1 << (n-1).to_s(2).size
> end
>
> ?

Ahh, but the following is both quicker and more economical of source code

  def next_power_of_2(n)
  end

If you don't care about a correct answer, then nil is as good as any. <G>

-- 
Rick DeNatale

IPMS/USA Region 12 Coordinator
http://ipmsr12.denhaven2.com/

Visit the Project Mercury Wiki Site
http://www.mercuryspacecraft.com/