init commit
This commit is contained in:
151
output/Libraries/AForge.Math/AForge/Math/Tools.cs
Normal file
151
output/Libraries/AForge.Math/AForge/Math/Tools.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
namespace AForge.Math;
|
||||
|
||||
public static class Tools
|
||||
{
|
||||
public static int Pow2(int power)
|
||||
{
|
||||
if (power < 0 || power > 30)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 1 << power;
|
||||
}
|
||||
|
||||
public static bool IsPowerOf2(int x)
|
||||
{
|
||||
if (x <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return (x & (x - 1)) == 0;
|
||||
}
|
||||
|
||||
public static int Log2(int x)
|
||||
{
|
||||
if (x <= 65536)
|
||||
{
|
||||
if (x <= 256)
|
||||
{
|
||||
if (x <= 16)
|
||||
{
|
||||
if (x <= 4)
|
||||
{
|
||||
if (x <= 2)
|
||||
{
|
||||
if (x <= 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
if (x <= 8)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
return 4;
|
||||
}
|
||||
if (x <= 64)
|
||||
{
|
||||
if (x <= 32)
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
return 6;
|
||||
}
|
||||
if (x <= 128)
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
return 8;
|
||||
}
|
||||
if (x <= 4096)
|
||||
{
|
||||
if (x <= 1024)
|
||||
{
|
||||
if (x <= 512)
|
||||
{
|
||||
return 9;
|
||||
}
|
||||
return 10;
|
||||
}
|
||||
if (x <= 2048)
|
||||
{
|
||||
return 11;
|
||||
}
|
||||
return 12;
|
||||
}
|
||||
if (x <= 16384)
|
||||
{
|
||||
if (x <= 8192)
|
||||
{
|
||||
return 13;
|
||||
}
|
||||
return 14;
|
||||
}
|
||||
if (x <= 32768)
|
||||
{
|
||||
return 15;
|
||||
}
|
||||
return 16;
|
||||
}
|
||||
if (x <= 16777216)
|
||||
{
|
||||
if (x <= 1048576)
|
||||
{
|
||||
if (x <= 262144)
|
||||
{
|
||||
if (x <= 131072)
|
||||
{
|
||||
return 17;
|
||||
}
|
||||
return 18;
|
||||
}
|
||||
if (x <= 524288)
|
||||
{
|
||||
return 19;
|
||||
}
|
||||
return 20;
|
||||
}
|
||||
if (x <= 4194304)
|
||||
{
|
||||
if (x <= 2097152)
|
||||
{
|
||||
return 21;
|
||||
}
|
||||
return 22;
|
||||
}
|
||||
if (x <= 8388608)
|
||||
{
|
||||
return 23;
|
||||
}
|
||||
return 24;
|
||||
}
|
||||
if (x <= 268435456)
|
||||
{
|
||||
if (x <= 67108864)
|
||||
{
|
||||
if (x <= 33554432)
|
||||
{
|
||||
return 25;
|
||||
}
|
||||
return 26;
|
||||
}
|
||||
if (x <= 134217728)
|
||||
{
|
||||
return 27;
|
||||
}
|
||||
return 28;
|
||||
}
|
||||
if (x <= 1073741824)
|
||||
{
|
||||
if (x <= 536870912)
|
||||
{
|
||||
return 29;
|
||||
}
|
||||
return 30;
|
||||
}
|
||||
return 31;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user