ignite-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vitaliy Biryukov <biryukovvitali...@gmail.com>
Subject Bug in method
Date Thu, 27 Jul 2017 14:24:18 GMT
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