Skip to content

Expose floating-point constants for generic Vector types using extension propertiesΒ #117569

@tannergooding

Description

@tannergooding

Proposal

We approved exposing the various generic math APIs on the vector types as part of #93513. However, at the time there was no way to define the floating-point constants on the generic vector types.

Due to the introduction of extension properties, this is now feasible and should be done for completeness and to help improve codegen, readability, and maintainability for the scenarios that need it.

namespace System.Numerics
{
    public static partial class Vector
    {
        extension<T>(Vector<T>)
            where T : IFloatingPointConstants<T>
        {
            public static Vector<T> Epsilon { get; }
            public static Vector<T> NaN { get; }
            public static Vector<T> NegativeInfinity { get; }
            public static Vector<T> NegativeZero { get; }
            public static Vector<T> PositiveInfinity { get; }
            public static Vector<T> E { get; }
            public static Vector<T> Pi { get; }
            public static Vector<T> Tau { get; }
        }
    }
}

namespace System.Runtime.Intrinsics
{
    public static partial class Vector128
    {
        extension<T>(Vector128<T>)
            where T : IFloatingPointConstants<T>
        {
            public static Vector128<T> Epsilon { get; }
            public static Vector128<T> NaN { get; }
            public static Vector128<T> NegativeInfinity { get; }
            public static Vector128<T> NegativeZero { get; }
            public static Vector128<T> PositiveInfinity { get; }
            public static Vector128<T> E { get; }
            public static Vector128<T> Pi { get; }
            public static Vector128<T> Tau { get; }
        }
    }

    public static partial class Vector256
    {
        extension<T>(Vector256<T>)
            where T : IFloatingPointConstants<T>
        {
            public static Vector256<T> Epsilon { get; }
            public static Vector256<T> NaN { get; }
            public static Vector256<T> NegativeInfinity { get; }
            public static Vector256<T> NegativeZero { get; }
            public static Vector256<T> PositiveInfinity { get; }
            public static Vector256<T> E { get; }
            public static Vector256<T> Pi { get; }
            public static Vector256<T> Tau { get; }
        }
    }

    public static partial class Vector512
    {
        extension<T>(Vector512<T>)
            where T : IFloatingPointConstants<T>
        {
            public static Vector512<T> Epsilon { get; }
            public static Vector512<T> NaN { get; }
            public static Vector512<T> NegativeInfinity { get; }
            public static Vector512<T> NegativeZero { get; }
            public static Vector512<T> PositiveInfinity { get; }
            public static Vector512<T> E { get; }
            public static Vector512<T> Pi { get; }
            public static Vector512<T> Tau { get; }
        }
    }

    public static partial class Vector64
    {
        extension<T>(Vector64<T>)
            where T : IFloatingPointConstants<T>
        {
            public static Vector64<T> Epsilon { get; }
            public static Vector64<T> NaN { get; }
            public static Vector64<T> NegativeInfinity { get; }
            public static Vector64<T> NegativeZero { get; }
            public static Vector64<T> PositiveInfinity { get; }
            public static Vector64<T> E { get; }
            public static Vector64<T> Pi { get; }
            public static Vector64<T> Tau { get; }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions