Vitaliy,

Let's file an issue and solve it :)
Don't forget to add tests.

On Thu, Jul 27, 2017 at 5:24 PM, Vitaliy Biryukov <
[email protected]> wrote:

> Hi, igniters!
>
> I noticed that the method "IgniteUtils.ceilPow2" can overflow for values
> greater than 2^30 and return Integer.MIN_VALUE for them.
>
> Maybe this check was skipped  for method speed. In this case, we need to
> add information about this into javaDoc.
>
> Current implementation:
>
> public static int ceilPow2(int v) {
>     return Integer.highestOneBit(v - 1) << 1;
> }
>
>
> It can be fixed like this:
> bit impl:
>
> int i = v - 1;
>
> return Integer.highestOneBit(i) << 1 - (i >>> 30 ^ v >> 31);
>
> more readable impl:
>
> if (v == Integer.MIN_VALUE)
>     return 0;
>
> int pow30 = 1 << 30;
>
> return v >= pow30 ? pow30 : Integer.highestOneBit(v - 1) << 1;
>
>
> What do you think? Sould I create  ticket with PR?
>
> --
> Best Regards,
> Vitaliy Biryukov
>
  • Bug in method Vitaliy Biryukov
    • Re: Bug in method Anton Vinogradov

Reply via email to