SOURCE DUMP v1

This commit is contained in:
Rian Drake 2026-10-15 14:09:11 +13:00
commit fb20299e9d
9 changed files with 768360 additions and 0 deletions

View file

@ -0,0 +1,28 @@
// <auto-generated /> - edit Vector.copy.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct sbyte2
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly void CopyTo(Span<sbyte> destination)
{
if (destination.Length < ComponentCount)
throw new ArgumentException("Length must be at least 2.", nameof(destination));
Unsafe.WriteUnaligned(ref Unsafe.As<sbyte, byte>(ref MemoryMarshal.GetReference(destination)), this);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool TryCopyTo(Span<sbyte> destination)
{
if (destination.Length < ComponentCount)
return false;
Unsafe.WriteUnaligned(ref Unsafe.As<sbyte, byte>(ref MemoryMarshal.GetReference(destination)), this);
return true;
}
}

View file

@ -0,0 +1,41 @@
// <auto-generated /> - edit Vector.equality.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct sbyte2
{
/// <inheritdoc />
public readonly override int GetHashCode()
{
return HashCode.Combine(X, Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool Equals(sbyte2 other)
{
return X.Equals(other.X) && Y.Equals(other.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly override bool Equals([NotNullWhen(true)] object? obj)
{
return obj is sbyte2 other && Equals(other);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(sbyte2 a, sbyte2 b)
{
return a.X == b.X && a.Y == b.Y;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(sbyte2 a, sbyte2 b)
{
return !(a == b);
}
}

View file

@ -0,0 +1,92 @@
// <auto-generated /> - edit Vector.format.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct sbyte2 : ISpanFormattable, IUtf8SpanFormattable, ISpanParsable<sbyte2>
{
/// <inheritdoc />
public readonly override string ToString()
{
return ToString("G", CultureInfo.CurrentCulture);
}
/// <inheritdoc cref="Vector2.ToString(string?)" />
public readonly string ToString(string? format)
{
return ToString(format, CultureInfo.CurrentCulture);
}
/// <inheritdoc />
public readonly string ToString(string? format, IFormatProvider? formatProvider)
{
var separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator;
return $"<{X.ToString(format, formatProvider)}{separator} {Y.ToString(format, formatProvider)}>";
}
/// <inheritdoc />
public readonly bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
{
return StringHelpers.TryFormat<sbyte2, sbyte>(this, destination, out charsWritten, format, provider);
}
/// <inheritdoc />
public readonly bool TryFormat(Span<byte> destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
{
return StringHelpers.TryFormat<sbyte2, sbyte>(this, destination, out bytesWritten, format, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static sbyte2 Parse(string s, IFormatProvider? provider)
{
ArgumentNullException.ThrowIfNull(s);
return Parse(s.AsSpan(), NumberStyles.Integer, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static sbyte2 Parse(ReadOnlySpan<char> s, IFormatProvider? provider = null)
{
return Parse(s, NumberStyles.Integer, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static sbyte2 Parse(string s, NumberStyles style, IFormatProvider? provider)
{
ArgumentNullException.ThrowIfNull(s);
return Parse(s.AsSpan(), style, provider);
}
/// <summary>Parses from the <see cref="ToString()" /> format, <c>&lt;1, 2, 3&gt;</c>.</summary>
/// <exception cref="FormatException">The input is not in a valid format, or a component fails to parse.</exception>
public static sbyte2 Parse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider)
{
if (!TryParse(s, style, provider, out var result))
throw new FormatException($"'{s}' is not in a valid sbyte2 format.");
return result;
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out sbyte2)" />
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out sbyte2 result)
{
return TryParse(s.AsSpan(), NumberStyles.Integer, provider, out result);
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out sbyte2)" />
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out sbyte2 result)
{
return TryParse(s, NumberStyles.Integer, provider, out result);
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out sbyte2)" />
public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out sbyte2 result)
{
return TryParse(s.AsSpan(), style, provider, out result);
}
/// <summary>Parses from the <see cref="ToString()" /> format, <c>&lt;1, 2, 3&gt;</c>.</summary>
/// <returns>true if the input parsed as a sbyte2.</returns>
public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out sbyte2 result)
{
return StringHelpers.TryParse<sbyte2, sbyte>(s, style, provider, out result);
}
}

View file

@ -0,0 +1,106 @@
// <auto-generated /> - edit Vector.tt to modify
#nullable enable
namespace Brutal.Numerics;
/// <summary>
/// Implements a 2D vector with sbyte components.
/// </summary>
[DebuggerTypeProxy(typeof(VectorDebugView2<sbyte2, sbyte, float>))]
public partial struct sbyte2 : IVector2<sbyte2, sbyte>
, ISignedIntegerVector<sbyte2, sbyte, int, float>
{
/// <inheritdoc />
public static int ComponentSize => sizeof(sbyte);
/// <summary>Gets the number of components.</summary>
public static int ComponentCount => 2;
/// <inheritdoc cref="Vector2.X" />
[XmlAttribute]
public sbyte X;
/// <inheritdoc cref="Vector2.Y" />
[XmlAttribute]
public sbyte Y;
sbyte IVector2<sbyte2, sbyte>.X { readonly get => X; set => X = value; }
sbyte IVector2<sbyte2, sbyte>.Y { readonly get => Y; set => Y = value; }
/// <inheritdoc cref="Vector2(float, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public sbyte2(sbyte x, sbyte y)
{
X = x;
Y = y;
}
/// <inheritdoc cref="Vector2(float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public sbyte2(sbyte xy)
: this(xy, xy) { }
/// <summary>Creates a vector from the leading 2 elements of a span.</summary>
/// <param name="span">The elements to read; must contain at least 2, and any beyond that are ignored.</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="span" /> holds fewer than 2 elements.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public sbyte2(ReadOnlySpan<sbyte> span)
{
if (span.Length < 2)
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 2.");
this = Unsafe.ReadUnaligned<sbyte2>(ref Unsafe.As<sbyte, byte>(ref MemoryMarshal.GetReference(span)));
}
/// <inheritdoc cref="sbyte2(ReadOnlySpan{sbyte})" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static sbyte2 IComponentTuple<sbyte2, sbyte>.Create(ReadOnlySpan<sbyte> span) => new(span);
/// <inheritdoc />
public static sbyte2 UnitX => new(1, 0);
/// <inheritdoc />
public static sbyte2 UnitY => new(0, 1);
/// <inheritdoc />
public sbyte this[int index]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get
{
if ((uint)index >= ComponentCount)
throw new ArgumentOutOfRangeException(nameof(index));
return Unsafe.Add(ref Unsafe.AsRef(in X), index);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
if ((uint)index >= ComponentCount)
throw new ArgumentOutOfRangeException(nameof(index));
Unsafe.Add(ref X, index) = value;
}
}
public readonly void Deconstruct(out sbyte x, out sbyte y)
{
x = X;
y = Y;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<sbyte> AsSpan()
{
return MemoryMarshal.CreateSpan(ref Unsafe.As<sbyte2, sbyte>(ref this), 2);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ReadOnlySpan<sbyte> AsReadOnlySpan()
{
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<sbyte2, sbyte>(ref Unsafe.AsRef(in this)), 2);
}
}

View file

@ -0,0 +1,42 @@
// <auto-generated /> - edit Vector.math-metric.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct sbyte2
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly float Length()
{
return (float)double.Sqrt((double)X * X + (double)Y * Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly int LengthSquared()
{
return Dot(this, this);
}
/// <inheritdoc cref="Vector2.Distance" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Distance(sbyte2 a, sbyte2 b)
{
return (float)double.Sqrt(((double)a.X - b.X) * ((double)a.X - b.X) + ((double)a.Y - b.Y) * ((double)a.Y - b.Y));
}
/// <inheritdoc cref="Vector2.DistanceSquared" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int DistanceSquared(sbyte2 a, sbyte2 b)
{
return (a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y);
}
/// <inheritdoc cref="Vector2.Dot" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Dot(sbyte2 a, sbyte2 b)
{
return a.X * b.X + a.Y * b.Y;
}
}

View file

@ -0,0 +1,100 @@
// <auto-generated /> - edit Vector.numerics-binary.tt to modify
#nullable enable
namespace Brutal.Numerics;
// IBinaryNumber
public partial struct sbyte2 : IBinaryNumber<sbyte2>
{
/// <summary>Determines if every component of a value is a power of two.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool IBinaryNumber<sbyte2>.IsPow2(sbyte2 value)
{
return sbyte.IsPow2(value.X) && sbyte.IsPow2(value.Y);
}
/// <inheritdoc cref="IBinaryNumber{TSelf}.Log2" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte2 Log2(sbyte2 value)
{
return new sbyte2(sbyte.Log2(value.X), sbyte.Log2(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte2 operator &(sbyte2 a, sbyte2 b)
{
return new((sbyte)(a.X & b.X), (sbyte)(a.Y & b.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte2 operator |(sbyte2 a, sbyte2 b)
{
return new((sbyte)(a.X | b.X), (sbyte)(a.Y | b.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte2 operator ^(sbyte2 a, sbyte2 b)
{
return new((sbyte)(a.X ^ b.X), (sbyte)(a.Y ^ b.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte2 operator ~(sbyte2 value)
{
return new((sbyte)(~value.X), (sbyte)(~value.Y));
}
}
// the componentwise predicate mask (no interface to mirror) - the per-lane truth IsPow2 collapses
public partial struct sbyte2
{
/// <summary>Determines which components of a value are powers of two.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsPow2(sbyte2 value)
{
return new bool2(sbyte.IsPow2(value.X), sbyte.IsPow2(value.Y));
}
}
// the good bits from IBinaryInteger - declared on IIntegerVector
public partial struct sbyte2
{
/// <inheritdoc cref="IBinaryInteger{TSelf}.PopCount" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte2 PopCount(sbyte2 value)
{
return new sbyte2(sbyte.PopCount(value.X), sbyte.PopCount(value.Y));
}
/// <inheritdoc cref="IBinaryInteger{TSelf}.LeadingZeroCount" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte2 LeadingZeroCount(sbyte2 value)
{
return new sbyte2(sbyte.LeadingZeroCount(value.X), sbyte.LeadingZeroCount(value.Y));
}
/// <inheritdoc cref="IBinaryInteger{TSelf}.TrailingZeroCount" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte2 TrailingZeroCount(sbyte2 value)
{
return new sbyte2(sbyte.TrailingZeroCount(value.X), sbyte.TrailingZeroCount(value.Y));
}
/// <inheritdoc cref="IBinaryInteger{TSelf}.RotateLeft" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte2 RotateLeft(sbyte2 value, int rotateAmount)
{
return new sbyte2(sbyte.RotateLeft(value.X, rotateAmount), sbyte.RotateLeft(value.Y, rotateAmount));
}
/// <inheritdoc cref="IBinaryInteger{TSelf}.RotateRight" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte2 RotateRight(sbyte2 value, int rotateAmount)
{
return new sbyte2(sbyte.RotateRight(value.X, rotateAmount), sbyte.RotateRight(value.Y, rotateAmount));
}
}

View file

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

View file

@ -0,0 +1,210 @@
// <auto-generated /> - edit Vector.pack.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct sbyte2
{
public static sbyte2 Pack(in byte2 vector, Func<byte, sbyte> elementConverter)
{
VectorPack.Pack(vector, out sbyte2 result, elementConverter);
return result;
}
public static sbyte2 Pack(in short2 vector, Func<short, sbyte> elementConverter)
{
VectorPack.Pack(vector, out sbyte2 result, elementConverter);
return result;
}
public static sbyte2 Pack(in ushort2 vector, Func<ushort, sbyte> elementConverter)
{
VectorPack.Pack(vector, out sbyte2 result, elementConverter);
return result;
}
public static sbyte2 Pack(in int2 vector, Func<int, sbyte> elementConverter)
{
VectorPack.Pack(vector, out sbyte2 result, elementConverter);
return result;
}
public static sbyte2 Pack(in uint2 vector, Func<uint, sbyte> elementConverter)
{
VectorPack.Pack(vector, out sbyte2 result, elementConverter);
return result;
}
public static sbyte2 Pack(in float2 vector, Func<float, sbyte> elementConverter)
{
VectorPack.Pack(vector, out sbyte2 result, elementConverter);
return result;
}
public static sbyte2 Pack(in double2 vector, Func<double, sbyte> elementConverter)
{
VectorPack.Pack(vector, out sbyte2 result, elementConverter);
return result;
}
public static sbyte2 Pack(in byte2 vector, Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast)
{
return Pack(vector, PackUtils.Byte.ToSByte(mode));
}
public static sbyte2 Pack(in short2 vector, Pack.Integer mode = Numerics.Pack.Integer.Cast)
{
return Pack(vector, PackUtils.Short.ToSByte(mode));
}
public static sbyte2 Pack(in ushort2 vector, Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast)
{
return Pack(vector, PackUtils.UShort.ToSByte(mode));
}
public static sbyte2 Pack(in int2 vector, Pack.Integer mode = Numerics.Pack.Integer.Cast)
{
return Pack(vector, PackUtils.Int.ToSByte(mode));
}
public static sbyte2 Pack(in uint2 vector, Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast)
{
return Pack(vector, PackUtils.UInt.ToSByte(mode));
}
public static sbyte2 Pack(in float2 vector, Pack.Float mode = Numerics.Pack.Float.Truncate)
{
return Pack(vector, PackUtils.Float.ToSByte(mode));
}
public static sbyte2 Pack(in double2 vector, Pack.Float mode = Numerics.Pack.Float.Truncate)
{
return Pack(vector, PackUtils.Double.ToSByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<byte2> source,
Span<sbyte2> destination,
Func<byte, sbyte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<short2> source,
Span<sbyte2> destination,
Func<short, sbyte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<ushort2> source,
Span<sbyte2> destination,
Func<ushort, sbyte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<int2> source,
Span<sbyte2> destination,
Func<int, sbyte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<uint2> source,
Span<sbyte2> destination,
Func<uint, sbyte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<float2> source,
Span<sbyte2> destination,
Func<float, sbyte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<double2> source,
Span<sbyte2> destination,
Func<double, sbyte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<byte2> source,
Span<sbyte2> destination,
Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast
)
{
PackSpan(source, destination, PackUtils.Byte.ToSByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<short2> source,
Span<sbyte2> destination,
Pack.Integer mode = Numerics.Pack.Integer.Cast
)
{
PackSpan(source, destination, PackUtils.Short.ToSByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<ushort2> source,
Span<sbyte2> destination,
Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast
)
{
PackSpan(source, destination, PackUtils.UShort.ToSByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<int2> source,
Span<sbyte2> destination,
Pack.Integer mode = Numerics.Pack.Integer.Cast
)
{
PackSpan(source, destination, PackUtils.Int.ToSByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<uint2> source,
Span<sbyte2> destination,
Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast
)
{
PackSpan(source, destination, PackUtils.UInt.ToSByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<float2> source,
Span<sbyte2> destination,
Pack.Float mode = Numerics.Pack.Float.Truncate
)
{
PackSpan(source, destination, PackUtils.Float.ToSByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<double2> source,
Span<sbyte2> destination,
Pack.Float mode = Numerics.Pack.Float.Truncate
)
{
PackSpan(source, destination, PackUtils.Double.ToSByte(mode));
}
}

View file

@ -0,0 +1,80 @@
// <auto-generated /> - edit Vector.swizzle.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct sbyte2
{
/// <summary>
/// Swizzle readonly getter/setter for the X and Y components of the vector.
/// </summary>
[XmlIgnore]
public sbyte2 XY
{
readonly get => this;
set => this = value;
}
/// <summary>
/// Swizzle readonly getter/setter for the Y and X components of the vector.
/// </summary>
[XmlIgnore]
public sbyte2 YX
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(Y, X);
set
{
Y = value.X;
X = value.Y;
}
}
}
public partial struct sbyte2
{
/// <summary>
/// The Red component of the vector (synonym for X).
/// </summary>
[XmlIgnore]
public sbyte R
{
readonly get => X;
set => X = value;
}
/// <summary>
/// The Green component of the vector (synonym for Y).
/// </summary>
[XmlIgnore]
public sbyte G
{
readonly get => Y;
set => Y = value;
}
/// <summary>
/// Swizzle readonly getter/setter for the Red and Green components of the vector.
/// </summary>
[XmlIgnore]
public sbyte2 RG
{
readonly get => this;
set => this = value;
}
/// <summary>
/// Swizzle readonly getter/setter for the Green and Red components of the vector.
/// </summary>
[XmlIgnore]
public sbyte2 GR
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(Y, X);
set
{
G = value.R;
R = value.G;
}
}
}