next power of 2

2012-10-06 Thread ref2401
is there any Phobos function to calculate the next power of 2 of the specified number?

Re: next power of 2

2012-10-06 Thread Andrei Alexandrescu
On 10/6/12 4:48 PM, ref2401 wrote: is there any Phobos function to calculate the next power of 2 of the specified number? Use 1U bsr(x). http://dlang.org/phobos/core_bitop.html#bsr Andrei

Re: next power of 2

2012-10-06 Thread Dmitry Olshansky
On 07-Oct-12 00:48, ref2401 wrote: is there any Phobos function to calculate the next power of 2 of the specified number? No though it's reinvented in a couple of places I think. Anyway this should work for unsigned numbers: import core.bitop; T nextPow2(T)(T x){ return x == 0 ? 1

Re: next power of 2

2012-10-06 Thread Dmitry Olshansky
On 07-Oct-12 00:54, Dmitry Olshansky wrote: On 07-Oct-12 00:48, ref2401 wrote: is there any Phobos function to calculate the next power of 2 of the specified number? No though it's reinvented in a couple of places I think. Anyway this should work for unsigned numbers: import core.bitop; T

Re: next power of 2

2012-10-06 Thread Andrei Alexandrescu
On 10/6/12 4:57 PM, Dmitry Olshansky wrote: On 07-Oct-12 00:54, Dmitry Olshansky wrote: On 07-Oct-12 00:48, ref2401 wrote: is there any Phobos function to calculate the next power of 2 of the specified number? No though it's reinvented in a couple of places I think. Anyway this should work

Re: next power of 2

2012-10-06 Thread Andrei Alexandrescu
On 10/6/12 4:54 PM, Dmitry Olshansky wrote: On 07-Oct-12 00:48, ref2401 wrote: is there any Phobos function to calculate the next power of 2 of the specified number? No though it's reinvented in a couple of places I think. Anyway this should work for unsigned numbers: import core.bitop; T

Re: next power of 2

2012-10-06 Thread Dmitry Olshansky
On 07-Oct-12 00:58, Andrei Alexandrescu wrote: On 10/6/12 4:57 PM, Dmitry Olshansky wrote: On 07-Oct-12 00:54, Dmitry Olshansky wrote: On 07-Oct-12 00:48, ref2401 wrote: is there any Phobos function to calculate the next power of 2 of the specified number? No though it's reinvented