Re: Off topic 'C' question - Mailing list pgsql-hackers

From Louis-David Mitterrand
Subject Re: Off topic 'C' question
Date
Msg-id 20000811231823.A3877@styx
Whole thread Raw
In response to Off topic 'C' question  (Mike Mascari <mascarm@mascari.com>)
Responses Re: Re: Off topic 'C' question  (Louis-David Mitterrand <cunctator@apartia.ch>)
List pgsql-hackers
On Sat, Jul 29, 2000 at 09:38:33PM -0400, Mike Mascari wrote:
> I have a quick question. What is the quickest way to determine
> the next highest power of two which is greater than a given
> integer in 'C'. For example, given the number 7, I would like to
> return 8. Given the number 13, I would like to return 16, etc. Is
> there a gem to do this without shifting a bit value from 1 left
> up to a maximum of 32 (or 64) iterations? 

You could use:

pow(x, ((int)(log(x)/log(2)) + 1));

-- 
Louis-David Mitterrand - ldm@apartia.org - http://www.apartia.org
"Poor girl looks as confused as a blind lesbian in a fish market." -Simon R. Green 


pgsql-hackers by date:

Previous
From: Andrew Selle
Date:
Subject: Returning null from Userdefined C function
Next
From: Tom Lane
Date:
Subject: Re: Returning null from Userdefined C function