// - edit Vector.numerics.tt to modify #nullable enable namespace Brutal.Numerics; // INumberBase public partial struct uint2 : INumberBase { /// public static uint2 Zero => new(0); /// public static uint2 One => new(1); static uint2 IAdditiveIdentity.AdditiveIdentity => Zero; static uint2 IMultiplicativeIdentity.MultiplicativeIdentity => One; static int INumberBase.Radix => 2; // every component type is binary static uint2 INumberBase.Abs(uint2 value) => value; static bool INumberBase.IsCanonical(uint2 value) => true; static bool INumberBase.IsComplexNumber(uint2 value) => false; static bool INumberBase.IsImaginaryNumber(uint2 value) => false; /// Determines if every component of a value is zero. [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool INumberBase.IsZero(uint2 value) { return value == Zero; } /// Determines if every component of a value is an even integral value. [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool INumberBase.IsEvenInteger(uint2 value) { return (value.X & 1) == 0 && (value.Y & 1) == 0; } /// Determines if every component of a value is an odd integral value. [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool INumberBase.IsOddInteger(uint2 value) { return (value.X & 1) == 1 && (value.Y & 1) == 1; } static bool INumberBase.IsNegative(uint2 value) => false; static bool INumberBase.IsPositive(uint2 value) => true; static bool INumberBase.IsFinite(uint2 value) => true; static bool INumberBase.IsInfinity(uint2 value) => false; static bool INumberBase.IsNegativeInfinity(uint2 value) => false; static bool INumberBase.IsPositiveInfinity(uint2 value) => false; static bool INumberBase.IsInteger(uint2 value) => true; static bool INumberBase.IsRealNumber(uint2 value) => true; static bool INumberBase.IsNaN(uint2 value) => false; static bool INumberBase.IsNormal(uint2 value) => value.X != 0 && value.Y != 0; static bool INumberBase.IsSubnormal(uint2 value) => false; /// Computes, componentwise, the value whose magnitude is greater. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 MaxMagnitude(uint2 a, uint2 b) { return Max(a, b); } /// Computes, componentwise, the value whose magnitude is greater. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 MaxMagnitudeNumber(uint2 a, uint2 b) { return Max(a, b); } /// Computes, componentwise, the value whose magnitude is smaller. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 MinMagnitude(uint2 a, uint2 b) { return Min(a, b); } /// Computes, componentwise, the value whose magnitude is smaller. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 MinMagnitudeNumber(uint2 a, uint2 b) { return Min(a, b); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 Add(uint2 a, uint2 b) { return a + b; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 Divide(uint2 a, uint2 b) { return a / b; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 Multiply(uint2 a, uint2 b) { return a * b; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 Negate(uint2 value) { return -value; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 Subtract(uint2 a, uint2 b) { return a - b; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 operator +(uint2 a, uint2 b) { return new(a.X + b.X, a.Y + b.Y); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 operator -(uint2 a, uint2 b) { return new(a.X - b.X, a.Y - b.Y); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 operator *(uint2 a, uint2 b) { return new(a.X * b.X, a.Y * b.Y); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 operator /(uint2 a, uint2 b) { return new(a.X / b.X, a.Y / b.Y); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 operator -(uint2 a) { return new(0 - a.X, 0 - a.Y); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 operator +(uint2 a) { return a; } // ++/-- are well-defined (+/- One) but a footgun on a concrete vector: generic-plane only. static uint2 IIncrementOperators.operator ++(uint2 value) => value + One; static uint2 IDecrementOperators.operator --(uint2 value) => value - One; static bool INumberBase.TryConvertFromChecked(TOther value, out uint2 result) { return NumberConversion.TryConvertFrom(value, out result); } static bool INumberBase.TryConvertToChecked(uint2 value, [MaybeNullWhen(false)] out TOther result) { result = default; return false; } static bool INumberBase.TryConvertFromSaturating(TOther value, out uint2 result) { return NumberConversion.TryConvertFrom(value, out result); } static bool INumberBase.TryConvertToSaturating(uint2 value, [MaybeNullWhen(false)] out TOther result) { result = default; return false; } static bool INumberBase.TryConvertFromTruncating(TOther value, out uint2 result) { return NumberConversion.TryConvertFrom(value, out result); } static bool INumberBase.TryConvertToTruncating(uint2 value, [MaybeNullWhen(false)] out TOther result) { result = default; return false; } } // IMultiplyOperators, IDivisionOperators public partial struct uint2 : IMultiplyOperators , IDivisionOperators { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 Divide(uint2 a, uint b) { return a / b; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 Multiply(uint2 a, uint b) { return a * b; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 Multiply(uint a, uint2 b) { return a * b; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 operator *(uint2 a, uint b) { return new(a.X * b, a.Y * b); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 operator /(uint2 a, uint b) { return new(a.X / b, a.Y / b); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 operator *(uint a, uint2 b) { return new(a * b.X, a * b.Y); } } // INumber public partial struct uint2 : INumber { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 Clamp(uint2 value, uint2 min, uint2 max) { // HLSL contract when min > max: max wins (clamp is Max-then-Min); pinned in // Clamp_InvertedBounds_MatchesBcl. NOT scalar T.Clamp, which throws on inversion. return Min(Max(value, min), max); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 Max(uint2 a, uint2 b) { return new(uint.Max(a.X, b.X), uint.Max(a.Y, b.Y)); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 Min(uint2 a, uint2 b) { return new(uint.Min(a.X, b.X), uint.Min(a.Y, b.Y)); } static uint2 INumber.MaxNumber(uint2 a, uint2 b) => Max(a, b); static uint2 INumber.MinNumber(uint2 a, uint2 b) => Min(a, b); static uint2 INumber.CopySign(uint2 value, uint2 sign) => value; // the Native variants permit either NaN/signed-zero behavior - forwarding is always legal static uint2 INumber.ClampNative(uint2 value, uint2 min, uint2 max) => Clamp(value, min, max); static uint2 INumber.MaxNative(uint2 a, uint2 b) => Max(a, b); static uint2 INumber.MinNative(uint2 a, uint2 b) => Min(a, b); // Sign's int return cannot hold a per-lane answer, and a collapsed one would lie for mixed signs static int INumber.Sign(uint2 value) => throw new NotSupportedException($"{nameof(uint2)} has no scalar sign."); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 operator %(uint2 a, uint2 b) { return new uint2(a.X % b.X, a.Y % b.Y); } int IComparable.CompareTo(object? obj) => throw new NotSupportedException($"{nameof(uint2)} has no total order."); int IComparable.CompareTo(uint2 other) => throw new NotSupportedException($"{nameof(uint2)} has no total order."); static bool IComparisonOperators.operator <(uint2 a, uint2 b) => throw new NotSupportedException($"{nameof(uint2)} has no total order."); static bool IComparisonOperators.operator <=(uint2 a, uint2 b) => throw new NotSupportedException($"{nameof(uint2)} has no total order."); static bool IComparisonOperators.operator >(uint2 a, uint2 b) => throw new NotSupportedException($"{nameof(uint2)} has no total order."); static bool IComparisonOperators.operator >=(uint2 a, uint2 b) => throw new NotSupportedException($"{nameof(uint2)} has no total order."); } // IComponentwiseComparison + the componentwise predicate masks (no interface to mirror) public partial struct uint2 : IComponentwiseComparison { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool2 operator <(uint2 a, uint2 b) { return new bool2(a.X < b.X, a.Y < b.Y); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool2 operator <=(uint2 a, uint2 b) { return new bool2(a.X <= b.X, a.Y <= b.Y); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool2 operator >(uint2 a, uint2 b) { return new bool2(a.X > b.X, a.Y > b.Y); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool2 operator >=(uint2 a, uint2 b) { return new bool2(a.X >= b.X, a.Y >= b.Y); } /// Determines which components of a value are zero. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool2 IsZero(uint2 value) { return new bool2(value.X == 0, value.Y == 0); } /// Determines which components of a value are an even integral value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool2 IsEvenInteger(uint2 value) { return new bool2(uint.IsEvenInteger(value.X), uint.IsEvenInteger(value.Y)); } /// Determines which components of a value are an odd integral value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool2 IsOddInteger(uint2 value) { return new bool2(uint.IsOddInteger(value.X), uint.IsOddInteger(value.Y)); } } // IUnsignedNumber - a marker, so there is nothing to implement public partial struct uint2 : IUnsignedNumber;