From 0725468f2cb8de7f81fe5602f37f5a6ce6c45cfd Mon Sep 17 00:00:00 2001 From: Syntriax Date: Thu, 1 Feb 2024 12:58:51 +0300 Subject: [PATCH] feat: Math.AbsMax & AbsMin --- Engine.Core/Math.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Engine.Core/Math.cs b/Engine.Core/Math.cs index 5d203db..cb7f4b8 100644 --- a/Engine.Core/Math.cs +++ b/Engine.Core/Math.cs @@ -129,7 +129,13 @@ public static class Math /// The first number. /// The second number. /// The number whose absolute value is larger. - public static float MaxMagnitude(float x, float y) => MathF.MaxMagnitude(x, y); + public static T AbsMax(T x, T y) where T : INumber + { + T xAbs = Abs(x); + T yAbs = Abs(y); + + return (xAbs > yAbs) ? x : y; + } /// /// Returns the smaller of two numbers. @@ -146,7 +152,13 @@ public static class Math /// The first number. /// The second number. /// The number whose absolute value is smaller. - public static float MinMagnitude(float x, float y) => MathF.MinMagnitude(x, y); + public static T AbsMin(T x, T y) where T : INumber + { + T xAbs = Abs(x); + T yAbs = Abs(y); + + return (xAbs < yAbs) ? x : y; + } /// /// Returns a specified number raised to the specified power.