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