Skip to content

Add System.Math API overloads for nint/nuint #43733

@Sergio0694

Description

@Sergio0694

Background and Motivation

C# 9 includes the new nint/nuint types, but it gets pretty awkward to use them in code that was previously using Math APIs such as Min or Max. This proposal is about adding overloads for the int/uint APIs in System.Math to support nint/nuint.

Right now you either have to manually write ternary operators everywhere to work around this, or just stick with int/uint.

Proposed API

namespace System
{
    public static class Math
    {
        public static nint Abs(nint value);
        public static nuint Clamp(nuint value, nuint min, nuint max);
        public static nint Clamp(nint value, nint min, nint max);
        public static nint DivRem(nint a, nint b, out nint result);
        public static nint Max(nint val1, nint val2);
        public static nuint Max(nuint val1, nuint val2);
        public static nint Min(nint val1, nint val2);
        public static nuint Min(nuint val1, nuint val2);
        public static nint Sign(nint value);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions