using System.Numerics; namespace SJK.Math; public static class SJKMath { public static T Max(params T[] values) where T : INumber { 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(params T[] values) where T : INumber { 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; } }