Skip to content

[API Proposal]: INumberBase.MinValue and INumberBase.MaxValue #115821

Closed as not planned
@eduherminio

Description

@eduherminio

Background and motivation

When having to initialize T : INumberBase<T> to some default values, theres T.Zero and T.One, but not min and max values.

Unless I'm missing the existence of an interface that has them, maybe INumberBase<T> is a good one to add it.

API Proposal

namespace System.Numerics;

public interface INumberBase<TSelf>
{
    static abstract TSelf MinValue { get; }

    static abstract TSelf MaxValue { get; }
}

API Usage

internal sealed class SPSAAttribute<T> : Attribute
     where T : INumberBase<T>, IMultiplyOperators<T, T, T>, IConvertible, IParsable<T>, ISpanParsable<T>, IDivisionOperators<T, T, T>
{
    public T MinValue { get; }
    public T MaxValue { get; }

    SPSAAttribute()
    {
        MinValue = T.MinValue;
        MaxValue = T.MaxValue;
    }
}

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions