be
This commit is contained in:
25
Utils.cs
Normal file
25
Utils.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
namespace Prac7Meow
|
||||
{
|
||||
internal class Utils
|
||||
{
|
||||
public static int NearPow(int n)
|
||||
{
|
||||
if (n == 0) return 0;
|
||||
if (n <= 2) return 2;
|
||||
|
||||
uint val = (uint)n;
|
||||
|
||||
val--;
|
||||
val |= val >> 1;
|
||||
val |= val >> 2;
|
||||
val |= val >> 4;
|
||||
val |= val >> 8;
|
||||
val |= val >> 16;
|
||||
val++;
|
||||
|
||||
if (val == 0) throw new OverflowException("Requested capacity is too large for int.");
|
||||
|
||||
return (int)val;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user