diff --git a/src/libraries/System.Private.CoreLib/src/System/Byte.cs b/src/libraries/System.Private.CoreLib/src/System/Byte.cs index db536b1752291..21ceb866f794f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Byte.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Byte.cs @@ -531,6 +531,63 @@ bool IBinaryInteger.TryWriteLittleEndian(Span destination, out int b /// static byte INumberBase.Abs(byte value) => value; + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static byte CreateChecked(TOther value) + where TOther : INumberBase + { + byte result; + + if (typeof(TOther) == typeof(byte)) + { + result = (byte)(object)value; + } + else if (!TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static byte CreateSaturating(TOther value) + where TOther : INumberBase + { + byte result; + + if (typeof(TOther) == typeof(byte)) + { + result = (byte)(object)value; + } + else if (!TryConvertFromSaturating(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static byte CreateTruncating(TOther value) + where TOther : INumberBase + { + byte result; + + if (typeof(TOther) == typeof(byte)) + { + result = (byte)(object)value; + } + else if (!TryConvertFromTruncating(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(byte value) => true; @@ -596,7 +653,11 @@ bool IBinaryInteger.TryWriteLittleEndian(Span destination, out int b /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromChecked(TOther value, out byte result) + static bool INumberBase.TryConvertFromChecked(TOther value, out byte result) => TryConvertFromChecked(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromChecked(TOther value, out byte result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -658,7 +719,11 @@ static bool INumberBase.TryConvertFromChecked(TOther value, out by /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromSaturating(TOther value, out byte result) + static bool INumberBase.TryConvertFromSaturating(TOther value, out byte result) => TryConvertFromSaturating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromSaturating(TOther value, out byte result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -721,7 +786,11 @@ static bool INumberBase.TryConvertFromSaturating(TOther value, out /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromTruncating(TOther value, out byte result) + static bool INumberBase.TryConvertFromTruncating(TOther value, out byte result) => TryConvertFromTruncating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromTruncating(TOther value, out byte result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and diff --git a/src/libraries/System.Private.CoreLib/src/System/Decimal.cs b/src/libraries/System.Private.CoreLib/src/System/Decimal.cs index 161da75bcb930..a435ab3939021 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Decimal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Decimal.cs @@ -1309,6 +1309,63 @@ public static decimal Abs(decimal value) return new decimal(in value, value._flags & ~SignMask); } + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal CreateChecked(TOther value) + where TOther : INumberBase + { + decimal result; + + if (typeof(TOther) == typeof(decimal)) + { + result = (decimal)(object)value; + } + else if (!TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal CreateSaturating(TOther value) + where TOther : INumberBase + { + decimal result; + + if (typeof(TOther) == typeof(decimal)) + { + result = (decimal)(object)value; + } + else if (!TryConvertFrom(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal CreateTruncating(TOther value) + where TOther : INumberBase + { + decimal result; + + if (typeof(TOther) == typeof(decimal)) + { + result = (decimal)(object)value; + } + else if (!TryConvertFrom(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// public static bool IsCanonical(decimal value) { @@ -1434,7 +1491,11 @@ public static decimal MinMagnitude(decimal x, decimal y) /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromChecked(TOther value, out decimal result) + static bool INumberBase.TryConvertFromChecked(TOther value, out decimal result) => TryConvertFromChecked(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromChecked(TOther value, out decimal result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and diff --git a/src/libraries/System.Private.CoreLib/src/System/Double.cs b/src/libraries/System.Private.CoreLib/src/System/Double.cs index 35fb97837ee38..943bae62720ae 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Double.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Double.cs @@ -995,6 +995,63 @@ public static double MinNumber(double x, double y) /// public static double Abs(double value) => Math.Abs(value); + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double CreateChecked(TOther value) + where TOther : INumberBase + { + double result; + + if (typeof(TOther) == typeof(double)) + { + result = (double)(object)value; + } + else if (!TryConvertFrom(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double CreateSaturating(TOther value) + where TOther : INumberBase + { + double result; + + if (typeof(TOther) == typeof(double)) + { + result = (double)(object)value; + } + else if (!TryConvertFrom(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double CreateTruncating(TOther value) + where TOther : INumberBase + { + double result; + + if (typeof(TOther) == typeof(double)) + { + result = (double)(object)value; + } + else if (!TryConvertFrom(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(double value) => true; diff --git a/src/libraries/System.Private.CoreLib/src/System/Half.cs b/src/libraries/System.Private.CoreLib/src/System/Half.cs index 5032b484a4ac7..3d2262294f437 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Half.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Half.cs @@ -1433,6 +1433,63 @@ public static Half MinNumber(Half x, Half y) /// public static Half Abs(Half value) => (Half)MathF.Abs((float)value); + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Half CreateChecked(TOther value) + where TOther : INumberBase + { + Half result; + + if (typeof(TOther) == typeof(Half)) + { + result = (Half)(object)value; + } + else if (!TryConvertFrom(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Half CreateSaturating(TOther value) + where TOther : INumberBase + { + Half result; + + if (typeof(TOther) == typeof(Half)) + { + result = (Half)(object)value; + } + else if (!TryConvertFrom(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Half CreateTruncating(TOther value) + where TOther : INumberBase + { + Half result; + + if (typeof(TOther) == typeof(Half)) + { + result = (Half)(object)value; + } + else if (!TryConvertFrom(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(Half value) => true; diff --git a/src/libraries/System.Private.CoreLib/src/System/Int128.cs b/src/libraries/System.Private.CoreLib/src/System/Int128.cs index aca3c8199100a..ceadb7cc03f8b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Int128.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Int128.cs @@ -1280,6 +1280,63 @@ public static Int128 Abs(Int128 value) return value; } + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Int128 CreateChecked(TOther value) + where TOther : INumberBase + { + Int128 result; + + if (typeof(TOther) == typeof(Int128)) + { + result = (Int128)(object)value; + } + else if (!TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Int128 CreateSaturating(TOther value) + where TOther : INumberBase + { + Int128 result; + + if (typeof(TOther) == typeof(Int128)) + { + result = (Int128)(object)value; + } + else if (!TryConvertFromSaturating(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Int128 CreateTruncating(TOther value) + where TOther : INumberBase + { + Int128 result; + + if (typeof(TOther) == typeof(Int128)) + { + result = (Int128)(object)value; + } + else if (!TryConvertFromTruncating(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(Int128 value) => true; @@ -1419,7 +1476,11 @@ public static Int128 MinMagnitude(Int128 x, Int128 y) /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromChecked(TOther value, out Int128 result) + static bool INumberBase.TryConvertFromChecked(TOther value, out Int128 result) => TryConvertFromChecked(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromChecked(TOther value, out Int128 result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -1487,7 +1548,11 @@ static bool INumberBase.TryConvertFromChecked(TOther value, out /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromSaturating(TOther value, out Int128 result) + static bool INumberBase.TryConvertFromSaturating(TOther value, out Int128 result) => TryConvertFromSaturating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromSaturating(TOther value, out Int128 result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -1558,7 +1623,11 @@ static bool INumberBase.TryConvertFromSaturating(TOther value, o /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromTruncating(TOther value, out Int128 result) + static bool INumberBase.TryConvertFromTruncating(TOther value, out Int128 result) => TryConvertFromTruncating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromTruncating(TOther value, out Int128 result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and diff --git a/src/libraries/System.Private.CoreLib/src/System/Int16.cs b/src/libraries/System.Private.CoreLib/src/System/Int16.cs index e59356033a874..c4006e3bb9832 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Int16.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Int16.cs @@ -577,6 +577,63 @@ public static short CopySign(short value, short sign) /// public static short Abs(short value) => Math.Abs(value); + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static short CreateChecked(TOther value) + where TOther : INumberBase + { + short result; + + if (typeof(TOther) == typeof(short)) + { + result = (short)(object)value; + } + else if (!TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static short CreateSaturating(TOther value) + where TOther : INumberBase + { + short result; + + if (typeof(TOther) == typeof(short)) + { + result = (short)(object)value; + } + else if (!TryConvertFromSaturating(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static short CreateTruncating(TOther value) + where TOther : INumberBase + { + short result; + + if (typeof(TOther) == typeof(short)) + { + result = (short)(object)value; + } + else if (!TryConvertFromTruncating(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(short value) => true; @@ -716,7 +773,11 @@ public static short MinMagnitude(short x, short y) /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromChecked(TOther value, out short result) + static bool INumberBase.TryConvertFromChecked(TOther value, out short result) => TryConvertFromChecked(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromChecked(TOther value, out short result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -784,7 +845,11 @@ static bool INumberBase.TryConvertFromChecked(TOther value, out s /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromSaturating(TOther value, out short result) + static bool INumberBase.TryConvertFromSaturating(TOther value, out short result) => TryConvertFromSaturating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromSaturating(TOther value, out short result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -859,7 +924,11 @@ static bool INumberBase.TryConvertFromSaturating(TOther value, ou /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromTruncating(TOther value, out short result) + static bool INumberBase.TryConvertFromTruncating(TOther value, out short result) => TryConvertFromTruncating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromTruncating(TOther value, out short result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and diff --git a/src/libraries/System.Private.CoreLib/src/System/Int32.cs b/src/libraries/System.Private.CoreLib/src/System/Int32.cs index 80caf14b548e3..f2797747e2007 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Int32.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Int32.cs @@ -569,6 +569,63 @@ public static int CopySign(int value, int sign) /// public static int Abs(int value) => Math.Abs(value); + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CreateChecked(TOther value) + where TOther : INumberBase + { + int result; + + if (typeof(TOther) == typeof(int)) + { + result = (int)(object)value; + } + else if (!TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CreateSaturating(TOther value) + where TOther : INumberBase + { + int result; + + if (typeof(TOther) == typeof(int)) + { + result = (int)(object)value; + } + else if (!TryConvertFromSaturating(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CreateTruncating(TOther value) + where TOther : INumberBase + { + int result; + + if (typeof(TOther) == typeof(int)) + { + result = (int)(object)value; + } + else if (!TryConvertFromTruncating(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(int value) => true; @@ -708,7 +765,11 @@ public static int MinMagnitude(int x, int y) /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromChecked(TOther value, out int result) + static bool INumberBase.TryConvertFromChecked(TOther value, out int result) => TryConvertFromChecked(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromChecked(TOther value, out int result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -776,7 +837,11 @@ static bool INumberBase.TryConvertFromChecked(TOther value, out int /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromSaturating(TOther value, out int result) + static bool INumberBase.TryConvertFromSaturating(TOther value, out int result) => TryConvertFromSaturating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromSaturating(TOther value, out int result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -850,7 +915,11 @@ static bool INumberBase.TryConvertFromSaturating(TOther value, out /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromTruncating(TOther value, out int result) + static bool INumberBase.TryConvertFromTruncating(TOther value, out int result) => TryConvertFromTruncating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromTruncating(TOther value, out int result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and diff --git a/src/libraries/System.Private.CoreLib/src/System/Int64.cs b/src/libraries/System.Private.CoreLib/src/System/Int64.cs index dd12ad83844a7..91d37036cdc56 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Int64.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Int64.cs @@ -556,6 +556,63 @@ public static long CopySign(long value, long sign) /// public static long Abs(long value) => Math.Abs(value); + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long CreateChecked(TOther value) + where TOther : INumberBase + { + long result; + + if (typeof(TOther) == typeof(long)) + { + result = (long)(object)value; + } + else if (!TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long CreateSaturating(TOther value) + where TOther : INumberBase + { + long result; + + if (typeof(TOther) == typeof(long)) + { + result = (long)(object)value; + } + else if (!TryConvertFromSaturating(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long CreateTruncating(TOther value) + where TOther : INumberBase + { + long result; + + if (typeof(TOther) == typeof(long)) + { + result = (long)(object)value; + } + else if (!TryConvertFromTruncating(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(long value) => true; @@ -695,7 +752,11 @@ public static long MinMagnitude(long x, long y) /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromChecked(TOther value, out long result) + static bool INumberBase.TryConvertFromChecked(TOther value, out long result) => TryConvertFromChecked(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromChecked(TOther value, out long result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -763,7 +824,11 @@ static bool INumberBase.TryConvertFromChecked(TOther value, out lo /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromSaturating(TOther value, out long result) + static bool INumberBase.TryConvertFromSaturating(TOther value, out long result) => TryConvertFromSaturating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromSaturating(TOther value, out long result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -835,7 +900,11 @@ static bool INumberBase.TryConvertFromSaturating(TOther value, out /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromTruncating(TOther value, out long result) + static bool INumberBase.TryConvertFromTruncating(TOther value, out long result) => TryConvertFromTruncating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromTruncating(TOther value, out long result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and diff --git a/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs b/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs index daedfb8f659cd..54f9c8c1a5377 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs @@ -529,6 +529,63 @@ public static nint CopySign(nint value, nint sign) /// public static nint Abs(nint value) => Math.Abs(value); + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint CreateChecked(TOther value) + where TOther : INumberBase + { + nint result; + + if (typeof(TOther) == typeof(nint)) + { + result = (nint)(object)value; + } + else if (!TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint CreateSaturating(TOther value) + where TOther : INumberBase + { + nint result; + + if (typeof(TOther) == typeof(nint)) + { + result = (nint)(object)value; + } + else if (!TryConvertFromSaturating(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint CreateTruncating(TOther value) + where TOther : INumberBase + { + nint result; + + if (typeof(TOther) == typeof(nint)) + { + result = (nint)(object)value; + } + else if (!TryConvertFromTruncating(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(nint value) => true; @@ -668,7 +725,11 @@ public static nint MinMagnitude(nint x, nint y) /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromChecked(TOther value, out nint result) + static bool INumberBase.TryConvertFromChecked(TOther value, out nint result) => TryConvertFromChecked(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromChecked(TOther value, out nint result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -736,7 +797,11 @@ static bool INumberBase.TryConvertFromChecked(TOther value, out ni /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromSaturating(TOther value, out nint result) + static bool INumberBase.TryConvertFromSaturating(TOther value, out nint result) => TryConvertFromSaturating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromSaturating(TOther value, out nint result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -809,7 +874,11 @@ static bool INumberBase.TryConvertFromSaturating(TOther value, out /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromTruncating(TOther value, out nint result) + static bool INumberBase.TryConvertFromTruncating(TOther value, out nint result) => TryConvertFromTruncating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromTruncating(TOther value, out nint result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs index 6f2da86fb61c5..04c9fd48ab85a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs @@ -1258,6 +1258,63 @@ bool IFloatingPoint.TryWriteSignificandLittleEndian(Span destinati /// public static NFloat Abs(NFloat value) => new NFloat(NativeType.Abs(value._value)); + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static NFloat CreateChecked(TOther value) + where TOther : INumberBase + { + NFloat result; + + if (typeof(TOther) == typeof(NFloat)) + { + result = (NFloat)(object)value; + } + else if (!TryConvertFrom(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static NFloat CreateSaturating(TOther value) + where TOther : INumberBase + { + NFloat result; + + if (typeof(TOther) == typeof(NFloat)) + { + result = (NFloat)(object)value; + } + else if (!TryConvertFrom(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static NFloat CreateTruncating(TOther value) + where TOther : INumberBase + { + NFloat result; + + if (typeof(TOther) == typeof(NFloat)) + { + result = (NFloat)(object)value; + } + else if (!TryConvertFrom(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(NFloat value) => true; diff --git a/src/libraries/System.Private.CoreLib/src/System/SByte.cs b/src/libraries/System.Private.CoreLib/src/System/SByte.cs index d84b767eb7e52..005bff2776819 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SByte.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SByte.cs @@ -584,6 +584,63 @@ public static sbyte CopySign(sbyte value, sbyte sign) /// public static sbyte Abs(sbyte value) => Math.Abs(value); + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static sbyte CreateChecked(TOther value) + where TOther : INumberBase + { + sbyte result; + + if (typeof(TOther) == typeof(sbyte)) + { + result = (sbyte)(object)value; + } + else if (!TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static sbyte CreateSaturating(TOther value) + where TOther : INumberBase + { + sbyte result; + + if (typeof(TOther) == typeof(sbyte)) + { + result = (sbyte)(object)value; + } + else if (!TryConvertFromSaturating(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static sbyte CreateTruncating(TOther value) + where TOther : INumberBase + { + sbyte result; + + if (typeof(TOther) == typeof(sbyte)) + { + result = (sbyte)(object)value; + } + else if (!TryConvertFromTruncating(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(sbyte value) => true; @@ -723,7 +780,11 @@ public static sbyte MinMagnitude(sbyte x, sbyte y) /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromChecked(TOther value, out sbyte result) + static bool INumberBase.TryConvertFromChecked(TOther value, out sbyte result) => TryConvertFromChecked(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromChecked(TOther value, out sbyte result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -791,7 +852,11 @@ static bool INumberBase.TryConvertFromChecked(TOther value, out s /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromSaturating(TOther value, out sbyte result) + static bool INumberBase.TryConvertFromSaturating(TOther value, out sbyte result) => TryConvertFromSaturating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromSaturating(TOther value, out sbyte result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -867,7 +932,11 @@ static bool INumberBase.TryConvertFromSaturating(TOther value, ou /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromTruncating(TOther value, out sbyte result) + static bool INumberBase.TryConvertFromTruncating(TOther value, out sbyte result) => TryConvertFromTruncating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromTruncating(TOther value, out sbyte result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and diff --git a/src/libraries/System.Private.CoreLib/src/System/Single.cs b/src/libraries/System.Private.CoreLib/src/System/Single.cs index d3fc519475dbc..f9aef99c7305d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Single.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Single.cs @@ -975,6 +975,63 @@ public static float MinNumber(float x, float y) /// public static float Abs(float value) => MathF.Abs(value); + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float CreateChecked(TOther value) + where TOther : INumberBase + { + float result; + + if (typeof(TOther) == typeof(float)) + { + result = (float)(object)value; + } + else if (!TryConvertFrom(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float CreateSaturating(TOther value) + where TOther : INumberBase + { + float result; + + if (typeof(TOther) == typeof(float)) + { + result = (float)(object)value; + } + else if (!TryConvertFrom(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float CreateTruncating(TOther value) + where TOther : INumberBase + { + float result; + + if (typeof(TOther) == typeof(float)) + { + result = (float)(object)value; + } + else if (!TryConvertFrom(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(float value) => true; diff --git a/src/libraries/System.Private.CoreLib/src/System/UInt128.cs b/src/libraries/System.Private.CoreLib/src/System/UInt128.cs index 1ed4e3419af0e..0d0fc3cf3cd96 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UInt128.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UInt128.cs @@ -1358,6 +1358,63 @@ public static UInt128 Clamp(UInt128 value, UInt128 min, UInt128 max) /// static UInt128 INumberBase.Abs(UInt128 value) => value; + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static UInt128 CreateChecked(TOther value) + where TOther : INumberBase + { + UInt128 result; + + if (typeof(TOther) == typeof(UInt128)) + { + result = (UInt128)(object)value; + } + else if (!TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static UInt128 CreateSaturating(TOther value) + where TOther : INumberBase + { + UInt128 result; + + if (typeof(TOther) == typeof(UInt128)) + { + result = (UInt128)(object)value; + } + else if (!TryConvertFromSaturating(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static UInt128 CreateTruncating(TOther value) + where TOther : INumberBase + { + UInt128 result; + + if (typeof(TOther) == typeof(UInt128)) + { + result = (UInt128)(object)value; + } + else if (!TryConvertFromTruncating(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(UInt128 value) => true; @@ -1423,7 +1480,11 @@ public static UInt128 Clamp(UInt128 value, UInt128 min, UInt128 max) /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromChecked(TOther value, out UInt128 result) + static bool INumberBase.TryConvertFromChecked(TOther value, out UInt128 result) => TryConvertFromChecked(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromChecked(TOther value, out UInt128 result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -1485,7 +1546,11 @@ static bool INumberBase.TryConvertFromChecked(TOther value, out /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromSaturating(TOther value, out UInt128 result) + static bool INumberBase.TryConvertFromSaturating(TOther value, out UInt128 result) => TryConvertFromSaturating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromSaturating(TOther value, out UInt128 result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -1547,7 +1612,11 @@ static bool INumberBase.TryConvertFromSaturating(TOther value, /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromTruncating(TOther value, out UInt128 result) + static bool INumberBase.TryConvertFromTruncating(TOther value, out UInt128 result) => TryConvertFromTruncating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromTruncating(TOther value, out UInt128 result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and diff --git a/src/libraries/System.Private.CoreLib/src/System/UInt16.cs b/src/libraries/System.Private.CoreLib/src/System/UInt16.cs index 63c395b2b633b..0a09a77143103 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UInt16.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UInt16.cs @@ -526,6 +526,63 @@ bool IBinaryInteger.TryWriteLittleEndian(Span destination, out int /// static ushort INumberBase.Abs(ushort value) => value; + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ushort CreateChecked(TOther value) + where TOther : INumberBase + { + ushort result; + + if (typeof(TOther) == typeof(ushort)) + { + result = (ushort)(object)value; + } + else if (!TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ushort CreateSaturating(TOther value) + where TOther : INumberBase + { + ushort result; + + if (typeof(TOther) == typeof(ushort)) + { + result = (ushort)(object)value; + } + else if (!TryConvertFromSaturating(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ushort CreateTruncating(TOther value) + where TOther : INumberBase + { + ushort result; + + if (typeof(TOther) == typeof(ushort)) + { + result = (ushort)(object)value; + } + else if (!TryConvertFromTruncating(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(ushort value) => true; @@ -591,7 +648,11 @@ bool IBinaryInteger.TryWriteLittleEndian(Span destination, out int /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromChecked(TOther value, out ushort result) + static bool INumberBase.TryConvertFromChecked(TOther value, out ushort result) => TryConvertFromChecked(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromChecked(TOther value, out ushort result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -653,7 +714,11 @@ static bool INumberBase.TryConvertFromChecked(TOther value, out /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromSaturating(TOther value, out ushort result) + static bool INumberBase.TryConvertFromSaturating(TOther value, out ushort result) => TryConvertFromSaturating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromSaturating(TOther value, out ushort result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -716,7 +781,11 @@ static bool INumberBase.TryConvertFromSaturating(TOther value, o /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromTruncating(TOther value, out ushort result) + static bool INumberBase.TryConvertFromTruncating(TOther value, out ushort result) => TryConvertFromTruncating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromTruncating(TOther value, out ushort result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and diff --git a/src/libraries/System.Private.CoreLib/src/System/UInt32.cs b/src/libraries/System.Private.CoreLib/src/System/UInt32.cs index 4d1ea8358def2..5f2b69890d74b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UInt32.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UInt32.cs @@ -512,6 +512,63 @@ bool IBinaryInteger.TryWriteLittleEndian(Span destination, out int b /// static uint INumberBase.Abs(uint value) => value; + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static uint CreateChecked(TOther value) + where TOther : INumberBase + { + uint result; + + if (typeof(TOther) == typeof(uint)) + { + result = (uint)(object)value; + } + else if (!TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static uint CreateSaturating(TOther value) + where TOther : INumberBase + { + uint result; + + if (typeof(TOther) == typeof(uint)) + { + result = (uint)(object)value; + } + else if (!TryConvertFromSaturating(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static uint CreateTruncating(TOther value) + where TOther : INumberBase + { + uint result; + + if (typeof(TOther) == typeof(uint)) + { + result = (uint)(object)value; + } + else if (!TryConvertFromTruncating(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(uint value) => true; @@ -577,7 +634,11 @@ bool IBinaryInteger.TryWriteLittleEndian(Span destination, out int b /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromChecked(TOther value, out uint result) + static bool INumberBase.TryConvertFromChecked(TOther value, out uint result) => TryConvertFromChecked(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromChecked(TOther value, out uint result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -639,7 +700,11 @@ static bool INumberBase.TryConvertFromChecked(TOther value, out ui /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromSaturating(TOther value, out uint result) + static bool INumberBase.TryConvertFromSaturating(TOther value, out uint result) => TryConvertFromSaturating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromSaturating(TOther value, out uint result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -702,7 +767,11 @@ static bool INumberBase.TryConvertFromSaturating(TOther value, out /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromTruncating(TOther value, out uint result) + static bool INumberBase.TryConvertFromTruncating(TOther value, out uint result) => TryConvertFromTruncating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromTruncating(TOther value, out uint result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and diff --git a/src/libraries/System.Private.CoreLib/src/System/UInt64.cs b/src/libraries/System.Private.CoreLib/src/System/UInt64.cs index 300dc4614f630..a1082b907a6f3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UInt64.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UInt64.cs @@ -511,6 +511,63 @@ bool IBinaryInteger.TryWriteLittleEndian(Span destination, out int /// static ulong INumberBase.Abs(ulong value) => value; + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ulong CreateChecked(TOther value) + where TOther : INumberBase + { + ulong result; + + if (typeof(TOther) == typeof(ulong)) + { + result = (ulong)(object)value; + } + else if (!TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ulong CreateSaturating(TOther value) + where TOther : INumberBase + { + ulong result; + + if (typeof(TOther) == typeof(ulong)) + { + result = (ulong)(object)value; + } + else if (!TryConvertFromSaturating(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ulong CreateTruncating(TOther value) + where TOther : INumberBase + { + ulong result; + + if (typeof(TOther) == typeof(ulong)) + { + result = (ulong)(object)value; + } + else if (!TryConvertFromTruncating(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(ulong value) => true; @@ -576,7 +633,11 @@ bool IBinaryInteger.TryWriteLittleEndian(Span destination, out int /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromChecked(TOther value, out ulong result) + static bool INumberBase.TryConvertFromChecked(TOther value, out ulong result) => TryConvertFromChecked(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromChecked(TOther value, out ulong result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -638,7 +699,11 @@ static bool INumberBase.TryConvertFromChecked(TOther value, out u /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromSaturating(TOther value, out ulong result) + static bool INumberBase.TryConvertFromSaturating(TOther value, out ulong result) => TryConvertFromSaturating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromSaturating(TOther value, out ulong result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -701,7 +766,11 @@ static bool INumberBase.TryConvertFromSaturating(TOther value, ou /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromTruncating(TOther value, out ulong result) + static bool INumberBase.TryConvertFromTruncating(TOther value, out ulong result) => TryConvertFromTruncating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromTruncating(TOther value, out ulong result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and diff --git a/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs b/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs index 11dddd3e66190..5cd03b4369ef9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs @@ -496,6 +496,63 @@ bool IBinaryInteger.TryWriteLittleEndian(Span destination, out int /// static nuint INumberBase.Abs(nuint value) => value; + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint CreateChecked(TOther value) + where TOther : INumberBase + { + nuint result; + + if (typeof(TOther) == typeof(nuint)) + { + result = (nuint)(object)value; + } + else if (!TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint CreateSaturating(TOther value) + where TOther : INumberBase + { + nuint result; + + if (typeof(TOther) == typeof(nuint)) + { + result = (nuint)(object)value; + } + else if (!TryConvertFromSaturating(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint CreateTruncating(TOther value) + where TOther : INumberBase + { + nuint result; + + if (typeof(TOther) == typeof(nuint)) + { + result = (nuint)(object)value; + } + else if (!TryConvertFromTruncating(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(nuint value) => true; @@ -561,7 +618,11 @@ bool IBinaryInteger.TryWriteLittleEndian(Span destination, out int /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromChecked(TOther value, out nuint result) + static bool INumberBase.TryConvertFromChecked(TOther value, out nuint result) => TryConvertFromChecked(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromChecked(TOther value, out nuint result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -623,7 +684,11 @@ static bool INumberBase.TryConvertFromChecked(TOther value, out n /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromSaturating(TOther value, out nuint result) + static bool INumberBase.TryConvertFromSaturating(TOther value, out nuint result) => TryConvertFromSaturating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromSaturating(TOther value, out nuint result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and @@ -686,7 +751,11 @@ static bool INumberBase.TryConvertFromSaturating(TOther value, ou /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromTruncating(TOther value, out nuint result) + static bool INumberBase.TryConvertFromTruncating(TOther value, out nuint result) => TryConvertFromTruncating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromTruncating(TOther value, out nuint result) + where TOther : INumberBase { // In order to reduce overall code duplication and improve the inlinabilty of these // methods for the corelib types we have `ConvertFrom` handle the same sign and diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs index bbc7222170ab8..3070633841517 100644 --- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs +++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs @@ -862,6 +862,9 @@ public static unsafe partial class NativeMemory public static System.Runtime.InteropServices.NFloat Cos(System.Runtime.InteropServices.NFloat x) { throw null; } public static System.Runtime.InteropServices.NFloat Cosh(System.Runtime.InteropServices.NFloat x) { throw null; } public static System.Runtime.InteropServices.NFloat CosPi(System.Runtime.InteropServices.NFloat x) { throw null; } + public static System.Runtime.InteropServices.NFloat CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static System.Runtime.InteropServices.NFloat CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static System.Runtime.InteropServices.NFloat CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Runtime.InteropServices.NFloat other) { throw null; } public static System.Runtime.InteropServices.NFloat Exp(System.Runtime.InteropServices.NFloat x) { throw null; } diff --git a/src/libraries/System.Runtime.Numerics/ref/System.Runtime.Numerics.cs b/src/libraries/System.Runtime.Numerics/ref/System.Runtime.Numerics.cs index bac59603bf274..9d11f190df0f9 100644 --- a/src/libraries/System.Runtime.Numerics/ref/System.Runtime.Numerics.cs +++ b/src/libraries/System.Runtime.Numerics/ref/System.Runtime.Numerics.cs @@ -45,6 +45,9 @@ namespace System.Numerics [System.CLSCompliantAttribute(false)] public int CompareTo(ulong other) { throw null; } public static System.Numerics.BigInteger CopySign(System.Numerics.BigInteger value, System.Numerics.BigInteger sign) { throw null; } + public static System.Numerics.BigInteger CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static System.Numerics.BigInteger CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static System.Numerics.BigInteger CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public static System.Numerics.BigInteger Divide(System.Numerics.BigInteger dividend, System.Numerics.BigInteger divisor) { throw null; } public static (System.Numerics.BigInteger Quotient, System.Numerics.BigInteger Remainder) DivRem(System.Numerics.BigInteger left, System.Numerics.BigInteger right) { throw null; } public static System.Numerics.BigInteger DivRem(System.Numerics.BigInteger dividend, System.Numerics.BigInteger divisor, out System.Numerics.BigInteger remainder) { throw null; } @@ -264,6 +267,9 @@ namespace System.Numerics public static System.Numerics.Complex Conjugate(System.Numerics.Complex value) { throw null; } public static System.Numerics.Complex Cos(System.Numerics.Complex value) { throw null; } public static System.Numerics.Complex Cosh(System.Numerics.Complex value) { throw null; } + public static System.Numerics.Complex CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static System.Numerics.Complex CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static System.Numerics.Complex CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public static System.Numerics.Complex Divide(double dividend, System.Numerics.Complex divisor) { throw null; } public static System.Numerics.Complex Divide(System.Numerics.Complex dividend, double divisor) { throw null; } public static System.Numerics.Complex Divide(System.Numerics.Complex dividend, System.Numerics.Complex divisor) { throw null; } diff --git a/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs b/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs index ec65b23290f05..2a76c9ad7df79 100644 --- a/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs +++ b/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs @@ -3936,6 +3936,63 @@ static int INumber.Sign(BigInteger value) /// static int INumberBase.Radix => 2; + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static BigInteger CreateChecked(TOther value) + where TOther : INumberBase + { + BigInteger result; + + if (typeof(TOther) == typeof(BigInteger)) + { + result = (BigInteger)(object)value; + } + else if (!TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static BigInteger CreateSaturating(TOther value) + where TOther : INumberBase + { + BigInteger result; + + if (typeof(TOther) == typeof(BigInteger)) + { + result = (BigInteger)(object)value; + } + else if (!TryConvertFromSaturating(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static BigInteger CreateTruncating(TOther value) + where TOther : INumberBase + { + BigInteger result; + + if (typeof(TOther) == typeof(BigInteger)) + { + result = (BigInteger)(object)value; + } + else if (!TryConvertFromTruncating(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(BigInteger value) => true; @@ -4069,7 +4126,11 @@ public static BigInteger MinMagnitude(BigInteger x, BigInteger y) /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromChecked(TOther value, out BigInteger result) + static bool INumberBase.TryConvertFromChecked(TOther value, out BigInteger result) => TryConvertFromChecked(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromChecked(TOther value, out BigInteger result) + where TOther : INumberBase { if (typeof(TOther) == typeof(byte)) { @@ -4182,7 +4243,11 @@ static bool INumberBase.TryConvertFromChecked(TOther value, /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromSaturating(TOther value, out BigInteger result) + static bool INumberBase.TryConvertFromSaturating(TOther value, out BigInteger result) => TryConvertFromSaturating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromSaturating(TOther value, out BigInteger result) + where TOther : INumberBase { if (typeof(TOther) == typeof(byte)) { @@ -4295,7 +4360,11 @@ static bool INumberBase.TryConvertFromSaturating(TOther valu /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool INumberBase.TryConvertFromTruncating(TOther value, out BigInteger result) + static bool INumberBase.TryConvertFromTruncating(TOther value, out BigInteger result) => TryConvertFromTruncating(value, out result); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool TryConvertFromTruncating(TOther value, out BigInteger result) + where TOther : INumberBase { if (typeof(TOther) == typeof(byte)) { diff --git a/src/libraries/System.Runtime.Numerics/src/System/Numerics/Complex.cs b/src/libraries/System.Runtime.Numerics/src/System/Numerics/Complex.cs index 334cfefbee0e9..f0e69c365cf0e 100644 --- a/src/libraries/System.Runtime.Numerics/src/System/Numerics/Complex.cs +++ b/src/libraries/System.Runtime.Numerics/src/System/Numerics/Complex.cs @@ -966,6 +966,63 @@ private static Complex Scale(Complex value, double factor) /// static Complex INumberBase.Abs(Complex value) => Abs(value); + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Complex CreateChecked(TOther value) + where TOther : INumberBase + { + Complex result; + + if (typeof(TOther) == typeof(Complex)) + { + result = (Complex)(object)value; + } + else if (!TryConvertFrom(value, out result) && !TOther.TryConvertToChecked(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Complex CreateSaturating(TOther value) + where TOther : INumberBase + { + Complex result; + + if (typeof(TOther) == typeof(Complex)) + { + result = (Complex)(object)value; + } + else if (!TryConvertFrom(value, out result) && !TOther.TryConvertToSaturating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Complex CreateTruncating(TOther value) + where TOther : INumberBase + { + Complex result; + + if (typeof(TOther) == typeof(Complex)) + { + result = (Complex)(object)value; + } + else if (!TryConvertFrom(value, out result) && !TOther.TryConvertToTruncating(value, out result)) + { + ThrowHelper.ThrowNotSupportedException(); + } + + return result; + } + /// static bool INumberBase.IsCanonical(Complex value) => true; diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index a8ee83f10e285..07abb8a23199f 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -729,6 +729,9 @@ public static partial class Buffer public static byte Clamp(byte value, byte min, byte max) { throw null; } public int CompareTo(byte value) { throw null; } public int CompareTo(object? value) { throw null; } + public static byte CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static byte CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static byte CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public static (byte Quotient, byte Remainder) DivRem(byte left, byte right) { throw null; } public bool Equals(byte obj) { throw null; } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } @@ -1884,6 +1887,9 @@ public sealed partial class DBNull : System.IConvertible, System.Runtime.Seriali public int CompareTo(decimal value) { throw null; } public int CompareTo(object? value) { throw null; } public static decimal CopySign(decimal value, decimal sign) { throw null; } + public static decimal CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static decimal CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static decimal CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public static decimal Divide(decimal d1, decimal d2) { throw null; } public bool Equals(decimal value) { throw null; } public static bool Equals(decimal d1, decimal d2) { throw null; } @@ -2138,6 +2144,9 @@ public partial class DivideByZeroException : System.ArithmeticException public static double Cos(double x) { throw null; } public static double Cosh(double x) { throw null; } public static double CosPi(double x) { throw null; } + public static double CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static double CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static double CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public bool Equals(double obj) { throw null; } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public static double Exp(double x) { throw null; } @@ -2767,6 +2776,9 @@ public partial class GopherStyleUriParser : System.UriParser public static System.Half Cos(System.Half x) { throw null; } public static System.Half Cosh(System.Half x) { throw null; } public static System.Half CosPi(System.Half x) { throw null; } + public static System.Half CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static System.Half CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static System.Half CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public bool Equals(System.Half other) { throw null; } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public static System.Half Exp(System.Half x) { throw null; } @@ -3088,6 +3100,9 @@ public sealed partial class InsufficientMemoryException : System.OutOfMemoryExce public int CompareTo(System.Int128 value) { throw null; } public int CompareTo(object? value) { throw null; } public static System.Int128 CopySign(System.Int128 value, System.Int128 sign) { throw null; } + public static System.Int128 CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static System.Int128 CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static System.Int128 CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public static (System.Int128 Quotient, System.Int128 Remainder) DivRem(System.Int128 left, System.Int128 right) { throw null; } public bool Equals(System.Int128 other) { throw null; } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } @@ -3262,6 +3277,9 @@ public sealed partial class InsufficientMemoryException : System.OutOfMemoryExce public int CompareTo(short value) { throw null; } public int CompareTo(object? value) { throw null; } public static short CopySign(short value, short sign) { throw null; } + public static short CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static short CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static short CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public static (short Quotient, short Remainder) DivRem(short left, short right) { throw null; } public bool Equals(short obj) { throw null; } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } @@ -3390,6 +3408,9 @@ public sealed partial class InsufficientMemoryException : System.OutOfMemoryExce public int CompareTo(int value) { throw null; } public int CompareTo(object? value) { throw null; } public static int CopySign(int value, int sign) { throw null; } + public static int CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static int CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static int CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public static (int Quotient, int Remainder) DivRem(int left, int right) { throw null; } public bool Equals(int obj) { throw null; } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } @@ -3518,6 +3539,9 @@ public sealed partial class InsufficientMemoryException : System.OutOfMemoryExce public int CompareTo(long value) { throw null; } public int CompareTo(object? value) { throw null; } public static long CopySign(long value, long sign) { throw null; } + public static long CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static long CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static long CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public static (long Quotient, long Remainder) DivRem(long left, long right) { throw null; } public bool Equals(long obj) { throw null; } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } @@ -3653,6 +3677,9 @@ public sealed partial class InsufficientMemoryException : System.OutOfMemoryExce public int CompareTo(nint value) { throw null; } public int CompareTo(object? value) { throw null; } public static nint CopySign(nint value, nint sign) { throw null; } + public static nint CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static nint CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static nint CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public static (nint Quotient, nint Remainder) DivRem(nint left, nint right) { throw null; } public bool Equals(nint other) { throw null; } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } @@ -4587,6 +4614,9 @@ public partial struct RuntimeTypeHandle : System.IEquatable(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static sbyte CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static sbyte CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public static (sbyte Quotient, sbyte Remainder) DivRem(sbyte left, sbyte right) { throw null; } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(sbyte obj) { throw null; } @@ -4754,6 +4784,9 @@ public sealed partial class SerializableAttribute : System.Attribute public static float Cos(float x) { throw null; } public static float Cosh(float x) { throw null; } public static float CosPi(float x) { throw null; } + public static float CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static float CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static float CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(float obj) { throw null; } public static float Exp(float x) { throw null; } @@ -6072,6 +6105,9 @@ public partial class TypeUnloadedException : System.SystemException public static System.UInt128 Clamp(System.UInt128 value, System.UInt128 min, System.UInt128 max) { throw null; } public int CompareTo(object? value) { throw null; } public int CompareTo(System.UInt128 value) { throw null; } + public static System.UInt128 CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static System.UInt128 CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static System.UInt128 CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public static (System.UInt128 Quotient, System.UInt128 Remainder) DivRem(System.UInt128 left, System.UInt128 right) { throw null; } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.UInt128 other) { throw null; } @@ -6252,6 +6288,9 @@ public partial class TypeUnloadedException : System.SystemException public static ushort Clamp(ushort value, ushort min, ushort max) { throw null; } public int CompareTo(object? value) { throw null; } public int CompareTo(ushort value) { throw null; } + public static ushort CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static ushort CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static ushort CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public static (ushort Quotient, ushort Remainder) DivRem(ushort left, ushort right) { throw null; } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(ushort obj) { throw null; } @@ -6380,6 +6419,9 @@ public partial class TypeUnloadedException : System.SystemException public static uint Clamp(uint value, uint min, uint max) { throw null; } public int CompareTo(object? value) { throw null; } public int CompareTo(uint value) { throw null; } + public static uint CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static uint CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static uint CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public static (uint Quotient, uint Remainder) DivRem(uint left, uint right) { throw null; } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(uint obj) { throw null; } @@ -6508,6 +6550,9 @@ public partial class TypeUnloadedException : System.SystemException public static ulong Clamp(ulong value, ulong min, ulong max) { throw null; } public int CompareTo(object? value) { throw null; } public int CompareTo(ulong value) { throw null; } + public static ulong CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static ulong CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static ulong CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public static (ulong Quotient, ulong Remainder) DivRem(ulong left, ulong right) { throw null; } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(ulong obj) { throw null; } @@ -6642,6 +6687,9 @@ public partial class TypeUnloadedException : System.SystemException public static nuint Clamp(nuint value, nuint min, nuint max) { throw null; } public int CompareTo(object? value) { throw null; } public int CompareTo(nuint value) { throw null; } + public static nuint CreateChecked(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static nuint CreateSaturating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } + public static nuint CreateTruncating(TOther value) where TOther : System.Numerics.INumberBase { throw null; } public static (nuint Quotient, nuint Remainder) DivRem(nuint left, nuint right) { throw null; } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(nuint other) { throw null; }