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