This commit is contained in:
@@ -20,6 +20,18 @@ public static class NumericHelpers
|
||||
return result > byte.MaxValue ? byte.MaxValue : (byte)result;
|
||||
}
|
||||
|
||||
public static byte AddOrMax(this byte value, byte addend)
|
||||
{
|
||||
var result = value + addend;
|
||||
return result > byte.MaxValue ? byte.MaxValue : (byte)result;
|
||||
}
|
||||
|
||||
public static byte SubtractOrMin(this byte value, byte subtrahend)
|
||||
{
|
||||
var result = value - subtrahend;
|
||||
return result < 0 ? (byte)0 : (byte)result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies two values. If this overflows, returns <see cref="byte.MaxValue"/>.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user