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