On Mon, Feb 12, 2018 at 09:27:07AM +0100, Alexandre Derumier wrote:
> +sub round_powerof2 {

Please just use:
    return 1 if $_[0] < 2;
    return 2 << int(log($_[0]-1)/log(2));


> + local $_ = (shift)-1;
> + my $num = (2**int(log($_)/log(2)))-1;
> + return ++($_ |= $num);
This ties knots into my brain when reading it.
This gets a power of two less than or equal to our number (eg for
numbers 8 through 15 we get 8), then decrement to set all lower bits 1
(=> 7) which is then bitor-ed into our original number producing 15
which is then incremented to 16. However, on '8' we actually want to
stick with 8 ;-) iow. if we already have a power of two, don't double
it.

_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to