Init Scripts in new repo
This commit is contained in:
53
Math/Math.cs
Normal file
53
Math/Math.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace SJK.Math;
|
||||
|
||||
public static class SJKMath
|
||||
{
|
||||
public static T Max<T>(params T[] values) where T : INumber<T>
|
||||
{
|
||||
if (values.Length == 0)
|
||||
throw new ArgumentException($"No values provided");
|
||||
T max = values[0];
|
||||
foreach (var item in values.Skip(1))
|
||||
{
|
||||
max = T.Max(item, max);
|
||||
}
|
||||
return max;
|
||||
}
|
||||
public static T Min<T>(params T[] values) where T : INumber<T>
|
||||
{
|
||||
if (values.Length == 0)
|
||||
throw new ArgumentException($"No values provided");
|
||||
T max = values[0];
|
||||
foreach (var item in values.Skip(1))
|
||||
{
|
||||
max = T.Min(item, max);
|
||||
}
|
||||
return max;
|
||||
}
|
||||
public static long UpperPowerOfTwo(long v)
|
||||
{
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
v |= v >> 16;
|
||||
v++;
|
||||
return v;
|
||||
|
||||
}
|
||||
public static int UpperPowerOfTwo(int v)
|
||||
{
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
v |= v >> 16;
|
||||
v++;
|
||||
return v;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user