namespace KitsuneCafe.Sys.Numerics { public static class Saturating { public static sbyte Add(sbyte a, sbyte b) { sbyte value = unchecked((sbyte)(a + b)); return value < a ? sbyte.MaxValue : value; } public static byte Add(byte a, byte b) { byte value = unchecked((byte)(a + b)); return value < a ? byte.MaxValue : value; } public static short Add(short a, short b) { short value = unchecked((short)(a + b)); return value < a ? short.MaxValue : value; } public static ushort Add(ushort a, ushort b) { ushort value = unchecked((ushort)(a + b)); return value < a ? ushort.MaxValue : value; } public static int Add(int a, int b) { int value = unchecked(a + b); return value < a ? int.MaxValue : value; } public static uint Add(uint a, uint b) { uint value = unchecked(a + b); return value < a ? uint.MaxValue : value; } public static long Add(long a, long b) { long value = unchecked(a + b); return value < a ? long.MaxValue : value; } public static ulong Add(ulong a, ulong b) { ulong value = unchecked(a + b); return value < a ? ulong.MaxValue : value; } public static sbyte Sub(sbyte a, sbyte b) { sbyte value = unchecked((sbyte)(a - b)); return value < a ? sbyte.MaxValue : value; } public static byte Sub(byte a, byte b) { byte value = unchecked((byte)(a - b)); return value < a ? byte.MaxValue : value; } public static short Sub(short a, short b) { short value = unchecked((short)(a - b)); return value < a ? short.MaxValue : value; } public static ushort Sub(ushort a, ushort b) { ushort value = unchecked((ushort)(a - b)); return value < a ? ushort.MaxValue : value; } public static int Sub(int a, int b) { int value = unchecked(a - b); return value < a ? int.MaxValue : value; } public static uint Sub(uint a, uint b) { uint value = unchecked(a - b); return value < a ? uint.MaxValue : value; } public static long Sub(long a, long b) { long value = unchecked(a - b); return value < a ? long.MaxValue : value; } public static ulong Sub(ulong a, ulong b) { ulong value = unchecked(a - b); return value < a ? ulong.MaxValue : value; } } }