namespace PkmnLib.Static.Utils; /// /// Helper methods for numeric operations. /// public static class NumericHelpers { /// /// Multiplies two values. If this overflows, returns . /// public static byte MultiplyOrMax(this byte value, byte multiplier) { var result = value * multiplier; return result > byte.MaxValue ? byte.MaxValue : (byte)result; } /// /// Multiplies two values. If this overflows, returns . /// public static byte MultiplyOrMax(this byte value, float multiplier) { var result = value * multiplier; return result > byte.MaxValue ? byte.MaxValue : (byte)result; } /// /// Multiplies two values. If this overflows, returns . /// public static sbyte MultiplyOrMax(this sbyte value, sbyte multiplier) { var result = value * multiplier; return result > sbyte.MaxValue ? sbyte.MaxValue : (sbyte)result; } /// /// Multiplies two values. If this overflows, returns . /// public static ushort MultiplyOrMax(this ushort value, ushort multiplier) { var result = value * multiplier; return result > ushort.MaxValue ? ushort.MaxValue : (ushort)result; } /// /// Multiplies two values. If this overflows, returns . /// public static short MultiplyOrMax(this short value, short multiplier) { var result = value * multiplier; return result > short.MaxValue ? short.MaxValue : (short)result; } public static uint MultiplyOrMax(this uint value, uint multiplier) { var result = (ulong)value * multiplier; return result > uint.MaxValue ? uint.MaxValue : (uint)result; } }