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