This commit is contained in:
Rian Drake 2026-10-15 14:09:11 +13:00
commit b578433e37
9 changed files with 784842 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 sbyte4
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly void CopyTo(Span<sbyte> destination)
{
if (destination.Length < ComponentCount)
throw new ArgumentException("Length must be at least 4.", 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 sbyte4
{
/// <inheritdoc />
public readonly override int GetHashCode()
{
return HashCode.Combine(X, Y, Z, W);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool Equals(sbyte4 other)
{
return X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z) && W.Equals(other.W);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly override bool Equals([NotNullWhen(true)] object? obj)
{
return obj is sbyte4 other && Equals(other);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(sbyte4 a, sbyte4 b)
{
return a.X == b.X && a.Y == b.Y && a.Z == b.Z && a.W == b.W;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(sbyte4 a, sbyte4 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 sbyte4 : ISpanFormattable, IUtf8SpanFormattable, ISpanParsable<sbyte4>
{
/// <inheritdoc />
public readonly override string ToString()
{
return ToString("G", CultureInfo.CurrentCulture);
}
/// <inheritdoc cref="Vector4.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)}{separator} {Z.ToString(format, formatProvider)}{separator} {W.ToString(format, formatProvider)}>";
}
/// <inheritdoc />
public readonly bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
{
return StringHelpers.TryFormat<sbyte4, 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<sbyte4, sbyte>(this, destination, out bytesWritten, format, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static sbyte4 Parse(string s, IFormatProvider? provider)
{
ArgumentNullException.ThrowIfNull(s);
return Parse(s.AsSpan(), NumberStyles.Integer, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static sbyte4 Parse(ReadOnlySpan<char> s, IFormatProvider? provider = null)
{
return Parse(s, NumberStyles.Integer, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static sbyte4 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 sbyte4 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 sbyte4 format.");
return result;
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out sbyte4)" />
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out sbyte4 result)
{
return TryParse(s.AsSpan(), NumberStyles.Integer, provider, out result);
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out sbyte4)" />
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out sbyte4 result)
{
return TryParse(s, NumberStyles.Integer, provider, out result);
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out sbyte4)" />
public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out sbyte4 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 sbyte4.</returns>
public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out sbyte4 result)
{
return StringHelpers.TryParse<sbyte4, sbyte>(s, style, provider, out result);
}
}

View file

@ -0,0 +1,147 @@
// <auto-generated /> - edit Vector.tt to modify
#nullable enable
namespace Brutal.Numerics;
/// <summary>
/// Implements a 4D vector with sbyte components.
/// </summary>
[DebuggerTypeProxy(typeof(VectorDebugView4<sbyte4, sbyte, float>))]
public partial struct sbyte4 : IVector4<sbyte4, sbyte>
, ISignedIntegerVector<sbyte4, sbyte, int, float>
{
/// <inheritdoc />
public static int ComponentSize => sizeof(sbyte);
/// <summary>Gets the number of components.</summary>
public static int ComponentCount => 4;
/// <inheritdoc cref="Vector4.X" />
[XmlAttribute]
public sbyte X;
/// <inheritdoc cref="Vector4.Y" />
[XmlAttribute]
public sbyte Y;
/// <inheritdoc cref="Vector4.Z" />
[XmlAttribute]
public sbyte Z;
/// <inheritdoc cref="Vector4.W" />
[XmlAttribute]
public sbyte W;
sbyte IVector4<sbyte4, sbyte>.X { readonly get => X; set => X = value; }
sbyte IVector4<sbyte4, sbyte>.Y { readonly get => Y; set => Y = value; }
sbyte IVector4<sbyte4, sbyte>.Z { readonly get => Z; set => Z = value; }
sbyte IVector4<sbyte4, sbyte>.W { readonly get => W; set => W = value; }
/// <inheritdoc cref="Vector4(float, float, float, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public sbyte4(sbyte x, sbyte y, sbyte z, sbyte w)
{
X = x;
Y = y;
Z = z;
W = w;
}
/// <inheritdoc cref="Vector4(float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public sbyte4(sbyte xyzw)
: this(xyzw, xyzw, xyzw, xyzw) { }
/// <inheritdoc cref="Vector4(Vector3, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public sbyte4(sbyte3 xyz, sbyte w)
: this(xyz.X, xyz.Y, xyz.Z, w) { }
/// <summary>
/// Creates a new instance of <see cref="sbyte4" /> from two <see cref="sbyte2" /> instances.
/// </summary>
/// <param name="xy">The first two components.</param>
/// <param name="zw">The last two components.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public sbyte4(sbyte2 xy, sbyte2 zw)
: this(xy.X, xy.Y, zw.X, zw.Y) { }
/// <inheritdoc cref="Vector4(Vector2, float, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public sbyte4(sbyte2 xy, sbyte z, sbyte w)
: this(xy.X, xy.Y, z, w) { }
/// <summary>Creates a vector from the leading 4 elements of a span.</summary>
/// <param name="span">The elements to read; must contain at least 4, and any beyond that are ignored.</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="span" /> holds fewer than 4 elements.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public sbyte4(ReadOnlySpan<sbyte> span)
{
if (span.Length < 4)
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 4.");
this = Unsafe.ReadUnaligned<sbyte4>(ref Unsafe.As<sbyte, byte>(ref MemoryMarshal.GetReference(span)));
}
/// <inheritdoc cref="sbyte4(ReadOnlySpan{sbyte})" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static sbyte4 IComponentTuple<sbyte4, sbyte>.Create(ReadOnlySpan<sbyte> span) => new(span);
/// <inheritdoc />
public static sbyte4 UnitX => new(1, 0, 0, 0);
/// <inheritdoc />
public static sbyte4 UnitY => new(0, 1, 0, 0);
/// <inheritdoc />
public static sbyte4 UnitZ => new(0, 0, 1, 0);
/// <inheritdoc />
public static sbyte4 UnitW => new(0, 0, 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, out sbyte z, out sbyte w)
{
x = X;
y = Y;
z = Z;
w = W;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<sbyte> AsSpan()
{
return MemoryMarshal.CreateSpan(ref Unsafe.As<sbyte4, sbyte>(ref this), 4);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ReadOnlySpan<sbyte> AsReadOnlySpan()
{
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<sbyte4, sbyte>(ref Unsafe.AsRef(in this)), 4);
}
}

View file

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

View file

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

View file

@ -0,0 +1,438 @@
// <auto-generated /> - edit Vector.numerics.tt to modify
#nullable enable
namespace Brutal.Numerics;
// INumberBase
public partial struct sbyte4 : INumberBase<sbyte4>
{
/// <inheritdoc />
public static sbyte4 Zero => new(0);
/// <inheritdoc />
public static sbyte4 One => new(1);
static sbyte4 IAdditiveIdentity<sbyte4, sbyte4>.AdditiveIdentity => Zero;
static sbyte4 IMultiplicativeIdentity<sbyte4, sbyte4>.MultiplicativeIdentity => One;
static int INumberBase<sbyte4>.Radix => 2; // every component type is binary
/// <inheritdoc cref="Vector4.Abs" />
[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<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<sbyte4>.IsCanonical(sbyte4 value) => true;
static bool INumberBase<sbyte4>.IsComplexNumber(sbyte4 value) => false;
static bool INumberBase<sbyte4>.IsImaginaryNumber(sbyte4 value) => false;
/// <summary>Determines if every component of a value is zero.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<sbyte4>.IsZero(sbyte4 value)
{
return value == Zero;
}
/// <summary>Determines if every component of a value is an even integral value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<sbyte4>.IsEvenInteger(sbyte4 value)
{
return (value.X & 1) == 0 && (value.Y & 1) == 0 && (value.Z & 1) == 0 && (value.W & 1) == 0;
}
/// <summary>Determines if every component of a value is an odd integral value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<sbyte4>.IsOddInteger(sbyte4 value)
{
return (value.X & 1) == 1 && (value.Y & 1) == 1 && (value.Z & 1) == 1 && (value.W & 1) == 1;
}
/// <summary>Determines if every component of a value is negative.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<sbyte4>.IsNegative(sbyte4 value)
{
return value.X < 0 && value.Y < 0 && value.Z < 0 && value.W < 0;
}
/// <summary>Determines if every component of a value is positive.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<sbyte4>.IsPositive(sbyte4 value)
{
return value.X >= 0 && value.Y >= 0 && value.Z >= 0 && value.W >= 0;
}
static bool INumberBase<sbyte4>.IsFinite(sbyte4 value) => true;
static bool INumberBase<sbyte4>.IsInfinity(sbyte4 value) => false;
static bool INumberBase<sbyte4>.IsNegativeInfinity(sbyte4 value) => false;
static bool INumberBase<sbyte4>.IsPositiveInfinity(sbyte4 value) => false;
static bool INumberBase<sbyte4>.IsInteger(sbyte4 value) => true;
static bool INumberBase<sbyte4>.IsRealNumber(sbyte4 value) => true;
static bool INumberBase<sbyte4>.IsNaN(sbyte4 value) => false;
static bool INumberBase<sbyte4>.IsNormal(sbyte4 value) => value.X != 0 && value.Y != 0 && value.Z != 0 && value.W != 0;
static bool INumberBase<sbyte4>.IsSubnormal(sbyte4 value) => false;
/// <summary>Computes, componentwise, the value whose magnitude is greater.</summary>
[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));
}
/// <summary>Computes, componentwise, the value whose magnitude is greater.</summary>
[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));
}
/// <summary>Computes, componentwise, the value whose magnitude is smaller.</summary>
[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));
}
/// <summary>Computes, componentwise, the value whose magnitude is smaller.</summary>
[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));
}
/// <inheritdoc cref="Vector4.Add" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte4 Add(sbyte4 a, sbyte4 b)
{
return a + b;
}
/// <inheritdoc cref="Vector4.Divide(Vector4, Vector4)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte4 Divide(sbyte4 a, sbyte4 b)
{
return a / b;
}
/// <inheritdoc cref="Vector4.Multiply(Vector4, Vector4)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte4 Multiply(sbyte4 a, sbyte4 b)
{
return a * b;
}
/// <inheritdoc cref="Vector4.Negate" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte4 Negate(sbyte4 value)
{
return -value;
}
/// <inheritdoc cref="Vector4.Subtract" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte4 Subtract(sbyte4 a, sbyte4 b)
{
return a - b;
}
/// <inheritdoc />
[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));
}
/// <inheritdoc />
[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));
}
/// <inheritdoc />
[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));
}
/// <inheritdoc />
[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));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte4 operator -(sbyte4 a)
{
return new((sbyte)(-a.X), (sbyte)(-a.Y), (sbyte)(-a.Z), (sbyte)(-a.W));
}
/// <inheritdoc />
[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<sbyte4>.operator ++(sbyte4 value) => value + One;
static sbyte4 IDecrementOperators<sbyte4>.operator --(sbyte4 value) => value - One;
static bool INumberBase<sbyte4>.TryConvertFromChecked<TOther>(TOther value, out sbyte4 result)
{
return NumberConversion.TryConvertFrom<sbyte4, sbyte, TOther, NumberConversion.Checked>(value, out result);
}
static bool INumberBase<sbyte4>.TryConvertToChecked<TOther>(sbyte4 value, [MaybeNullWhen(false)] out TOther result)
{
result = default;
return false;
}
static bool INumberBase<sbyte4>.TryConvertFromSaturating<TOther>(TOther value, out sbyte4 result)
{
return NumberConversion.TryConvertFrom<sbyte4, sbyte, TOther, NumberConversion.Saturating>(value, out result);
}
static bool INumberBase<sbyte4>.TryConvertToSaturating<TOther>(sbyte4 value, [MaybeNullWhen(false)] out TOther result)
{
result = default;
return false;
}
static bool INumberBase<sbyte4>.TryConvertFromTruncating<TOther>(TOther value, out sbyte4 result)
{
return NumberConversion.TryConvertFrom<sbyte4, sbyte, TOther, NumberConversion.Truncating>(value, out result);
}
static bool INumberBase<sbyte4>.TryConvertToTruncating<TOther>(sbyte4 value, [MaybeNullWhen(false)] out TOther result)
{
result = default;
return false;
}
}
// IMultiplyOperators<TSelf, TComponent, TSelf>, IDivisionOperators<TSelf, TComponent, TSelf>
public partial struct sbyte4
: IMultiplyOperators<sbyte4, sbyte, sbyte4>
, IDivisionOperators<sbyte4, sbyte, sbyte4>
{
/// <inheritdoc cref="Vector4.Divide(Vector4, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte4 Divide(sbyte4 a, sbyte b)
{
return a / b;
}
/// <inheritdoc cref="Vector4.Multiply(Vector4, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte4 Multiply(sbyte4 a, sbyte b)
{
return a * b;
}
/// <inheritdoc cref="Vector4.Multiply(float, Vector4)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte4 Multiply(sbyte a, sbyte4 b)
{
return a * b;
}
/// <inheritdoc />
[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));
}
/// <inheritdoc />
[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));
}
/// <inheritdoc />
[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<sbyte4>
{
/// <inheritdoc cref="Vector4.Clamp" />
[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);
}
/// <inheritdoc cref="Vector4.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));
}
/// <inheritdoc cref="Vector4.Min" />
[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<sbyte4>.MaxNumber(sbyte4 a, sbyte4 b) => Max(a, b);
static sbyte4 INumber<sbyte4>.MinNumber(sbyte4 a, sbyte4 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 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<sbyte4>.ClampNative(sbyte4 value, sbyte4 min, sbyte4 max) => Clamp(value, min, max);
static sbyte4 INumber<sbyte4>.MaxNative(sbyte4 a, sbyte4 b) => Max(a, b);
static sbyte4 INumber<sbyte4>.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<sbyte4>.Sign(sbyte4 value) =>
throw new NotSupportedException($"{nameof(sbyte4)} has no scalar sign.");
/// <inheritdoc />
[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<sbyte4>.CompareTo(sbyte4 other) =>
throw new NotSupportedException($"{nameof(sbyte4)} has no total order.");
static bool IComparisonOperators<sbyte4, sbyte4, bool>.operator <(sbyte4 a, sbyte4 b) =>
throw new NotSupportedException($"{nameof(sbyte4)} has no total order.");
static bool IComparisonOperators<sbyte4, sbyte4, bool>.operator <=(sbyte4 a, sbyte4 b) =>
throw new NotSupportedException($"{nameof(sbyte4)} has no total order.");
static bool IComparisonOperators<sbyte4, sbyte4, bool>.operator >(sbyte4 a, sbyte4 b) =>
throw new NotSupportedException($"{nameof(sbyte4)} has no total order.");
static bool IComparisonOperators<sbyte4, sbyte4, bool>.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<sbyte4, bool4>
{
/// <inheritdoc />
[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);
}
/// <inheritdoc />
[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);
}
/// <inheritdoc />
[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);
}
/// <inheritdoc />
[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);
}
/// <summary>Determines which components of a value are zero.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool4 IsZero(sbyte4 value)
{
return new bool4(value.X == 0, value.Y == 0, value.Z == 0, value.W == 0);
}
/// <summary>Determines which components of a value are an even integral value.</summary>
[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));
}
/// <summary>Determines which components of a value are an odd integral value.</summary>
[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));
}
/// <summary>Determines which components of a value are negative.</summary>
[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));
}
/// <summary>Determines which components of a value are positive.</summary>
[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<sbyte4>
{
/// <inheritdoc />
public static sbyte4 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 sbyte4
{
public static sbyte4 Pack(in byte4 vector, Func<byte, sbyte> elementConverter)
{
VectorPack.Pack(vector, out sbyte4 result, elementConverter);
return result;
}
public static sbyte4 Pack(in short4 vector, Func<short, sbyte> elementConverter)
{
VectorPack.Pack(vector, out sbyte4 result, elementConverter);
return result;
}
public static sbyte4 Pack(in ushort4 vector, Func<ushort, sbyte> elementConverter)
{
VectorPack.Pack(vector, out sbyte4 result, elementConverter);
return result;
}
public static sbyte4 Pack(in int4 vector, Func<int, sbyte> elementConverter)
{
VectorPack.Pack(vector, out sbyte4 result, elementConverter);
return result;
}
public static sbyte4 Pack(in uint4 vector, Func<uint, sbyte> elementConverter)
{
VectorPack.Pack(vector, out sbyte4 result, elementConverter);
return result;
}
public static sbyte4 Pack(in float4 vector, Func<float, sbyte> elementConverter)
{
VectorPack.Pack(vector, out sbyte4 result, elementConverter);
return result;
}
public static sbyte4 Pack(in double4 vector, Func<double, sbyte> elementConverter)
{
VectorPack.Pack(vector, out sbyte4 result, elementConverter);
return result;
}
public static sbyte4 Pack(in byte4 vector, Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast)
{
return Pack(vector, PackUtils.Byte.ToSByte(mode));
}
public static sbyte4 Pack(in short4 vector, Pack.Integer mode = Numerics.Pack.Integer.Cast)
{
return Pack(vector, PackUtils.Short.ToSByte(mode));
}
public static sbyte4 Pack(in ushort4 vector, Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast)
{
return Pack(vector, PackUtils.UShort.ToSByte(mode));
}
public static sbyte4 Pack(in int4 vector, Pack.Integer mode = Numerics.Pack.Integer.Cast)
{
return Pack(vector, PackUtils.Int.ToSByte(mode));
}
public static sbyte4 Pack(in uint4 vector, Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast)
{
return Pack(vector, PackUtils.UInt.ToSByte(mode));
}
public static sbyte4 Pack(in float4 vector, Pack.Float mode = Numerics.Pack.Float.Truncate)
{
return Pack(vector, PackUtils.Float.ToSByte(mode));
}
public static sbyte4 Pack(in double4 vector, Pack.Float mode = Numerics.Pack.Float.Truncate)
{
return Pack(vector, PackUtils.Double.ToSByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<byte4> source,
Span<sbyte4> destination,
Func<byte, sbyte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<short4> source,
Span<sbyte4> destination,
Func<short, sbyte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<ushort4> source,
Span<sbyte4> destination,
Func<ushort, sbyte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<int4> source,
Span<sbyte4> destination,
Func<int, sbyte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<uint4> source,
Span<sbyte4> destination,
Func<uint, sbyte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<float4> source,
Span<sbyte4> destination,
Func<float, sbyte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<double4> source,
Span<sbyte4> destination,
Func<double, sbyte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<byte4> source,
Span<sbyte4> destination,
Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast
)
{
PackSpan(source, destination, PackUtils.Byte.ToSByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<short4> source,
Span<sbyte4> destination,
Pack.Integer mode = Numerics.Pack.Integer.Cast
)
{
PackSpan(source, destination, PackUtils.Short.ToSByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<ushort4> source,
Span<sbyte4> destination,
Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast
)
{
PackSpan(source, destination, PackUtils.UShort.ToSByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<int4> source,
Span<sbyte4> destination,
Pack.Integer mode = Numerics.Pack.Integer.Cast
)
{
PackSpan(source, destination, PackUtils.Int.ToSByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<uint4> source,
Span<sbyte4> destination,
Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast
)
{
PackSpan(source, destination, PackUtils.UInt.ToSByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<float4> source,
Span<sbyte4> destination,
Pack.Float mode = Numerics.Pack.Float.Truncate
)
{
PackSpan(source, destination, PackUtils.Float.ToSByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<double4> source,
Span<sbyte4> destination,
Pack.Float mode = Numerics.Pack.Float.Truncate
)
{
PackSpan(source, destination, PackUtils.Double.ToSByte(mode));
}
}

File diff suppressed because it is too large Load diff