ignite-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anton Vinogradov <avinogra...@gridgain.com>
Subject Re: Bug in method
Date Thu, 27 Jul 2017 15:36:19 GMT
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 <
biryukovvitaliy92@gmail.com> 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
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message