More abilities

This commit is contained in:
2025-06-15 13:20:58 +02:00
parent ec8681eaa9
commit cd6095455a
21 changed files with 251 additions and 29 deletions

View File

@@ -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;
}
}