feat: Math.AbsMax & AbsMin

This commit is contained in:
Syntriax 2024-02-01 12:58:51 +03:00
parent 5826230e7a
commit 0725468f2c
1 changed files with 14 additions and 2 deletions

View File

@ -129,7 +129,13 @@ public static class Math
/// <param name="x">The first number.</param>
/// <param name="y">The second number.</param>
/// <returns>The number whose absolute value is larger.</returns>
public static float MaxMagnitude(float x, float y) => MathF.MaxMagnitude(x, y);
public static T AbsMax<T>(T x, T y) where T : INumber<T>
{
T xAbs = Abs(x);
T yAbs = Abs(y);
return (xAbs > yAbs) ? x : y;
}
/// <summary>
/// Returns the smaller of two numbers.
@ -146,7 +152,13 @@ public static class Math
/// <param name="x">The first number.</param>
/// <param name="y">The second number.</param>
/// <returns>The number whose absolute value is smaller.</returns>
public static float MinMagnitude(float x, float y) => MathF.MinMagnitude(x, y);
public static T AbsMin<T>(T x, T y) where T : INumber<T>
{
T xAbs = Abs(x);
T yAbs = Abs(y);
return (xAbs < yAbs) ? x : y;
}
/// <summary>
/// Returns a specified number raised to the specified power.