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