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