brutal/brutal.numerics/Brutal.Numerics/Vector/short4/short4.numerics.gen.cs
2026-10-15 14:12:02 +13:00

438 lines
17 KiB
C#

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