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