Init Scripts in new repo

This commit is contained in:
2026-04-04 13:18:04 -04:00
commit d988008613
26 changed files with 1497 additions and 0 deletions

53
Math/Math.cs Normal file
View 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;
}
}