More abilities
This commit is contained in:
@@ -82,4 +82,22 @@ public static class NumericHelpers
|
||||
var result = value * multiplier;
|
||||
return result > uint.MaxValue ? uint.MaxValue : (uint)result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies two values. If this overflows, returns <see cref="uint.MaxValue"/>.
|
||||
/// </summary>
|
||||
public static int MultiplyOrMax(this int value, int multiplier)
|
||||
{
|
||||
var result = (long)value * multiplier;
|
||||
return result > int.MaxValue ? int.MaxValue : (int)result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies two values. If this overflows, returns <see cref="uint.MaxValue"/>.
|
||||
/// </summary>
|
||||
public static int MultiplyOrMax(this int value, float multiplier)
|
||||
{
|
||||
var result = value * multiplier;
|
||||
return result > int.MaxValue ? int.MaxValue : (int)result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user