-
Notifications
You must be signed in to change notification settings - Fork 0
Mathf Extensions Utility
Andrzej Kebab edited this page Feb 4, 2024
·
2 revisions
The MathfExtensions class in the UtilityLibrary.Unity.Runtime namespace provides extension methods for finding the minimum and maximum values for various numeric types. The class includes methods for byte, short, long, half (if ENABLED_UNITY_MATHEMATICS is defined), decimal, and double. These methods allow finding the minimum and maximum values among multiple values or between two values.
-
Min(byte a, byte b): Returns the smaller of two
bytevalues. -
Min(params byte[] values): Returns the smallest value among an array of
bytevalues. -
Min(short a, short b): Returns the smaller of two
shortvalues. -
Min(params short[] values): Returns the smallest value among an array of
shortvalues. -
Min(long a, long b): Returns the smaller of two
longvalues. -
Min(params long[] values): Returns the smallest value among an array of
longvalues. -
Min(half a, half b): Returns the smaller of two
halfvalues (ifENABLED_UNITY_MATHEMATICSis defined). -
Min(params half[] values): Returns the smallest value among an array of
halfvalues (ifENABLED_UNITY_MATHEMATICSis defined). -
Min(decimal a, decimal b): Returns the smaller of two
decimalvalues. -
Min(params decimal[] values): Returns the smallest value among an array of
decimalvalues. -
Min(double a, double b): Returns the smaller of two
doublevalues. -
Min(params double[] values): Returns the smallest value among an array of
doublevalues.
-
Max(byte a, byte b): Returns the larger of two
bytevalues. -
Max(params byte[] values): Returns the largest value among an array of
bytevalues. -
Max(short a, short b): Returns the larger of two
shortvalues. -
Max(params short[] values): Returns the largest value among an array of
shortvalues. -
Max(long a, long b): Returns the larger of two
longvalues. -
Max(params long[] values): Returns the largest value among an array of
longvalues. -
Max(half a, half b): Returns the larger of two
halfvalues (ifENABLED_UNITY_MATHEMATICSis defined). -
Max(params half[] values): Returns the largest value among an array of
halfvalues (ifENABLED_UNITY_MATHEMATICSis defined). -
Max(decimal a, decimal b): Returns the larger of two
decimalvalues. -
Max(params decimal[] values): Returns the largest value among an array of
decimalvalues. -
Max(double a, double b): Returns the larger of two
doublevalues. -
Max(params double[] values): Returns the largest value among an array of
doublevalues.
using UtilityLibrary.Unity.Runtime;
public class MathfExtensionsExample : MonoBehaviour
{
void Start()
{
byte minValue = MathfExtensions.Min((byte)5, (byte)10, (byte)3);
byte maxValue = MathfExtensions.Max((byte)5, (byte)10, (byte)3);
short minValueShort = MathfExtensions.Min((short)5, (short)10, (short)3);
short maxValueShort = MathfExtensions.Max((short)5, (short)10, (short)3);
long minValueLong = MathfExtensions.Min(5L, 10L, 3L);
long maxValueLong = MathfExtensions.Max(5L, 10L, 3L);
// etc...
}
}This utility class simplifies finding the minimum and maximum values for various numeric types, providing concise and readable code.