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