// - edit Vector.numerics.tt to modify #nullable enable namespace Brutal.Numerics; // INumberBase public partial struct long3 : INumberBase { /// public static long3 Zero => new(0); /// public static long3 One => new(1); static long3 IAdditiveIdentity.AdditiveIdentity => Zero; static long3 IMultiplicativeIdentity.MultiplicativeIdentity => One; static int INumberBase.Radix => 2; // every component type is binary /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 Abs(long3 value) { return new long3(WrappingAbs(value.X), WrappingAbs(value.Y), WrappingAbs(value.Z)); } /* |MinValue| is unrepresentable, so that lane keeps MinValue and Abs can return a NEGATIVE * number. Deliberate, settled 2026-08-25: Math.Abs throws there instead, which kills a whole * vector for one pathological lane. Everyone else wraps - HLSL, GLSL, SPIR-V SAbs, LLVM's * llvm.abs on its non-poison branch, and .NET's own Vector128.Abs, whose Scalar.Abs even * carries the comment "avoid Math.Abs for integers since it throws for MinValue". * unchecked is explicit because the wrap IS the contract here: on the narrow types the * truncating cast is what performs it (-short.MinValue widens to 32768, which no short holds), * so this must not depend on the project's overflow setting. */ private static long WrappingAbs(long value) => unchecked(value < 0 ? -value : value); static bool INumberBase.IsCanonical(long3 value) => true; static bool INumberBase.IsComplexNumber(long3 value) => false; static bool INumberBase.IsImaginaryNumber(long3 value) => false; /// Determines if every component of a value is zero. [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool INumberBase.IsZero(long3 value) { return value == Zero; } /// Determines if every component of a value is an even integral value. [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool INumberBase.IsEvenInteger(long3 value) { return (value.X & 1) == 0 && (value.Y & 1) == 0 && (value.Z & 1) == 0; } /// Determines if every component of a value is an odd integral value. [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool INumberBase.IsOddInteger(long3 value) { return (value.X & 1) == 1 && (value.Y & 1) == 1 && (value.Z & 1) == 1; } /// Determines if every component of a value is negative. [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool INumberBase.IsNegative(long3 value) { return value.X < 0 && value.Y < 0 && value.Z < 0; } /// Determines if every component of a value is positive. [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool INumberBase.IsPositive(long3 value) { return value.X >= 0 && value.Y >= 0 && value.Z >= 0; } static bool INumberBase.IsFinite(long3 value) => true; static bool INumberBase.IsInfinity(long3 value) => false; static bool INumberBase.IsNegativeInfinity(long3 value) => false; static bool INumberBase.IsPositiveInfinity(long3 value) => false; static bool INumberBase.IsInteger(long3 value) => true; static bool INumberBase.IsRealNumber(long3 value) => true; static bool INumberBase.IsNaN(long3 value) => false; static bool INumberBase.IsNormal(long3 value) => value.X != 0 && value.Y != 0 && value.Z != 0; static bool INumberBase.IsSubnormal(long3 value) => false; /// Computes, componentwise, the value whose magnitude is greater. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 MaxMagnitude(long3 a, long3 b) { return new long3(long.MaxMagnitude(a.X, b.X), long.MaxMagnitude(a.Y, b.Y), long.MaxMagnitude(a.Z, b.Z)); } /// Computes, componentwise, the value whose magnitude is greater. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 MaxMagnitudeNumber(long3 a, long3 b) { return new long3(long.MaxMagnitude(a.X, b.X), long.MaxMagnitude(a.Y, b.Y), long.MaxMagnitude(a.Z, b.Z)); } /// Computes, componentwise, the value whose magnitude is smaller. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 MinMagnitude(long3 a, long3 b) { return new long3(long.MinMagnitude(a.X, b.X), long.MinMagnitude(a.Y, b.Y), long.MinMagnitude(a.Z, b.Z)); } /// Computes, componentwise, the value whose magnitude is smaller. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 MinMagnitudeNumber(long3 a, long3 b) { return new long3(long.MinMagnitude(a.X, b.X), long.MinMagnitude(a.Y, b.Y), long.MinMagnitude(a.Z, b.Z)); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 Add(long3 a, long3 b) { return a + b; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 Divide(long3 a, long3 b) { return a / b; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 Multiply(long3 a, long3 b) { return a * b; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 Negate(long3 value) { return -value; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 Subtract(long3 a, long3 b) { return a - b; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 operator +(long3 a, long3 b) { return new(a.X + b.X, a.Y + b.Y, a.Z + b.Z); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 operator -(long3 a, long3 b) { return new(a.X - b.X, a.Y - b.Y, a.Z - b.Z); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 operator *(long3 a, long3 b) { return new(a.X * b.X, a.Y * b.Y, a.Z * b.Z); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 operator /(long3 a, long3 b) { return new(a.X / b.X, a.Y / b.Y, a.Z / b.Z); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 operator -(long3 a) { return new(-a.X, -a.Y, -a.Z); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 operator +(long3 a) { return a; } // ++/-- are well-defined (+/- One) but a footgun on a concrete vector: generic-plane only. static long3 IIncrementOperators.operator ++(long3 value) => value + One; static long3 IDecrementOperators.operator --(long3 value) => value - One; static bool INumberBase.TryConvertFromChecked(TOther value, out long3 result) { return NumberConversion.TryConvertFrom(value, out result); } static bool INumberBase.TryConvertToChecked(long3 value, [MaybeNullWhen(false)] out TOther result) { result = default; return false; } static bool INumberBase.TryConvertFromSaturating(TOther value, out long3 result) { return NumberConversion.TryConvertFrom(value, out result); } static bool INumberBase.TryConvertToSaturating(long3 value, [MaybeNullWhen(false)] out TOther result) { result = default; return false; } static bool INumberBase.TryConvertFromTruncating(TOther value, out long3 result) { return NumberConversion.TryConvertFrom(value, out result); } static bool INumberBase.TryConvertToTruncating(long3 value, [MaybeNullWhen(false)] out TOther result) { result = default; return false; } } // IMultiplyOperators, IDivisionOperators public partial struct long3 : IMultiplyOperators , IDivisionOperators { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 Divide(long3 a, long b) { return a / b; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 Multiply(long3 a, long b) { return a * b; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 Multiply(long a, long3 b) { return a * b; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 operator *(long3 a, long b) { return new(a.X * b, a.Y * b, a.Z * b); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 operator /(long3 a, long b) { return new(a.X / b, a.Y / b, a.Z / b); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 operator *(long a, long3 b) { return new(a * b.X, a * b.Y, a * b.Z); } } // INumber public partial struct long3 : INumber { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 Clamp(long3 value, long3 min, long3 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 long3 Max(long3 a, long3 b) { return new(long.Max(a.X, b.X), long.Max(a.Y, b.Y), long.Max(a.Z, b.Z)); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 Min(long3 a, long3 b) { return new(long.Min(a.X, b.X), long.Min(a.Y, b.Y), long.Min(a.Z, b.Z)); } static long3 INumber.MaxNumber(long3 a, long3 b) => Max(a, b); static long3 INumber.MinNumber(long3 a, long3 b) => Min(a, b); /// Copies, componentwise, the sign of onto the magnitude of . [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 CopySign(long3 value, long3 sign) { return new long3(long.CopySign(value.X, sign.X), long.CopySign(value.Y, sign.Y), long.CopySign(value.Z, sign.Z)); } // the Native variants permit either NaN/signed-zero behavior - forwarding is always legal static long3 INumber.ClampNative(long3 value, long3 min, long3 max) => Clamp(value, min, max); static long3 INumber.MaxNative(long3 a, long3 b) => Max(a, b); static long3 INumber.MinNative(long3 a, long3 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(long3 value) => throw new NotSupportedException($"{nameof(long3)} has no scalar sign."); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long3 operator %(long3 a, long3 b) { return new long3(a.X % b.X, a.Y % b.Y, a.Z % b.Z); } int IComparable.CompareTo(object? obj) => throw new NotSupportedException($"{nameof(long3)} has no total order."); int IComparable.CompareTo(long3 other) => throw new NotSupportedException($"{nameof(long3)} has no total order."); static bool IComparisonOperators.operator <(long3 a, long3 b) => throw new NotSupportedException($"{nameof(long3)} has no total order."); static bool IComparisonOperators.operator <=(long3 a, long3 b) => throw new NotSupportedException($"{nameof(long3)} has no total order."); static bool IComparisonOperators.operator >(long3 a, long3 b) => throw new NotSupportedException($"{nameof(long3)} has no total order."); static bool IComparisonOperators.operator >=(long3 a, long3 b) => throw new NotSupportedException($"{nameof(long3)} has no total order."); } // IComponentwiseComparison + the componentwise predicate masks (no interface to mirror) public partial struct long3 : IComponentwiseComparison { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool3 operator <(long3 a, long3 b) { return new bool3(a.X < b.X, a.Y < b.Y, a.Z < b.Z); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool3 operator <=(long3 a, long3 b) { return new bool3(a.X <= b.X, a.Y <= b.Y, a.Z <= b.Z); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool3 operator >(long3 a, long3 b) { return new bool3(a.X > b.X, a.Y > b.Y, a.Z > b.Z); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool3 operator >=(long3 a, long3 b) { return new bool3(a.X >= b.X, a.Y >= b.Y, a.Z >= b.Z); } /// Determines which components of a value are zero. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool3 IsZero(long3 value) { return new bool3(value.X == 0, value.Y == 0, value.Z == 0); } /// Determines which components of a value are an even integral value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool3 IsEvenInteger(long3 value) { return new bool3(long.IsEvenInteger(value.X), long.IsEvenInteger(value.Y), long.IsEvenInteger(value.Z)); } /// Determines which components of a value are an odd integral value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool3 IsOddInteger(long3 value) { return new bool3(long.IsOddInteger(value.X), long.IsOddInteger(value.Y), long.IsOddInteger(value.Z)); } /// Determines which components of a value are negative. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool3 IsNegative(long3 value) { return new bool3(long.IsNegative(value.X), long.IsNegative(value.Y), long.IsNegative(value.Z)); } /// Determines which components of a value are positive. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool3 IsPositive(long3 value) { return new bool3(long.IsPositive(value.X), long.IsPositive(value.Y), long.IsPositive(value.Z)); } } // ISignedNumber public partial struct long3 : ISignedNumber { /// public static long3 NegativeOne => new(-1); }