From fe9a54df8f4b5e6a2e4cafc0e4234a64e8c9cf8e Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Fri, 2 Jul 2021 15:19:12 -0700 Subject: [PATCH] Expose and implement generic math interfaces on core types (#54650) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Pin MicrosoftNetCompilersToolsetVersion to a version that supports Static Abstracts in Interfaces * Fixed issues related to enabling generic math in a general sense (#4) - Disable constraint checking during EEInit - Disable il linker running on CoreLib - Fixup generic math tests to actually build * Adding interfaces to support generic math * Implement generic math interfaces on core types * Updating the System.Runtime ref assembly to support generic math * Add a basic xunit test for generic-math * Removing unnecessary nullable annotations * Ensure all preview interface members are explicitly implemented * Don't use var for various methods in Double/Half/Single * Ensure FeatureGenericMath is defined for Mono * Skip generic math tests on Mono WASM due to https://github.com/dotnet/runtime/issues/54910 * Apply suggestions from code review Co-authored-by: Aleksey Kliger (λgeek) Co-authored-by: David Wrighton Co-authored-by: Aleksey Kliger (λgeek) --- eng/Versions.props | 2 + src/coreclr/clr.featuredefines.props | 4 +- src/coreclr/vm/typedesc.cpp | 5 + .../System.Private.CoreLib.Shared.projitems | 23 + .../System.Private.CoreLib/src/System/Byte.cs | 732 ++++- .../System.Private.CoreLib/src/System/Char.cs | 746 +++++ .../src/System/DateOnly.cs | 78 +- .../src/System/DateTime.cs | 120 + .../src/System/DateTimeOffset.cs | 119 + .../src/System/Decimal.cs | 537 ++++ .../src/System/Double.cs | 837 ++++- .../System.Private.CoreLib/src/System/Guid.cs | 292 ++ .../System.Private.CoreLib/src/System/Half.cs | 895 ++++++ .../src/System/IAdditionOperators.cs | 33 + .../src/System/IAdditiveIdentity.cs | 22 + .../src/System/IBitwiseOperators.cs | 43 + .../src/System/IComparisonOperators.cs | 46 + .../src/System/IDecrementOperators.cs | 29 + .../src/System/IDivisionOperators.cs | 33 + .../src/System/IEqualityOperators.cs | 31 + .../src/System/IFloatingPoint.cs | 342 ++ .../src/System/IIncrementOperators.cs | 29 + .../src/System/IInteger.cs | 47 + .../src/System/IMinMaxValue.cs | 24 + .../src/System/IModulusOperators.cs | 34 + .../src/System/IMultiplicativeIdentity.cs | 22 + .../src/System/IMultiplyOperators.cs | 33 + .../src/System/INumber.cs | 192 ++ .../src/System/IParseable.cs | 35 + .../src/System/IShiftOperators.cs | 39 + .../src/System/ISpanParseable.cs | 33 + .../src/System/ISubtractionOperators.cs | 33 + .../src/System/IUnaryNegationOperators.cs | 30 + .../src/System/IUnaryPlusOperators.cs | 30 + .../src/System/Int16.cs | 721 +++++ .../src/System/Int32.cs | 698 +++++ .../src/System/Int64.cs | 664 ++++ .../src/System/IntPtr.cs | 739 ++++- .../src/System/SByte.cs | 740 +++++ .../src/System/Single.cs | 833 ++++- .../src/System/TimeOnly.cs | 81 +- .../src/System/TimeSpan.cs | 179 ++ .../src/System/UInt16.cs | 708 +++++ .../src/System/UInt32.cs | 698 +++++ .../src/System/UInt64.cs | 678 ++++ .../src/System/UIntPtr.cs | 754 ++++- .../System.Runtime/ref/System.Runtime.cs | 2787 ++++++++++++++++- .../System.Runtime/ref/System.Runtime.csproj | 6 +- .../tests/System.Runtime.Tests.csproj | 2 + .../tests/System/GenericMathTests.cs | 73 + .../tests/System/Int32GenericMathTests.cs | 35 + .../System.Private.CoreLib.csproj | 2 + 52 files changed, 15921 insertions(+), 27 deletions(-) create mode 100644 src/libraries/System.Private.CoreLib/src/System/IAdditionOperators.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/IAdditiveIdentity.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/IBitwiseOperators.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/IComparisonOperators.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/IDecrementOperators.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/IDivisionOperators.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/IEqualityOperators.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/IFloatingPoint.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/IIncrementOperators.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/IInteger.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/IMinMaxValue.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/IModulusOperators.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/IMultiplicativeIdentity.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/IMultiplyOperators.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/INumber.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/IParseable.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/IShiftOperators.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/ISpanParseable.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/ISubtractionOperators.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/IUnaryNegationOperators.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/IUnaryPlusOperators.cs create mode 100644 src/libraries/System.Runtime/tests/System/GenericMathTests.cs create mode 100644 src/libraries/System.Runtime/tests/System/Int32GenericMathTests.cs diff --git a/eng/Versions.props b/eng/Versions.props index 1c8ae0b1d33b0..cdb313d0a0654 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -17,6 +17,8 @@ release true + + 4.0.0-2.21323.11 true false false diff --git a/src/coreclr/clr.featuredefines.props b/src/coreclr/clr.featuredefines.props index 67a5eab17c868..08fca8de6dd64 100644 --- a/src/coreclr/clr.featuredefines.props +++ b/src/coreclr/clr.featuredefines.props @@ -9,6 +9,7 @@ true true true + true true @@ -58,7 +59,8 @@ $(DefineConstants);FEATURE_BASICFREEZE $(DefineConstants);FEATURE_PORTABLE_SHUFFLE_THUNKS $(DefineConstants);FEATURE_ICASTABLE - + $(DefineConstants);FEATURE_GENERIC_MATH + $(DefineConstants);PROFILING_SUPPORTED $(DefineConstants);FEATURE_PROFAPI_ATTACH_DETACH diff --git a/src/coreclr/vm/typedesc.cpp b/src/coreclr/vm/typedesc.cpp index fbc6ff0170ece..f8567e0a9aa35 100644 --- a/src/coreclr/vm/typedesc.cpp +++ b/src/coreclr/vm/typedesc.cpp @@ -1730,6 +1730,11 @@ BOOL TypeVarTypeDesc::SatisfiesConstraints(SigTypeContext *pTypeContextOfConstra } CONTRACTL_END; + // During EEStartup, we cannot safely validate constraints, but we can also be confident that the code doesn't violate them + // Just skip validation and declare that the constraints are satisfied. + if (g_fEEInit) + return TRUE; + IMDInternalImport* pInternalImport = GetModule()->GetMDImport(); mdGenericParamConstraint tkConstraint; diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 1ceea5e5c0cc9..57d2b9b858691 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -2257,4 +2257,27 @@ Interop\Windows\Kernel32\Interop.Threading.cs + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libraries/System.Private.CoreLib/src/System/Byte.cs b/src/libraries/System.Private.CoreLib/src/System/Byte.cs index 8f127b6cbdd46..39bfeae2a7e44 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Byte.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Byte.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -13,6 +14,13 @@ namespace System [StructLayout(LayoutKind.Sequential)] [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public readonly struct Byte : IComparable, IConvertible, ISpanFormattable, IComparable, IEquatable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IBinaryInteger, + IMinMaxValue, + IUnsignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly byte m_value; // Do not rename (binary serialization) @@ -22,7 +30,6 @@ namespace System // The minimum value that a Byte may represent: 0. public const byte MinValue = 0; - // Compares this object to another object, returning an integer that // indicates the relationship. // Returns a value less than zero if this object @@ -190,14 +197,14 @@ public bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan } // - // IConvertible implementation + // IConvertible // + public TypeCode GetTypeCode() { return TypeCode.Byte; } - bool IConvertible.ToBoolean(IFormatProvider? provider) { return Convert.ToBoolean(m_value); @@ -272,5 +279,724 @@ object IConvertible.ToType(Type type, IFormatProvider? provider) { return Convert.DefaultToType((IConvertible)this, type, provider); } + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static byte IAdditionOperators.operator +(byte left, byte right) + => (byte)(left + right); + + // [RequiresPreviewFeatures] + // static checked byte IAdditionOperators.operator +(byte left, byte right) + // => checked((byte)(left + right)); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static byte IAdditiveIdentity.AdditiveIdentity => 0; + + // + // IBinaryInteger + // + + [RequiresPreviewFeatures] + static byte IBinaryInteger.LeadingZeroCount(byte value) + => (byte)(BitOperations.LeadingZeroCount(value) - 24); + + [RequiresPreviewFeatures] + static byte IBinaryInteger.PopCount(byte value) + => (byte)BitOperations.PopCount(value); + + [RequiresPreviewFeatures] + static byte IBinaryInteger.RotateLeft(byte value, byte rotateAmount) + => (byte)((value << (rotateAmount & 7)) | (value >> ((8 - rotateAmount) & 7))); + + [RequiresPreviewFeatures] + static byte IBinaryInteger.RotateRight(byte value, byte rotateAmount) + => (byte)((value >> (rotateAmount & 7)) | (value << ((8 - rotateAmount) & 7))); + + [RequiresPreviewFeatures] + static byte IBinaryInteger.TrailingZeroCount(byte value) + => (byte)(BitOperations.TrailingZeroCount(value << 24) - 24); + + // + // IBinaryNumber + // + + [RequiresPreviewFeatures] + static bool IBinaryNumber.IsPow2(byte value) + => BitOperations.IsPow2((uint)value); + + [RequiresPreviewFeatures] + static byte IBinaryNumber.Log2(byte value) + => (byte)BitOperations.Log2(value); + + // + // IBitwiseOperators + // + + [RequiresPreviewFeatures] + static byte IBitwiseOperators.operator &(byte left, byte right) + => (byte)(left & right); + + [RequiresPreviewFeatures] + static byte IBitwiseOperators.operator |(byte left, byte right) + => (byte)(left | right); + + [RequiresPreviewFeatures] + static byte IBitwiseOperators.operator ^(byte left, byte right) + => (byte)(left ^ right); + + [RequiresPreviewFeatures] + static byte IBitwiseOperators.operator ~(byte value) + => (byte)(~value); + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(byte left, byte right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(byte left, byte right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(byte left, byte right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(byte left, byte right) + => left >= right; + + // + // IDecrementOperators + // + + [RequiresPreviewFeatures] + static byte IDecrementOperators.operator --(byte value) + => value--; + + // [RequiresPreviewFeatures] + // static checked byte IDecrementOperators.operator --(byte value) + // => checked(value--); + + // + // IDivisionOperators + // + + [RequiresPreviewFeatures] + static byte IDivisionOperators.operator /(byte left, byte right) + => (byte)(left / right); + + // [RequiresPreviewFeatures] + // static checked byte IDivisionOperators.operator /(byte left, byte right) + // => checked((byte)(left / right)); + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(byte left, byte right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(byte left, byte right) + => left != right; + + // + // IIncrementOperators + // + + [RequiresPreviewFeatures] + static byte IIncrementOperators.operator ++(byte value) + => value++; + + // [RequiresPreviewFeatures] + // static checked byte IIncrementOperators.operator ++(byte value) + // => checked(value++); + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static byte IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static byte IMinMaxValue.MaxValue => MaxValue; + + // + // IModulusOperators + // + + [RequiresPreviewFeatures] + static byte IModulusOperators.operator %(byte left, byte right) + => (byte)(left % right); + + // [RequiresPreviewFeatures] + // static checked byte IModulusOperators.operator %(byte left, byte right) + // => checked((byte)(left % right)); + + // + // IMultiplicativeIdentity + // + + [RequiresPreviewFeatures] + static byte IMultiplicativeIdentity.MultiplicativeIdentity => 1; + + // + // IMultiplyOperators + // + + [RequiresPreviewFeatures] + static byte IMultiplyOperators.operator *(byte left, byte right) + => (byte)(left * right); + + // [RequiresPreviewFeatures] + // static checked byte IMultiplyOperators.operator *(byte left, byte right) + // => checked((byte)(left * right)); + + // + // INumber + // + + [RequiresPreviewFeatures] + static byte INumber.One => 1; + + [RequiresPreviewFeatures] + static byte INumber.Zero => 0; + + [RequiresPreviewFeatures] + static byte INumber.Abs(byte value) + => value; + + [RequiresPreviewFeatures] + static byte INumber.Clamp(byte value, byte min, byte max) + => Math.Clamp(value, min, max); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static byte INumber.Create(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return checked((byte)(char)(object)value); + } + else if (typeof(TOther) == typeof(decimal)) + { + return checked((byte)(decimal)(object)value); + } + else if (typeof(TOther) == typeof(double)) + { + return checked((byte)(double)(object)value); + } + else if (typeof(TOther) == typeof(short)) + { + return checked((byte)(short)(object)value); + } + else if (typeof(TOther) == typeof(int)) + { + return checked((byte)(int)(object)value); + } + else if (typeof(TOther) == typeof(long)) + { + return checked((byte)(long)(object)value); + } + else if (typeof(TOther) == typeof(nint)) + { + return checked((byte)(nint)(object)value); + } + else if (typeof(TOther) == typeof(sbyte)) + { + return checked((byte)(sbyte)(object)value); + } + else if (typeof(TOther) == typeof(float)) + { + return checked((byte)(float)(object)value); + } + else if (typeof(TOther) == typeof(ushort)) + { + return checked((byte)(ushort)(object)value); + } + else if (typeof(TOther) == typeof(uint)) + { + return checked((byte)(uint)(object)value); + } + else if (typeof(TOther) == typeof(ulong)) + { + return checked((byte)(ulong)(object)value); + } + else if (typeof(TOther) == typeof(nuint)) + { + return checked((byte)(nuint)(object)value); + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static byte INumber.CreateSaturating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + var actualValue = (char)(object)value; + return (actualValue > MaxValue) ? MaxValue : (byte)actualValue; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (byte)actualValue; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (byte)actualValue; + } + else if (typeof(TOther) == typeof(short)) + { + var actualValue = (short)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (byte)actualValue; + } + else if (typeof(TOther) == typeof(int)) + { + var actualValue = (int)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (byte)actualValue; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (byte)actualValue; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (byte)actualValue; + } + else if (typeof(TOther) == typeof(sbyte)) + { + var actualValue = (sbyte)(object)value; + return (actualValue < 0) ? MinValue : (byte)actualValue; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (byte)actualValue; + } + else if (typeof(TOther) == typeof(ushort)) + { + var actualValue = (ushort)(object)value; + return (actualValue > MaxValue) ? MaxValue : (byte)actualValue; + } + else if (typeof(TOther) == typeof(uint)) + { + var actualValue = (uint)(object)value; + return (actualValue > MaxValue) ? MaxValue : (byte)actualValue; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + return (actualValue > MaxValue) ? MaxValue : (byte)actualValue; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + return (actualValue > MaxValue) ? MaxValue : (byte)actualValue; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static byte INumber.CreateTruncating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (byte)(char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (byte)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (byte)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (byte)(short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (byte)(int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (byte)(long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (byte)(nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (byte)(sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (byte)(float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (byte)(ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (byte)(uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (byte)(ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (byte)(nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + static (byte Quotient, byte Remainder) INumber.DivRem(byte left, byte right) + => Math.DivRem(left, right); + + [RequiresPreviewFeatures] + static byte INumber.Max(byte x, byte y) + => Math.Max(x, y); + + [RequiresPreviewFeatures] + static byte INumber.Min(byte x, byte y) + => Math.Min(x, y); + + [RequiresPreviewFeatures] + static byte INumber.Parse(string s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static byte INumber.Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static byte INumber.Sign(byte value) + => (byte)((value == 0) ? 0 : 1); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static bool INumber.TryCreate(TOther value, out byte result) + { + if (typeof(TOther) == typeof(byte)) + { + result = (byte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + var actualValue = (char)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (byte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (byte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (byte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(short)) + { + var actualValue = (short)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (byte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(int)) + { + var actualValue = (int)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (byte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (byte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (byte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(sbyte)) + { + var actualValue = (sbyte)(object)value; + + if (actualValue < 0) + { + result = default; + return false; + } + + result = (byte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (byte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + var actualValue = (ushort)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (byte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + var actualValue = (uint)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (byte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (byte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (byte)actualValue; + return true; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + result = default; + return false; + } + } + + [RequiresPreviewFeatures] + static bool INumber.TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out byte result) + => TryParse(s, style, provider, out result); + + [RequiresPreviewFeatures] + static bool INumber.TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) + => TryParse(s, style, provider, out result); + + // + // IParseable + // + + [RequiresPreviewFeatures] + static byte IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out byte result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // IShiftOperators + // + + [RequiresPreviewFeatures] + static byte IShiftOperators.operator <<(byte value, int shiftAmount) + => (byte)(value << shiftAmount); + + [RequiresPreviewFeatures] + static byte IShiftOperators.operator >>(byte value, int shiftAmount) + => (byte)(value >> shiftAmount); + + // [RequiresPreviewFeatures] + // static byte IShiftOperators.operator >>>(byte value, int shiftAmount) + // => (byte)(value >> shiftAmount); + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static byte ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, NumberStyles.Integer, provider); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static byte ISubtractionOperators.operator -(byte left, byte right) + => (byte)(left - right); + + // [RequiresPreviewFeatures] + // static checked byte ISubtractionOperators.operator -(byte left, byte right) + // => checked((byte)(left - right)); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static byte IUnaryNegationOperators.operator -(byte value) + => (byte)(-value); + + // [RequiresPreviewFeatures] + // static checked byte IUnaryNegationOperators.operator -(byte value) + // => checked((byte)(-value)); + + // + // IUnaryPlusOperators + // + + [RequiresPreviewFeatures] + static byte IUnaryPlusOperators.operator +(byte value) + => (byte)(+value); + + // [RequiresPreviewFeatures] + // static checked byte IUnaryPlusOperators.operator +(byte value) + // => checked((byte)(+value)); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Char.cs b/src/libraries/System.Private.CoreLib/src/System/Char.cs index 613d0909429d4..2f58b54b7460a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Char.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Char.cs @@ -14,7 +14,10 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; +using System.Numerics; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using System.Text; namespace System @@ -23,6 +26,13 @@ namespace System [StructLayout(LayoutKind.Sequential)] [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public readonly struct Char : IComparable, IComparable, IEquatable, IConvertible, ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IBinaryInteger, + IMinMaxValue, + IUnsignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { // // Member Variables @@ -1049,5 +1059,741 @@ public static int ConvertToUtf32(string s, int index) // Not a high-surrogate or low-surrogate. Genereate the UTF32 value for the BMP characters. return (int)s[index]; } + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static char IAdditionOperators.operator +(char left, char right) + => (char)(left + right); + + // [RequiresPreviewFeatures] + // static checked char IAdditionOperators.operator +(char left, char right) + // => checked((char)(left + right)); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static char IAdditiveIdentity.AdditiveIdentity => (char)0; + + // + // IBinaryInteger + // + + [RequiresPreviewFeatures] + static char IBinaryInteger.LeadingZeroCount(char value) + => (char)(BitOperations.LeadingZeroCount(value) - 16); + + [RequiresPreviewFeatures] + static char IBinaryInteger.PopCount(char value) + => (char)BitOperations.PopCount(value); + + [RequiresPreviewFeatures] + static char IBinaryInteger.RotateLeft(char value, char rotateAmount) + => (char)((value << (rotateAmount & 15)) | (value >> ((16 - rotateAmount) & 15))); + + [RequiresPreviewFeatures] + static char IBinaryInteger.RotateRight(char value, char rotateAmount) + => (char)((value >> (rotateAmount & 15)) | (value << ((16 - rotateAmount) & 15))); + + [RequiresPreviewFeatures] + static char IBinaryInteger.TrailingZeroCount(char value) + => (char)(BitOperations.TrailingZeroCount(value << 16) - 16); + + // + // IBinaryNumber + // + + [RequiresPreviewFeatures] + static bool IBinaryNumber.IsPow2(char value) + => BitOperations.IsPow2((uint)value); + + [RequiresPreviewFeatures] + static char IBinaryNumber.Log2(char value) + => (char)BitOperations.Log2(value); + + // + // IBitwiseOperators + // + + [RequiresPreviewFeatures] + static char IBitwiseOperators.operator &(char left, char right) + => (char)(left & right); + + [RequiresPreviewFeatures] + static char IBitwiseOperators.operator |(char left, char right) + => (char)(left | right); + + [RequiresPreviewFeatures] + static char IBitwiseOperators.operator ^(char left, char right) + => (char)(left ^ right); + + [RequiresPreviewFeatures] + static char IBitwiseOperators.operator ~(char value) + => (char)(~value); + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(char left, char right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(char left, char right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(char left, char right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(char left, char right) + => left >= right; + + // + // IDecrementOperators + // + + [RequiresPreviewFeatures] + static char IDecrementOperators.operator --(char value) + => value--; + + // [RequiresPreviewFeatures] + // static checked char IDecrementOperators.operator --(char value) + // => checked(value--); + + // + // IDivisionOperators + // + + [RequiresPreviewFeatures] + static char IDivisionOperators.operator /(char left, char right) + => (char)(left / right); + + // [RequiresPreviewFeatures] + // static checked char IDivisionOperators.operator /(char left, char right) + // => checked((char)(left / right)); + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(char left, char right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(char left, char right) + => left != right; + + // + // IIncrementOperators + // + + [RequiresPreviewFeatures] + static char IIncrementOperators.operator ++(char value) + => value++; + + // [RequiresPreviewFeatures] + // static checked char IIncrementOperators.operator ++(char value) + // => checked(value++); + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static char IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static char IMinMaxValue.MaxValue => MaxValue; + + // + // IModulusOperators + // + + [RequiresPreviewFeatures] + static char IModulusOperators.operator %(char left, char right) + => (char)(left % right); + + // [RequiresPreviewFeatures] + // static checked char IModulusOperators.operator %(char left, char right) + // => checked((char)(left % right)); + + // + // IMultiplicativeIdentity + // + + [RequiresPreviewFeatures] + static char IMultiplicativeIdentity.MultiplicativeIdentity => (char)1; + + // + // IMultiplyOperators + // + + [RequiresPreviewFeatures] + static char IMultiplyOperators.operator *(char left, char right) + => (char)(left * right); + + // [RequiresPreviewFeatures] + // static checked char IMultiplyOperators.operator *(char left, char right) + // => checked((char)(left * right)); + + // + // INumber + // + + [RequiresPreviewFeatures] + static char INumber.One => (char)1; + + [RequiresPreviewFeatures] + static char INumber.Zero => (char)0; + + [RequiresPreviewFeatures] + static char INumber.Abs(char value) + => value; + + [RequiresPreviewFeatures] + static char INumber.Clamp(char value, char min, char max) + => (char)Math.Clamp(value, min, max); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static char INumber.Create(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (char)(byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return checked((char)(decimal)(object)value); + } + else if (typeof(TOther) == typeof(double)) + { + return checked((char)(double)(object)value); + } + else if (typeof(TOther) == typeof(short)) + { + return checked((char)(short)(object)value); + } + else if (typeof(TOther) == typeof(int)) + { + return checked((char)(int)(object)value); + } + else if (typeof(TOther) == typeof(long)) + { + return checked((char)(long)(object)value); + } + else if (typeof(TOther) == typeof(nint)) + { + return checked((char)(nint)(object)value); + } + else if (typeof(TOther) == typeof(sbyte)) + { + return checked((char)(sbyte)(object)value); + } + else if (typeof(TOther) == typeof(float)) + { + return checked((char)(float)(object)value); + } + else if (typeof(TOther) == typeof(ushort)) + { + return (char)(ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return checked((char)(uint)(object)value); + } + else if (typeof(TOther) == typeof(ulong)) + { + return checked((char)(ulong)(object)value); + } + else if (typeof(TOther) == typeof(nuint)) + { + return checked((char)(nuint)(object)value); + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static char INumber.CreateSaturating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (char)(byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (char)actualValue; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (char)actualValue; + } + else if (typeof(TOther) == typeof(short)) + { + var actualValue = (short)(object)value; + return (actualValue < MinValue) ? MinValue : (char)actualValue; + } + else if (typeof(TOther) == typeof(int)) + { + var actualValue = (int)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (char)actualValue; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (char)actualValue; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (char)actualValue; + } + else if (typeof(TOther) == typeof(sbyte)) + { + var actualValue = (sbyte)(object)value; + return (actualValue < MinValue) ? MinValue : (char)actualValue; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (char)actualValue; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (char)(ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + var actualValue = (uint)(object)value; + return (actualValue > MaxValue) ? MaxValue : (char)actualValue; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + return (actualValue > MaxValue) ? MaxValue : (char)actualValue; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + return (actualValue > MaxValue) ? MaxValue : (char)actualValue; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static char INumber.CreateTruncating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (char)(byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (char)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (char)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (char)(short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (char)(int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (char)(long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (char)(nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (char)(sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (char)(float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (char)(ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (char)(uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (char)(ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (char)(nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + static (char Quotient, char Remainder) INumber.DivRem(char left, char right) + => ((char, char))Math.DivRem(left, right); + + [RequiresPreviewFeatures] + static char INumber.Max(char x, char y) + => (char)Math.Max(x, y); + + [RequiresPreviewFeatures] + static char INumber.Min(char x, char y) + => (char)Math.Min(x, y); + + [RequiresPreviewFeatures] + static char INumber.Parse(string s, NumberStyles style, IFormatProvider? provider) + => Parse(s); + + [RequiresPreviewFeatures] + static char INumber.Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) + { + if (s.Length != 1) + { + throw new FormatException(SR.Format_NeedSingleChar); + } + return s[0]; + } + + [RequiresPreviewFeatures] + static char INumber.Sign(char value) + => (char)((value == 0) ? 0 : 1); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static bool INumber.TryCreate(TOther value, out char result) + { + if (typeof(TOther) == typeof(byte)) + { + result = (char)(byte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + result = (char)(object)value; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (char)actualValue; + return true; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (char)actualValue; + return true; + } + else if (typeof(TOther) == typeof(short)) + { + var actualValue = (short)(object)value; + + if (actualValue < 0) + { + result = default; + return false; + } + + result = (char)actualValue; + return true; + } + else if (typeof(TOther) == typeof(int)) + { + var actualValue = (int)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (char)actualValue; + return true; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (char)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (char)actualValue; + return true; + } + else if (typeof(TOther) == typeof(sbyte)) + { + var actualValue = (sbyte)(object)value; + + if (actualValue < 0) + { + result = default; + return false; + } + + result = (char)actualValue; + return true; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (char)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + var actualValue = (ushort)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (char)actualValue; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + var actualValue = (uint)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (char)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (char)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (char)actualValue; + return true; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + result = default; + return false; + } + } + + [RequiresPreviewFeatures] + static bool INumber.TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out char result) + => TryParse(s, out result); + + [RequiresPreviewFeatures] + static bool INumber.TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out char result) + { + if (s.Length != 1) + { + result = default; + return false; + } + result = s[0]; + return true; + } + + // + // IParseable + // + + [RequiresPreviewFeatures] + static char IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out char result) + => TryParse(s, out result); + + // + // IShiftOperators + // + + [RequiresPreviewFeatures] + static char IShiftOperators.operator <<(char value, int shiftAmount) + => (char)(value << shiftAmount); + + [RequiresPreviewFeatures] + static char IShiftOperators.operator >>(char value, int shiftAmount) + => (char)(value >> shiftAmount); + + // [RequiresPreviewFeatures] + // static char IShiftOperators.operator >>>(char value, int shiftAmount) + // => (char)(value >> shiftAmount); + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static char ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + { + if (s.Length != 1) + { + throw new FormatException(SR.Format_NeedSingleChar); + } + return s[0]; + } + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out char result) + { + if (s.Length != 1) + { + result = default; + return false; + } + result = s[0]; + return true; + } + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static char ISubtractionOperators.operator -(char left, char right) + => (char)(left - right); + + // [RequiresPreviewFeatures] + // static checked char ISubtractionOperators.operator -(char left, char right) + // => checked((char)(left - right)); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static char IUnaryNegationOperators.operator -(char value) + => (char)(-value); + + // [RequiresPreviewFeatures] + // static checked char IUnaryNegationOperators.operator -(char value) + // => checked((char)(-value)); + + // + // IUnaryPlusOperators + // + + [RequiresPreviewFeatures] + static char IUnaryPlusOperators.operator +(char value) + => (char)(+value); + + // [RequiresPreviewFeatures] + // static checked char IUnaryPlusOperators.operator +(char value) + // => checked((char)(+value)); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/DateOnly.cs b/src/libraries/System.Private.CoreLib/src/System/DateOnly.cs index 1ca9b084ee0aa..7e64638fa5103 100644 --- a/src/libraries/System.Private.CoreLib/src/System/DateOnly.cs +++ b/src/libraries/System.Private.CoreLib/src/System/DateOnly.cs @@ -2,8 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; -using System.Globalization; using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Runtime.Versioning; namespace System { @@ -11,6 +12,13 @@ namespace System /// Represents dates with values ranging from January 1, 0001 Anno Domini (Common Era) through December 31, 9999 A.D. (C.E.) in the Gregorian calendar. /// public readonly struct DateOnly : IComparable, IComparable, IEquatable, ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IComparisonOperators, + IMinMaxValue, + ISpanParseable +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly int _dayNumber; @@ -822,5 +830,73 @@ public string ToString(string? format, IFormatProvider? provider) return DateTimeFormat.TryFormat(GetEquivalentDateTime(), destination, out charsWritten, format, provider); } + +#if FEATURE_GENERIC_MATH + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(DateOnly left, DateOnly right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(DateOnly left, DateOnly right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(DateOnly left, DateOnly right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(DateOnly left, DateOnly right) + => left >= right; + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(DateOnly left, DateOnly right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(DateOnly left, DateOnly right) + => left != right; + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static DateOnly IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static DateOnly IMinMaxValue.MaxValue => MaxValue; + + // + // IParseable + // + + [RequiresPreviewFeatures] + static DateOnly IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider, DateTimeStyles.None); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out DateOnly result) + => TryParse(s, provider, DateTimeStyles.None, out result); + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static DateOnly ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, provider, DateTimeStyles.None); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateOnly result) + => TryParse(s, provider, DateTimeStyles.None, out result); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/DateTime.cs b/src/libraries/System.Private.CoreLib/src/System/DateTime.cs index dc2ebdf1380df..1d0235268a14e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/DateTime.cs +++ b/src/libraries/System.Private.CoreLib/src/System/DateTime.cs @@ -7,6 +7,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; +using System.Runtime.Versioning; namespace System { @@ -44,6 +45,17 @@ namespace System [Serializable] [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public readonly partial struct DateTime : IComparable, ISpanFormattable, IConvertible, IComparable, IEquatable, ISerializable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IAdditionOperators, + IAdditiveIdentity, + IComparisonOperators, + IMinMaxValue, + ISpanParseable, + ISubtractionOperators, + ISubtractionOperators +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { // Number of 100ns ticks per time unit private const long TicksPerMillisecond = 10000; @@ -1503,5 +1515,113 @@ internal static bool TryCreate(int year, int month, int day, int hour, int minut result = new DateTime(ticks); return true; } + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static DateTime IAdditionOperators.operator +(DateTime left, TimeSpan right) + => left + right; + + // [RequiresPreviewFeatures] + // static checked DateTime IAdditionOperators.operator +(DateTime left, TimeSpan right) + // => checked(left + right); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static TimeSpan IAdditiveIdentity.AdditiveIdentity + => default; + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(DateTime left, DateTime right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(DateTime left, DateTime right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(DateTime left, DateTime right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(DateTime left, DateTime right) + => left >= right; + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(DateTime left, DateTime right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(DateTime left, DateTime right) + => left != right; + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static DateTime IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static DateTime IMinMaxValue.MaxValue => MaxValue; + + // + // IParseable + // + + [RequiresPreviewFeatures] + static DateTime IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out DateTime result) + => TryParse(s, provider, DateTimeStyles.None, out result); + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static DateTime ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, provider, DateTimeStyles.None); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) + => TryParse(s, provider, DateTimeStyles.None, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static DateTime ISubtractionOperators.operator -(DateTime left, TimeSpan right) + => left - right; + + // [RequiresPreviewFeatures] + // static checked DateTime ISubtractionOperators.operator -(DateTime left, TimeSpan right) + // => checked(left - right); + + [RequiresPreviewFeatures] + static TimeSpan ISubtractionOperators.operator -(DateTime left, DateTime right) + => left - right; + + // [RequiresPreviewFeatures] + // static checked TimeSpan ISubtractionOperators.operator -(DateTime left, DateTime right) + // => checked(left - right); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs b/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs index 8b91fd6a2a8f3..f9fcc33b9a0cf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs +++ b/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs @@ -6,6 +6,7 @@ using System.Globalization; using System.Runtime.InteropServices; using System.Runtime.Serialization; +using System.Runtime.Versioning; namespace System { @@ -32,6 +33,17 @@ namespace System [Serializable] [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public readonly struct DateTimeOffset : IComparable, ISpanFormattable, IComparable, IEquatable, ISerializable, IDeserializationCallback +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IAdditionOperators, + IAdditiveIdentity, + IComparisonOperators, + IMinMaxValue, + ISpanParseable, + ISubtractionOperators, + ISubtractionOperators +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { // Constants internal const long MaxOffset = TimeSpan.TicksPerHour * 14; @@ -852,5 +864,112 @@ public static implicit operator DateTimeOffset(DateTime dateTime) => public static bool operator >=(DateTimeOffset left, DateTimeOffset right) => left.UtcDateTime >= right.UtcDateTime; + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static DateTimeOffset IAdditionOperators.operator +(DateTimeOffset left, TimeSpan right) + => left + right; + + // [RequiresPreviewFeatures] + // static checked DateTimeOffset IAdditionOperators.operator +(DateTimeOffset left, TimeSpan right) + // => checked(left + right); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static TimeSpan IAdditiveIdentity.AdditiveIdentity => default; + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(DateTimeOffset left, DateTimeOffset right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(DateTimeOffset left, DateTimeOffset right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(DateTimeOffset left, DateTimeOffset right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(DateTimeOffset left, DateTimeOffset right) + => left >= right; + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(DateTimeOffset left, DateTimeOffset right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(DateTimeOffset left, DateTimeOffset right) + => left != right; + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static DateTimeOffset IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static DateTimeOffset IMinMaxValue.MaxValue => MaxValue; + + // + // IParseable + // + + [RequiresPreviewFeatures] + static DateTimeOffset IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out DateTimeOffset result) + => TryParse(s, provider, DateTimeStyles.None, out result); + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static DateTimeOffset ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, provider, DateTimeStyles.None); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) + => TryParse(s, provider, DateTimeStyles.None, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static DateTimeOffset ISubtractionOperators.operator -(DateTimeOffset left, TimeSpan right) + => left - right; + + // [RequiresPreviewFeatures] + // static checked DateTimeOffset ISubtractionOperators.operator -(DateTimeOffset left, TimeSpan right) + // => checked(left - right); + + [RequiresPreviewFeatures] + static TimeSpan ISubtractionOperators.operator -(DateTimeOffset left, DateTimeOffset right) + => left - right; + + // [RequiresPreviewFeatures] + // static checked TimeSpan ISubtractionOperators.operator -(DateTimeOffset left, DateTimeOffset right) + // => checked(left - right); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Decimal.cs b/src/libraries/System.Private.CoreLib/src/System/Decimal.cs index 429d4c3cdf6a9..e5f26f2ff0148 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Decimal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Decimal.cs @@ -8,6 +8,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; +using System.Runtime.Versioning; namespace System { @@ -58,6 +59,12 @@ namespace System [System.Runtime.Versioning.NonVersionable] // This only applies to field layout [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public readonly partial struct Decimal : ISpanFormattable, IComparable, IConvertible, IComparable, IEquatable, ISerializable, IDeserializationCallback +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IMinMaxValue, + ISignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { // Sign mask for the flags field. A value of zero in this bit indicates a // positive Decimal value, and a value of one in this bit indicates a @@ -1072,5 +1079,535 @@ object IConvertible.ToType(Type type, IFormatProvider? provider) { return Convert.DefaultToType((IConvertible)this, type, provider); } + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static decimal IAdditionOperators.operator +(decimal left, decimal right) + => checked(left + right); + + // [RequiresPreviewFeatures] + // static checked decimal IAdditionOperators.operator +(decimal left, decimal right) + // => checked(left + right); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static decimal IAdditiveIdentity.AdditiveIdentity => 0.0m; + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(decimal left, decimal right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(decimal left, decimal right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(decimal left, decimal right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(decimal left, decimal right) + => left >= right; + + // + // IDecrementOperators + // + + [RequiresPreviewFeatures] + static decimal IDecrementOperators.operator --(decimal value) + => value--; + + // [RequiresPreviewFeatures] + // static checked decimal IDecrementOperators.operator --(decimal value) + // => checked(value--); + + // + // IDivisionOperators + // + + [RequiresPreviewFeatures] + static decimal IDivisionOperators.operator /(decimal left, decimal right) + => left / right; + + // [RequiresPreviewFeatures] + // static checked decimal IDivisionOperators.operator /(decimal left, decimal right) + // => checked(left / right); + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(decimal left, decimal right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(decimal left, decimal right) + => left != right; + + // + // IIncrementOperators + // + + [RequiresPreviewFeatures] + static decimal IIncrementOperators.operator ++(decimal value) + => value++; + + // [RequiresPreviewFeatures] + // static checked decimal IIncrementOperators.operator ++(decimal value) + // => checked(value++); + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static decimal IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static decimal IMinMaxValue.MaxValue => MaxValue; + + // + // IModulusOperators + // + + [RequiresPreviewFeatures] + static decimal IModulusOperators.operator %(decimal left, decimal right) + => left % right; + + // [RequiresPreviewFeatures] + // static checked decimal IModulusOperators.operator %(decimal left, decimal right) + // => checked(left % right); + + // + // IMultiplicativeIdentity + // + + [RequiresPreviewFeatures] + static decimal IMultiplicativeIdentity.MultiplicativeIdentity => 1.0m; + + // + // IMultiplyOperators + // + + [RequiresPreviewFeatures] + static decimal IMultiplyOperators.operator *(decimal left, decimal right) + => left * right; + + // [RequiresPreviewFeatures] + // static checked decimal IMultiplyOperators.operator *(decimal left, decimal right) + // => checked(left * right); + + // + // INumber + // + + [RequiresPreviewFeatures] + static decimal INumber.One => 1.0m; + + [RequiresPreviewFeatures] + static decimal INumber.Zero => 0.0m; + + [RequiresPreviewFeatures] + static decimal INumber.Abs(decimal value) + => Math.Abs(value); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static decimal INumber.Create(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (decimal)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (decimal)(float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static decimal INumber.CreateSaturating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (decimal)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (decimal)(float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static decimal INumber.CreateTruncating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (decimal)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (decimal)(float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + static decimal INumber.Clamp(decimal value, decimal min, decimal max) + => Math.Clamp(value, min, max); + + [RequiresPreviewFeatures] + static (decimal Quotient, decimal Remainder) INumber.DivRem(decimal left, decimal right) + => (left / right, left % right); + + [RequiresPreviewFeatures] + static decimal INumber.Max(decimal x, decimal y) + => Math.Max(x, y); + + [RequiresPreviewFeatures] + static decimal INumber.Min(decimal x, decimal y) + => Math.Min(x, y); + + [RequiresPreviewFeatures] + static decimal INumber.Parse(string s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static decimal INumber.Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static decimal INumber.Sign(decimal value) + => Math.Sign(value); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static bool INumber.TryCreate(TOther value, out decimal result) + { + if (typeof(TOther) == typeof(byte)) + { + result = (byte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + result = (char)(object)value; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + result = (decimal)(object)value; + return true; + } + else if (typeof(TOther) == typeof(double)) + { + result = (decimal)(double)(object)value; + return true; + } + else if (typeof(TOther) == typeof(short)) + { + result = (short)(object)value; + return true; + } + else if (typeof(TOther) == typeof(int)) + { + result = (int)(object)value; + return true; + } + else if (typeof(TOther) == typeof(long)) + { + result = (long)(object)value; + return true; + } + else if (typeof(TOther) == typeof(nint)) + { + result = (nint)(object)value; + return true; + } + else if (typeof(TOther) == typeof(sbyte)) + { + result = (sbyte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(float)) + { + result = (decimal)(float)(object)value; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + result = (ushort)(object)value; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + result = (uint)(object)value; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + result = (ulong)(object)value; + return true; + } + else if (typeof(TOther) == typeof(nuint)) + { + result = (nuint)(object)value; + return true; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + result = default; + return false; + } + } + + [RequiresPreviewFeatures] + static bool INumber.TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out decimal result) + => TryParse(s, style, provider, out result); + + [RequiresPreviewFeatures] + static bool INumber.TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out decimal result) + => TryParse(s, style, provider, out result); + + // + // IParseable + // + + [RequiresPreviewFeatures] + static decimal IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out decimal result) + => TryParse(s, NumberStyles.Number, provider, out result); + + // + // ISignedNumber + // + + [RequiresPreviewFeatures] + static decimal ISignedNumber.NegativeOne => -1; + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static decimal ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, NumberStyles.Number, provider); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out decimal result) + => TryParse(s, NumberStyles.Number, provider, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static decimal ISubtractionOperators.operator -(decimal left, decimal right) + => left - right; + + // [RequiresPreviewFeatures] + // static checked decimal ISubtractionOperators.operator -(decimal left, decimal right) + // => checked(left - right); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static decimal IUnaryNegationOperators.operator -(decimal value) + => -value; + + // [RequiresPreviewFeatures] + // static checked decimal IUnaryNegationOperators.operator -(decimal value) + // => checked(-value); + + // + // IUnaryPlusOperators + // + + [RequiresPreviewFeatures] + static decimal IUnaryPlusOperators.operator +(decimal value) + => +value; + + // [RequiresPreviewFeatures] + // static checked decimal IUnaryPlusOperators.operator +(decimal value) + // => checked(+value); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Double.cs b/src/libraries/System.Private.CoreLib/src/System/Double.cs index d3c9741202751..85d5f8c36f11d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Double.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Double.cs @@ -25,6 +25,12 @@ namespace System [StructLayout(LayoutKind.Sequential)] [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public readonly struct Double : IComparable, IConvertible, ISpanFormattable, IComparable, IEquatable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IBinaryFloatingPoint, + IMinMaxValue +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly double m_value; // Do not rename (binary serialization) @@ -50,11 +56,11 @@ namespace System internal const ulong SignMask = 0x8000_0000_0000_0000; internal const int SignShift = 63; - internal const int ShiftedSignMask = (int)(SignMask >> SignShift); + internal const uint ShiftedSignMask = (uint)(SignMask >> SignShift); internal const ulong ExponentMask = 0x7FF0_0000_0000_0000; internal const int ExponentShift = 52; - internal const int ShiftedExponentMask = (int)(ExponentMask >> ExponentShift); + internal const uint ShiftedExponentMask = (uint)(ExponentMask >> ExponentShift); internal const ulong SignificandMask = 0x000F_FFFF_FFFF_FFFF; @@ -144,7 +150,7 @@ public static unsafe bool IsSubnormal(double d) internal static int ExtractExponentFromBits(ulong bits) { - return (int)(bits >> ExponentShift) & ShiftedExponentMask; + return (int)(bits >> ExponentShift) & (int)ShiftedExponentMask; } internal static ulong ExtractSignificandFromBits(ulong bits) @@ -444,5 +450,830 @@ object IConvertible.ToType(Type type, IFormatProvider? provider) { return Convert.DefaultToType((IConvertible)this, type, provider); } + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static double IAdditionOperators.operator +(double left, double right) + => left + right; + + // [RequiresPreviewFeatures] + // static checked double IAdditionOperators.operator +(double left, double right) + // => checked(left + right); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static double IAdditiveIdentity.AdditiveIdentity => 0.0; + + // + // IBinaryNumber + // + + [RequiresPreviewFeatures] + static bool IBinaryNumber.IsPow2(double value) + { + ulong bits = BitConverter.DoubleToUInt64Bits(value); + + uint exponent = (uint)(bits >> ExponentShift) & ShiftedExponentMask; + ulong significand = bits & SignificandMask; + + return (value > 0) + && (exponent != MinExponent) && (exponent != MaxExponent) + && (significand == MinSignificand); + } + + [RequiresPreviewFeatures] + static double IBinaryNumber.Log2(double value) + => Math.Log2(value); + + // + // IBitwiseOperators + // + + [RequiresPreviewFeatures] + static double IBitwiseOperators.operator &(double left, double right) + { + ulong bits = BitConverter.DoubleToUInt64Bits(left) & BitConverter.DoubleToUInt64Bits(right); + return BitConverter.UInt64BitsToDouble(bits); + } + + [RequiresPreviewFeatures] + static double IBitwiseOperators.operator |(double left, double right) + { + ulong bits = BitConverter.DoubleToUInt64Bits(left) | BitConverter.DoubleToUInt64Bits(right); + return BitConverter.UInt64BitsToDouble(bits); + } + + [RequiresPreviewFeatures] + static double IBitwiseOperators.operator ^(double left, double right) + { + ulong bits = BitConverter.DoubleToUInt64Bits(left) ^ BitConverter.DoubleToUInt64Bits(right); + return BitConverter.UInt64BitsToDouble(bits); + } + + [RequiresPreviewFeatures] + static double IBitwiseOperators.operator ~(double value) + { + ulong bits = ~BitConverter.DoubleToUInt64Bits(value); + return BitConverter.UInt64BitsToDouble(bits); + } + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(double left, double right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(double left, double right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(double left, double right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(double left, double right) + => left >= right; + + // + // IDecrementOperators + // + + [RequiresPreviewFeatures] + static double IDecrementOperators.operator --(double value) + => value--; + + // [RequiresPreviewFeatures] + // static checked double IDecrementOperators.operator --(double value) + // => checked(value--); + + // + // IDivisionOperators + // + + [RequiresPreviewFeatures] + static double IDivisionOperators.operator /(double left, double right) + => left / right; + + // [RequiresPreviewFeatures] + // static checked double IDivisionOperators.operator /(double left, double right) + // => checked(left / right); + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(double left, double right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(double left, double right) + => left != right; + + // + // IFloatingPoint + // + + [RequiresPreviewFeatures] + static double IFloatingPoint.E => Math.E; + + [RequiresPreviewFeatures] + static double IFloatingPoint.Epsilon => Epsilon; + + [RequiresPreviewFeatures] + static double IFloatingPoint.NaN => NaN; + + [RequiresPreviewFeatures] + static double IFloatingPoint.NegativeInfinity => NegativeInfinity; + + [RequiresPreviewFeatures] + static double IFloatingPoint.NegativeZero => -0.0; + + [RequiresPreviewFeatures] + static double IFloatingPoint.Pi => Math.PI; + + [RequiresPreviewFeatures] + static double IFloatingPoint.PositiveInfinity => PositiveInfinity; + + [RequiresPreviewFeatures] + static double IFloatingPoint.Tau => Math.Tau; + + [RequiresPreviewFeatures] + static double IFloatingPoint.Acos(double x) + => Math.Acos(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Acosh(double x) + => Math.Acosh(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Asin(double x) + => Math.Asin(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Asinh(double x) + => Math.Asinh(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Atan(double x) + => Math.Atan(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Atan2(double y, double x) + => Math.Atan2(y, x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Atanh(double x) + => Math.Atanh(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.BitIncrement(double x) + => Math.BitIncrement(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.BitDecrement(double x) + => Math.BitDecrement(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Cbrt(double x) + => Math.Cbrt(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Ceiling(double x) + => Math.Ceiling(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.CopySign(double x, double y) + => Math.CopySign(x, y); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Cos(double x) + => Math.Cos(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Cosh(double x) + => Math.Cosh(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Exp(double x) + => Math.Exp(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Floor(double x) + => Math.Floor(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.FusedMultiplyAdd(double left, double right, double addend) + => Math.FusedMultiplyAdd(left, right, addend); + + [RequiresPreviewFeatures] + static double IFloatingPoint.IEEERemainder(double left, double right) + => Math.IEEERemainder(left, right); + + [RequiresPreviewFeatures] + static TInteger IFloatingPoint.ILogB(double x) + => TInteger.Create(Math.ILogB(x)); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Log(double x) + => Math.Log(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Log(double x, double newBase) + => Math.Log(x, newBase); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Log2(double x) + => Math.Log2(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Log10(double x) + => Math.Log10(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.MaxMagnitude(double x, double y) + => Math.MaxMagnitude(x, y); + + [RequiresPreviewFeatures] + static double IFloatingPoint.MinMagnitude(double x, double y) + => Math.MinMagnitude(x, y); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Pow(double x, double y) + => Math.Pow(x, y); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Round(double x) + => Math.Round(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Round(double x, TInteger digits) + => Math.Round(x, int.Create(digits)); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Round(double x, MidpointRounding mode) + => Math.Round(x, mode); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Round(double x, TInteger digits, MidpointRounding mode) + => Math.Round(x, int.Create(digits), mode); + + [RequiresPreviewFeatures] + static double IFloatingPoint.ScaleB(double x, TInteger n) + => Math.ScaleB(x, int.Create(n)); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Sin(double x) + => Math.Sin(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Sinh(double x) + => Math.Sinh(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Sqrt(double x) + => Math.Sqrt(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Tan(double x) + => Math.Tan(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Tanh(double x) + => Math.Tanh(x); + + [RequiresPreviewFeatures] + static double IFloatingPoint.Truncate(double x) + => Math.Truncate(x); + + // static double IFloatingPoint.AcosPi(double x) + // => Math.AcosPi(x); + // + // static double IFloatingPoint.AsinPi(double x) + // => Math.AsinPi(x); + // + // static double IFloatingPoint.AtanPi(double x) + // => Math.AtanPi(x); + // + // static double IFloatingPoint.Atan2Pi(double y, double x) + // => Math.Atan2Pi(y, x); + // + // static double IFloatingPoint.Compound(double x, double n) + // => Math.Compound(x, n); + // + // static double IFloatingPoint.CosPi(double x) + // => Math.CosPi(x); + // + // static double IFloatingPoint.ExpM1(double x) + // => Math.ExpM1(x); + // + // static double IFloatingPoint.Exp2(double x) + // => Math.Exp2(x); + // + // static double IFloatingPoint.Exp2M1(double x) + // => Math.Exp2M1(x); + // + // static double IFloatingPoint.Exp10(double x) + // => Math.Exp10(x); + // + // static double IFloatingPoint.Exp10M1(double x) + // => Math.Exp10M1(x); + // + // static double IFloatingPoint.Hypot(double x, double y) + // => Math.Hypot(x, y); + // + // static double IFloatingPoint.LogP1(double x) + // => Math.LogP1(x); + // + // static double IFloatingPoint.Log2P1(double x) + // => Math.Log2P1(x); + // + // static double IFloatingPoint.Log10P1(double x) + // => Math.Log10P1(x); + // + // static double IFloatingPoint.MaxMagnitudeNumber(double x, double y) + // => Math.MaxMagnitudeNumber(x, y); + // + // static double IFloatingPoint.MaxNumber(double x, double y) + // => Math.MaxNumber(x, y); + // + // static double IFloatingPoint.MinMagnitudeNumber(double x, double y) + // => Math.MinMagnitudeNumber(x, y); + // + // static double IFloatingPoint.MinNumber(double x, double y) + // => Math.MinNumber(x, y); + // + // static double IFloatingPoint.Root(double x, double n) + // => Math.Root(x, n); + // + // static double IFloatingPoint.SinPi(double x) + // => Math.SinPi(x, y); + // + // static double TanPi(double x) + // => Math.TanPi(x, y); + + // + // IIncrementOperators + // + + [RequiresPreviewFeatures] + static double IIncrementOperators.operator ++(double value) + => value++; + + // [RequiresPreviewFeatures] + // static checked double IIncrementOperators.operator ++(double value) + // => checked(value++); + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static double IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static double IMinMaxValue.MaxValue => MaxValue; + + // + // IModulusOperators + // + + [RequiresPreviewFeatures] + static double IModulusOperators.operator %(double left, double right) + => left % right; + + // [RequiresPreviewFeatures] + // static checked double IModulusOperators.operator %(double left, double right) + // => checked(left % right); + + // + // IMultiplicativeIdentity + // + + [RequiresPreviewFeatures] + static double IMultiplicativeIdentity.MultiplicativeIdentity => 1.0; + + // + // IMultiplyOperators + // + + [RequiresPreviewFeatures] + static double IMultiplyOperators.operator *(double left, double right) + => (double)(left * right); + + // [RequiresPreviewFeatures] + // static checked double IMultiplyOperators.operator *(double left, double right) + // => checked((double)(left * right)); + + // + // INumber + // + + [RequiresPreviewFeatures] + static double INumber.One => 1.0; + + [RequiresPreviewFeatures] + static double INumber.Zero => 0.0; + + [RequiresPreviewFeatures] + static double INumber.Abs(double value) + => Math.Abs(value); + + [RequiresPreviewFeatures] + static double INumber.Clamp(double value, double min, double max) + => Math.Clamp(value, min, max); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static double INumber.Create(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (double)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static double INumber.CreateSaturating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (double)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static double INumber.CreateTruncating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (double)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + static (double Quotient, double Remainder) INumber.DivRem(double left, double right) + => (left / right, left % right); + + [RequiresPreviewFeatures] + static double INumber.Max(double x, double y) + => Math.Max(x, y); + + [RequiresPreviewFeatures] + static double INumber.Min(double x, double y) + => Math.Min(x, y); + + [RequiresPreviewFeatures] + static double INumber.Parse(string s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static double INumber.Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static double INumber.Sign(double value) + => Math.Sign(value); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static bool INumber.TryCreate(TOther value, out double result) + { + if (typeof(TOther) == typeof(byte)) + { + result = (byte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + result = (char)(object)value; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + result = (double)(decimal)(object)value; + return true; + } + else if (typeof(TOther) == typeof(double)) + { + result = (double)(object)value; + return true; + } + else if (typeof(TOther) == typeof(short)) + { + result = (short)(object)value; + return true; + } + else if (typeof(TOther) == typeof(int)) + { + result = (int)(object)value; + return true; + } + else if (typeof(TOther) == typeof(long)) + { + result = (long)(object)value; + return true; + } + else if (typeof(TOther) == typeof(nint)) + { + result = (nint)(object)value; + return true; + } + else if (typeof(TOther) == typeof(sbyte)) + { + result = (sbyte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(float)) + { + result = (float)(object)value; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + result = (ushort)(object)value; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + result = (uint)(object)value; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + result = (ulong)(object)value; + return true; + } + else if (typeof(TOther) == typeof(nuint)) + { + result = (nuint)(object)value; + return true; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + result = default; + return false; + } + } + + [RequiresPreviewFeatures] + static bool INumber.TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out double result) + => TryParse(s, style, provider, out result); + + [RequiresPreviewFeatures] + static bool INumber.TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out double result) + => TryParse(s, style, provider, out result); + + // + // IParseable + // + + [RequiresPreviewFeatures] + static double IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out double result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // ISignedNumber + // + + [RequiresPreviewFeatures] + static double ISignedNumber.NegativeOne => -1; + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static double ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, NumberStyles.Integer, provider); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static double ISubtractionOperators.operator -(double left, double right) + => (double)(left - right); + + // [RequiresPreviewFeatures] + // static checked double ISubtractionOperators.operator -(double left, double right) + // => checked((double)(left - right)); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static double IUnaryNegationOperators.operator -(double value) + => (double)(-value); + + // [RequiresPreviewFeatures] + // static checked double IUnaryNegationOperators.operator -(double value) + // => checked((double)(-value)); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static double IUnaryPlusOperators.operator +(double value) + => (double)(+value); + + // [RequiresPreviewFeatures] + // static checked double IUnaryPlusOperators.operator +(double value) + // => checked((double)(+value)); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Guid.cs b/src/libraries/System.Private.CoreLib/src/System/Guid.cs index 0a26175427939..fa7d6acf9d2de 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Guid.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Guid.cs @@ -19,6 +19,12 @@ namespace System [NonVersionable] // This only applies to field layout [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public readonly partial struct Guid : ISpanFormattable, IComparable, IComparable, IEquatable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IComparisonOperators, + ISpanParseable +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { public static readonly Guid Empty; @@ -1161,5 +1167,291 @@ bool ISpanFormattable.TryFormat(Span destination, out int charsWritten, Re // Like with the IFormattable implementation, provider is ignored. return TryFormat(destination, out charsWritten, format); } + +#if FEATURE_GENERIC_MATH + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(Guid left, Guid right) + { + if (left._a != right._a) + { + return (uint)left._a < (uint)right._a; + } + + if (left._b != right._b) + { + return (uint)left._b < (uint)right._b; + } + + if (left._c != right._c) + { + return (uint)left._c < (uint)right._c; + } + + if (left._d != right._d) + { + return left._d < right._d; + } + + if (left._e != right._e) + { + return left._e < right._e; + } + + if (left._f != right._f) + { + return left._f < right._f; + } + + if (left._g != right._g) + { + return left._g < right._g; + } + + if (left._h != right._h) + { + return left._h < right._h; + } + + if (left._i != right._i) + { + return left._i < right._i; + } + + if (left._j != right._j) + { + return left._j < right._j; + } + + if (left._k != right._k) + { + return left._k < right._k; + } + + return false; + } + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(Guid left, Guid right) + { + if (left._a != right._a) + { + return (uint)left._a < (uint)right._a; + } + + if (left._b != right._b) + { + return (uint)left._b < (uint)right._b; + } + + if (left._c != right._c) + { + return (uint)left._c < (uint)right._c; + } + + if (left._d != right._d) + { + return left._d < right._d; + } + + if (left._e != right._e) + { + return left._e < right._e; + } + + if (left._f != right._f) + { + return left._f < right._f; + } + + if (left._g != right._g) + { + return left._g < right._g; + } + + if (left._h != right._h) + { + return left._h < right._h; + } + + if (left._i != right._i) + { + return left._i < right._i; + } + + if (left._j != right._j) + { + return left._j < right._j; + } + + if (left._k != right._k) + { + return left._k < right._k; + } + + return true; + } + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(Guid left, Guid right) + { + if (left._a != right._a) + { + return (uint)left._a > (uint)right._a; + } + + if (left._b != right._b) + { + return (uint)left._b > (uint)right._b; + } + + if (left._c != right._c) + { + return (uint)left._c > (uint)right._c; + } + + if (left._d != right._d) + { + return left._d > right._d; + } + + if (left._e != right._e) + { + return left._e > right._e; + } + + if (left._f != right._f) + { + return left._f > right._f; + } + + if (left._g != right._g) + { + return left._g > right._g; + } + + if (left._h != right._h) + { + return left._h > right._h; + } + + if (left._i != right._i) + { + return left._i > right._i; + } + + if (left._j != right._j) + { + return left._j > right._j; + } + + if (left._k != right._k) + { + return left._k > right._k; + } + + return false; + } + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(Guid left, Guid right) + { + if (left._a != right._a) + { + return (uint)left._a > (uint)right._a; + } + + if (left._b != right._b) + { + return (uint)left._b > (uint)right._b; + } + + if (left._c != right._c) + { + return (uint)left._c > (uint)right._c; + } + + if (left._d != right._d) + { + return left._d > right._d; + } + + if (left._e != right._e) + { + return left._e > right._e; + } + + if (left._f != right._f) + { + return left._f > right._f; + } + + if (left._g != right._g) + { + return left._g > right._g; + } + + if (left._h != right._h) + { + return left._h > right._h; + } + + if (left._i != right._i) + { + return left._i > right._i; + } + + if (left._j != right._j) + { + return left._j > right._j; + } + + if (left._k != right._k) + { + return left._k > right._k; + } + + return true; + } + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(Guid left, Guid right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(Guid left, Guid right) + => left != right; + + // + // IParseable + // + + [RequiresPreviewFeatures] + static Guid IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out Guid result) + => TryParse(s, out result); + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static Guid ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) + => TryParse(s, out result); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Half.cs b/src/libraries/System.Private.CoreLib/src/System/Half.cs index c5c5b35358164..ea64c10f83538 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Half.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Half.cs @@ -5,7 +5,9 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Numerics; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Runtime.Versioning; namespace System { @@ -16,6 +18,12 @@ namespace System /// [StructLayout(LayoutKind.Sequential)] public readonly struct Half : IComparable, ISpanFormattable, IComparable, IEquatable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IBinaryFloatingPoint, + IMinMaxValue +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private const NumberStyles DefaultParseStyle = NumberStyles.Float | NumberStyles.AllowThousands; @@ -23,9 +31,11 @@ namespace System private const ushort SignMask = 0x8000; private const ushort SignShift = 15; + private const ushort ShiftedSignMask = SignMask >> SignShift; private const ushort ExponentMask = 0x7C00; private const ushort ExponentShift = 10; + private const ushort ShiftedExponentMask = ExponentMask >> ExponentShift; private const ushort SignificandMask = 0x03FF; private const ushort SignificandShift = 0; @@ -690,5 +700,890 @@ private static double CreateDouble(bool sign, ushort exp, ulong sig) => BitConverter.UInt64BitsToDouble(((sign ? 1UL : 0UL) << double.SignShift) + ((ulong)exp << double.ExponentShift) + sig); #endregion + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static Half IAdditionOperators.operator +(Half left, Half right) + => (Half)((float)left + (float)right); + + // [RequiresPreviewFeatures] + // static checked Half IAdditionOperators.operator +(Half left, Half right) + // => checked((Half)((float)left + (float)right)); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static Half IAdditiveIdentity.AdditiveIdentity => PositiveZero; + + // + // IBinaryNumber + // + + [RequiresPreviewFeatures] + static bool IBinaryNumber.IsPow2(Half value) + { + uint bits = BitConverter.HalfToUInt16Bits(value); + + uint exponent = (bits >> ExponentShift) & ShiftedExponentMask; + uint significand = bits & SignificandMask; + + return (value > PositiveZero) + && (exponent != MinExponent) && (exponent != MaxExponent) + && (significand == MinSignificand); + } + + [RequiresPreviewFeatures] + static Half IBinaryNumber.Log2(Half value) + => (Half)MathF.Log2((float)value); + + // + // IBitwiseOperators + // + + [RequiresPreviewFeatures] + static Half IBitwiseOperators.operator &(Half left, Half right) + { + ushort bits = (ushort)(BitConverter.HalfToUInt16Bits(left) & BitConverter.HalfToUInt16Bits(right)); + return BitConverter.UInt16BitsToHalf(bits); + } + + [RequiresPreviewFeatures] + static Half IBitwiseOperators.operator |(Half left, Half right) + { + ushort bits = (ushort)(BitConverter.HalfToUInt16Bits(left) | BitConverter.HalfToUInt16Bits(right)); + return BitConverter.UInt16BitsToHalf(bits); + } + + [RequiresPreviewFeatures] + static Half IBitwiseOperators.operator ^(Half left, Half right) + { + ushort bits = (ushort)(BitConverter.HalfToUInt16Bits(left) ^ BitConverter.HalfToUInt16Bits(right)); + return BitConverter.UInt16BitsToHalf(bits); + } + + [RequiresPreviewFeatures] + static Half IBitwiseOperators.operator ~(Half value) + { + ushort bits = (ushort)(~BitConverter.HalfToUInt16Bits(value)); + return BitConverter.UInt16BitsToHalf(bits); + } + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(Half left, Half right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(Half left, Half right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(Half left, Half right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(Half left, Half right) + => left >= right; + + // + // IDecrementOperators + // + + [RequiresPreviewFeatures] + static Half IDecrementOperators.operator --(Half value) + { + var tmp = (float)value; + tmp--; + return (Half)tmp; + } + + // [RequiresPreviewFeatures] + // static checked Half IDecrementOperators.operator --(Half value) + // { + // var tmp = (float)value; + // tmp--; + // return (Half)tmp; + // } + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(Half left, Half right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(Half left, Half right) + => left != right; + + // + // IDivisionOperators + // + + [RequiresPreviewFeatures] + static Half IDivisionOperators.operator /(Half left, Half right) + => (Half)((float)left / (float)right); + + // [RequiresPreviewFeatures] + // static checked Half IDivisionOperators.operator /(Half left, Half right) + // => checked((Half)((float)left / (float)right)); + + // + // IFloatingPoint + // + + [RequiresPreviewFeatures] + static Half IFloatingPoint.E => (Half)MathF.E; + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Epsilon => Epsilon; + + [RequiresPreviewFeatures] + static Half IFloatingPoint.NaN => NaN; + + [RequiresPreviewFeatures] + static Half IFloatingPoint.NegativeInfinity => NegativeInfinity; + + [RequiresPreviewFeatures] + static Half IFloatingPoint.NegativeZero => NegativeZero; + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Pi => (Half)MathF.PI; + + [RequiresPreviewFeatures] + static Half IFloatingPoint.PositiveInfinity => PositiveInfinity; + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Tau => (Half)MathF.Tau; + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Acos(Half x) + => (Half)MathF.Acos((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Acosh(Half x) + => (Half)MathF.Acosh((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Asin(Half x) + => (Half)MathF.Asin((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Asinh(Half x) + => (Half)MathF.Asinh((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Atan(Half x) + => (Half)MathF.Atan((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Atan2(Half y, Half x) + => (Half)MathF.Atan2((float)y, (float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Atanh(Half x) + => (Half)MathF.Atanh((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.BitIncrement(Half x) + { + ushort bits = BitConverter.HalfToUInt16Bits(x); + + if ((bits & ExponentMask) >= ExponentMask) + { + // NaN returns NaN + // -Infinity returns float.MinValue + // +Infinity returns +Infinity + return (bits == (ExponentMask | SignMask)) ? MinValue : x; + } + + if (bits == NegativeZeroBits) + { + // -0.0 returns float.Epsilon + return Epsilon; + } + + // Negative values need to be decremented + // Positive values need to be incremented + + bits += unchecked((ushort)((bits < 0) ? -1 : +1)); + return BitConverter.UInt16BitsToHalf(bits); + } + + [RequiresPreviewFeatures] + static Half IFloatingPoint.BitDecrement(Half x) + { + ushort bits = BitConverter.HalfToUInt16Bits(x); + + if ((bits & ExponentMask) >= ExponentMask) + { + // NaN returns NaN + // -Infinity returns -Infinity + // +Infinity returns float.MaxValue + return (bits == ExponentMask) ? MaxValue : x; + } + + if (bits == PositiveZeroBits) + { + // +0.0 returns -float.Epsilon + return new Half(EpsilonBits | SignMask); + } + + // Negative values need to be incremented + // Positive values need to be decremented + + bits += (ushort)((bits < 0) ? +1 : -1); + return BitConverter.UInt16BitsToHalf(bits); + } + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Cbrt(Half x) + => (Half)MathF.Cbrt((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Ceiling(Half x) + => (Half)MathF.Ceiling((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.CopySign(Half x, Half y) + => (Half)MathF.CopySign((float)x, (float)y); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Cos(Half x) + => (Half)MathF.Cos((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Cosh(Half x) + => (Half)MathF.Cosh((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Exp(Half x) + => (Half)MathF.Exp((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Floor(Half x) + => (Half)MathF.Floor((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.FusedMultiplyAdd(Half left, Half right, Half addend) + => (Half)MathF.FusedMultiplyAdd((float)left, (float)right, (float)addend); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.IEEERemainder(Half left, Half right) + => (Half)MathF.IEEERemainder((float)left, (float)right); + + [RequiresPreviewFeatures] + static TInteger IFloatingPoint.ILogB(Half x) + => TInteger.Create(MathF.ILogB((float)x)); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Log(Half x) + => (Half)MathF.Log((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Log(Half x, Half newBase) + => (Half)MathF.Log((float)x, (float)newBase); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Log2(Half x) + => (Half)MathF.Log2((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Log10(Half x) + => (Half)MathF.Log10((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.MaxMagnitude(Half x, Half y) + => (Half)MathF.MaxMagnitude((float)x, (float)y); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.MinMagnitude(Half x, Half y) + => (Half)MathF.MinMagnitude((float)x, (float)y); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Pow(Half x, Half y) + => (Half)MathF.Pow((float)x, (float)y); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Round(Half x) + => (Half)MathF.Round((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Round(Half x, TInteger digits) + => (Half)MathF.Round((float)x, int.Create(digits)); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Round(Half x, MidpointRounding mode) + => (Half)MathF.Round((float)x, mode); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Round(Half x, TInteger digits, MidpointRounding mode) + => (Half)MathF.Round((float)x, int.Create(digits), mode); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.ScaleB(Half x, TInteger n) + => (Half)MathF.ScaleB((float)x, int.Create(n)); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Sin(Half x) + => (Half)MathF.Sin((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Sinh(Half x) + => (Half)MathF.Sinh((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Sqrt(Half x) + => (Half)MathF.Sqrt((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Tan(Half x) + => (Half)MathF.Tan((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Tanh(Half x) + => (Half)MathF.Tanh((float)x); + + [RequiresPreviewFeatures] + static Half IFloatingPoint.Truncate(Half x) + => (Half)MathF.Truncate((float)x); + + // static Half IFloatingPoint.AcosPi(Half x) + // => (Half)MathF.AcosPi((float)x); + // + // static Half IFloatingPoint.AsinPi(Half x) + // => (Half)MathF.AsinPi((float)x); + // + // static Half IFloatingPoint.AtanPi(Half x) + // => (Half)MathF.AtanPi((float)x); + // + // static Half IFloatingPoint.Atan2Pi(Half y, Half x) + // => (Half)MathF.Atan2Pi((float)y, (float)x); + // + // static Half IFloatingPoint.Compound(Half x, Half n) + // => (Half)MathF.Compound((float)x, (float)n); + // + // static Half IFloatingPoint.CosPi(Half x) + // => (Half)MathF.CosPi((float)x); + // + // static Half IFloatingPoint.ExpM1(Half x) + // => (Half)MathF.ExpM1((float)x); + // + // static Half IFloatingPoint.Exp2(Half x) + // => (Half)MathF.Exp2((float)x); + // + // static Half IFloatingPoint.Exp2M1(Half x) + // => (Half)MathF.Exp2M1((float)x); + // + // static Half IFloatingPoint.Exp10(Half x) + // => (Half)MathF.Exp10((float)x); + // + // static Half IFloatingPoint.Exp10M1(Half x) + // => (Half)MathF.Exp10M1((float)x); + // + // static Half IFloatingPoint.Hypot(Half x, Half y) + // => (Half)MathF.Hypot((float)x, (float)y); + // + // static Half IFloatingPoint.LogP1(Half x) + // => (Half)MathF.LogP1((float)x); + // + // static Half IFloatingPoint.Log2P1(Half x) + // => (Half)MathF.Log2P1((float)x); + // + // static Half IFloatingPoint.Log10P1(Half x) + // => (Half)MathF.Log10P1((float)x); + // + // static Half IFloatingPoint.MaxMagnitudeNumber(Half x, Half y) + // => (Half)MathF.MaxMagnitudeNumber((float)x, (float)y); + // + // static Half IFloatingPoint.MaxNumber(Half x, Half y) + // => (Half)MathF.MaxNumber((float)x, (float)y); + // + // static Half IFloatingPoint.MinMagnitudeNumber(Half x, Half y) + // => (Half)MathF.MinMagnitudeNumber((float)x, (float)y); + // + // static Half IFloatingPoint.MinNumber(Half x, Half y) + // => (Half)MathF.MinNumber((float)x, (float)y); + // + // static Half IFloatingPoint.Root(Half x, Half n) + // => (Half)MathF.Root((float)x, (float)n); + // + // static Half IFloatingPoint.SinPi(Half x) + // => (Half)MathF.SinPi((float)x, (float)y); + // + // static Half TanPi(Half x) + // => (Half)MathF.TanPi((float)x, (float)y); + + // + // IIncrementOperators + // + + [RequiresPreviewFeatures] + static Half IIncrementOperators.operator ++(Half value) + { + var tmp = (float)value; + tmp++; + return (Half)tmp; + } + + // [RequiresPreviewFeatures] + // static checked Half IIncrementOperators.operator ++(Half value) + // { + // var tmp = (float)value; + // tmp++; + // return (Half)tmp; + // } + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static Half IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static Half IMinMaxValue.MaxValue => MaxValue; + + // + // IModulusOperators + // + + [RequiresPreviewFeatures] + static Half IModulusOperators.operator %(Half left, Half right) + => (Half)((float)left % (float)right); + + // [RequiresPreviewFeatures] + // static checked Half IModulusOperators.operator %(Half left, Half right) + // => checked((Half)((float)left % (float)right)); + + // + // IMultiplicativeIdentity + // + + [RequiresPreviewFeatures] + static Half IMultiplicativeIdentity.MultiplicativeIdentity => (Half)1.0f; + + // + // IMultiplyOperators + // + + [RequiresPreviewFeatures] + static Half IMultiplyOperators.operator *(Half left, Half right) + => (Half)((float)left * (float)right); + + // [RequiresPreviewFeatures] + // static checked Half IMultiplyOperators.operator *(Half left, Half right) + // => checked((Half)((float)left * (float)right)); + + // + // INumber + // + + [RequiresPreviewFeatures] + static Half INumber.One => (Half)1.0f; + + [RequiresPreviewFeatures] + static Half INumber.Zero => PositiveZero; + + [RequiresPreviewFeatures] + static Half INumber.Abs(Half value) + => (Half)MathF.Abs((float)value); + + [RequiresPreviewFeatures] + static Half INumber.Clamp(Half value, Half min, Half max) + => (Half)Math.Clamp((float)value, (float)min, (float)max); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static Half INumber.Create(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (Half)(byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (Half)(char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (Half)(float)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (Half)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (Half)(short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (Half)(int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (Half)(long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (Half)(long)(nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (Half)(sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (Half)(float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (Half)(ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (Half)(uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (Half)(ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (Half)(ulong)(nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static Half INumber.CreateSaturating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (Half)(byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (Half)(char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (Half)(float)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (Half)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (Half)(short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (Half)(int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (Half)(long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (Half)(long)(nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (Half)(sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (Half)(float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (Half)(ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (Half)(uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (Half)(ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (Half)(ulong)(nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static Half INumber.CreateTruncating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (Half)(byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (Half)(char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (Half)(float)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (Half)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (Half)(short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (Half)(int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (Half)(long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (Half)(long)(nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (Half)(sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (Half)(float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (Half)(ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (Half)(uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (Half)(ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (Half)(ulong)(nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + static (Half Quotient, Half Remainder) INumber.DivRem(Half left, Half right) + => ((Half, Half))((float)left / (float)right, (float)left % (float)right); + + [RequiresPreviewFeatures] + static Half INumber.Max(Half x, Half y) + => (Half)MathF.Max((float)x, (float)y); + + [RequiresPreviewFeatures] + static Half INumber.Min(Half x, Half y) + => (Half)MathF.Min((float)x, (float)y); + + [RequiresPreviewFeatures] + static Half INumber.Parse(string s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static Half INumber.Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static Half INumber.Sign(Half value) + => (Half)MathF.Sign((float)value); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static bool INumber.TryCreate(TOther value, out Half result) + { + if (typeof(TOther) == typeof(byte)) + { + result = (Half)(byte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + result = (Half)(char)(object)value; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + result = (Half)(float)(decimal)(object)value; + return true; + } + else if (typeof(TOther) == typeof(double)) + { + result = (Half)(double)(object)value; + return true; + } + else if (typeof(TOther) == typeof(short)) + { + result = (Half)(short)(object)value; + return true; + } + else if (typeof(TOther) == typeof(int)) + { + result = (Half)(int)(object)value; + return true; + } + else if (typeof(TOther) == typeof(long)) + { + result = (Half)(long)(object)value; + return true; + } + else if (typeof(TOther) == typeof(nint)) + { + result = (Half)(long)(nint)(object)value; + return true; + } + else if (typeof(TOther) == typeof(sbyte)) + { + result = (Half)(sbyte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(float)) + { + result = (Half)(float)(object)value; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + result = (Half)(ushort)(object)value; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + result = (Half)(uint)(object)value; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + result = (Half)(ulong)(object)value; + return true; + } + else if (typeof(TOther) == typeof(nuint)) + { + result = (Half)(ulong)(nuint)(object)value; + return true; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + result = default; + return false; + } + } + + [RequiresPreviewFeatures] + static bool INumber.TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out Half result) + => TryParse(s, style, provider, out result); + + [RequiresPreviewFeatures] + static bool INumber.TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out Half result) + => TryParse(s, style, provider, out result); + + // + // IParseable + // + + [RequiresPreviewFeatures] + static Half IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out Half result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // ISignedNumber + // + + [RequiresPreviewFeatures] + static Half ISignedNumber.NegativeOne => (Half)(-1.0f); + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static Half ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, NumberStyles.Integer, provider); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out Half result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static Half ISubtractionOperators.operator -(Half left, Half right) + => (Half)((float)left - (float)right); + + // [RequiresPreviewFeatures] + // static checked Half ISubtractionOperators.operator -(Half left, Half right) + // => checked((Half)((float)left - (float)right)); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static Half IUnaryNegationOperators.operator -(Half value) + => (Half)(-(float)value); + + // [RequiresPreviewFeatures] + // static checked Half IUnaryNegationOperators.operator -(Half value) + // => checked((Half)(-(float)value)); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static Half IUnaryPlusOperators.operator +(Half value) + => value; + + // [RequiresPreviewFeatures] + // static checked Half IUnaryPlusOperators.operator +(Half value) + // => checked(value); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/IAdditionOperators.cs b/src/libraries/System.Private.CoreLib/src/System/IAdditionOperators.cs new file mode 100644 index 0000000000000..fb09cfac334c8 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IAdditionOperators.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for computing the sum of two values. + /// The type that implements this interface. + /// The type that will be added to . + /// The type that contains the sum of and . + [RequiresPreviewFeatures] + public interface IAdditionOperators + where TSelf : IAdditionOperators + { + /// Adds two values together to compute their sum. + /// The value to which is added. + /// The value which is added to . + /// The sum of and . + static abstract TResult operator +(TSelf left, TOther right); + + // /// Adds two values together to compute their sum. + // /// The value to which is added. + // /// The value which is added to . + // /// The sum of and . + // /// The sum of and is not representable by . + // static abstract checked TResult operator +(TSelf left, TOther right); + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/IAdditiveIdentity.cs b/src/libraries/System.Private.CoreLib/src/System/IAdditiveIdentity.cs new file mode 100644 index 0000000000000..5b07145c32837 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IAdditiveIdentity.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for getting the additive identity of a given type. + /// The type that implements this interface. + /// The type that contains the additive identify of . + [RequiresPreviewFeatures] + public interface IAdditiveIdentity + where TSelf : IAdditiveIdentity + { + /// Gets the additive identity of the current type. + static abstract TResult AdditiveIdentity { get; } + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/IBitwiseOperators.cs b/src/libraries/System.Private.CoreLib/src/System/IBitwiseOperators.cs new file mode 100644 index 0000000000000..d4d1a35d0e66f --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IBitwiseOperators.cs @@ -0,0 +1,43 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for performing bitwise operations over two values. + /// The type that implements this interface. + /// The type that will is used in the operation with . + /// The type that contains the result of op . + [RequiresPreviewFeatures] + public interface IBitwiseOperators + where TSelf : IBitwiseOperators + { + /// Computes the bitwise-and of two values. + /// The value to and with . + /// The value to and with . + /// The bitwise-and of and . + static abstract TResult operator &(TSelf left, TOther right); + + /// Computes the bitwise-or of two values. + /// The value to or with . + /// The value to or with . + /// The bitwise-or of and . + static abstract TResult operator |(TSelf left, TOther right); + + /// Computes the exclusive-or of two values. + /// The value to xor with . + /// The value to xorwith . + /// The exclusive-or of and . + static abstract TResult operator ^(TSelf left, TOther right); + + /// Computes the ones-complement representation of a given value. + /// The value for which to compute its ones-complement. + /// The ones-complement of . + static abstract TResult operator ~(TSelf value); + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/IComparisonOperators.cs b/src/libraries/System.Private.CoreLib/src/System/IComparisonOperators.cs new file mode 100644 index 0000000000000..5bd4a22e28c96 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IComparisonOperators.cs @@ -0,0 +1,46 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for comparing two values to determine relative order. + /// The type that implements this interface. + /// The type that will be compared with . + [RequiresPreviewFeatures] + public interface IComparisonOperators + : IComparable, + IComparable, + IEqualityOperators + where TSelf : IComparisonOperators + { + /// Compares two values to determine which is less. + /// The value to compare with . + /// The value to compare with . + /// true if is less than ; otherwise, false. + static abstract bool operator <(TSelf left, TOther right); + + /// Compares two values to determine which is less or equal. + /// The value to compare with . + /// The value to compare with . + /// true if is less than or equal to ; otherwise, false. + static abstract bool operator <=(TSelf left, TOther right); + + /// Compares two values to determine which is greater. + /// The value to compare with . + /// The value to compare with . + /// true if is greater than ; otherwise, false. + static abstract bool operator >(TSelf left, TOther right); + + /// Compares two values to determine which is greater or equal. + /// The value to compare with . + /// The value to compare with . + /// true if is greater than or equal to ; otherwise, false. + static abstract bool operator >=(TSelf left, TOther right); + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/IDecrementOperators.cs b/src/libraries/System.Private.CoreLib/src/System/IDecrementOperators.cs new file mode 100644 index 0000000000000..9a240b14a9614 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IDecrementOperators.cs @@ -0,0 +1,29 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for decrementing a given value. + /// The type that implements this interface. + [RequiresPreviewFeatures] + public interface IDecrementOperators + where TSelf : IDecrementOperators + { + /// Decrements a value. + /// The value to decrement. + /// The result of decrementing . + static abstract TSelf operator --(TSelf value); + + // /// Decrements a value. + // /// The value to decrement. + // /// The result of decrementing . + // /// The result of decrementing is not representable by . + // static abstract checked TSelf operator --(TSelf value); + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/IDivisionOperators.cs b/src/libraries/System.Private.CoreLib/src/System/IDivisionOperators.cs new file mode 100644 index 0000000000000..4beba8cddbddf --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IDivisionOperators.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for computing the quotient of two values. + /// The type that implements this interface. + /// The type that will divide . + /// The type that contains the quotient of and . + [RequiresPreviewFeatures] + public interface IDivisionOperators + where TSelf : IDivisionOperators + { + /// Divides two values together to compute their quotient. + /// The value which divides. + /// The value which divides . + /// The quotient of divided-by . + static abstract TResult operator /(TSelf left, TOther right); + + // /// Divides two values together to compute their quotient. + // /// The value which divides. + // /// The value which divides . + // /// The quotient of divided-by . + // /// The quotient of divided-by is not representable by . + // static abstract checked TResult operator /(TSelf left, TOther right); + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/IEqualityOperators.cs b/src/libraries/System.Private.CoreLib/src/System/IEqualityOperators.cs new file mode 100644 index 0000000000000..f6f8fa5050a97 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IEqualityOperators.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for comparing two values to determine equality. + /// The type that implements this interface. + /// The type that will be compared with . + [RequiresPreviewFeatures] + public interface IEqualityOperators : IEquatable + where TSelf : IEqualityOperators + { + /// Compares two values to determine equality. + /// The value to compare with . + /// The value to compare with . + /// true if is equal to ; otherwise, false. + static abstract bool operator ==(TSelf left, TOther right); + + /// Compares two values to determine inequality. + /// The value to compare with . + /// The value to compare with . + /// true if is not equal to ; otherwise, false. + static abstract bool operator !=(TSelf left, TOther right); + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/IFloatingPoint.cs b/src/libraries/System.Private.CoreLib/src/System/IFloatingPoint.cs new file mode 100644 index 0000000000000..cb69e03fd771f --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IFloatingPoint.cs @@ -0,0 +1,342 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a floating-point type. + /// The type that implements the interface. + [RequiresPreviewFeatures] + public interface IFloatingPoint + : ISignedNumber + where TSelf : IFloatingPoint + { + /// Gets the mathematical constant e. + static abstract TSelf E { get; } + + /// Gets the smallest value such that can be added to 0 that does not result in 0. + static abstract TSelf Epsilon { get; } + + /// Gets a value that represents NaN. + static abstract TSelf NaN { get; } + + /// Gets a value that represents negative infinity. + static abstract TSelf NegativeInfinity { get; } + + /// Gets a value that represents negative zero. + static abstract TSelf NegativeZero { get; } + + /// Gets the mathematical constant pi. + static abstract TSelf Pi { get; } + + /// Gets a value that represents positive infinity. + static abstract TSelf PositiveInfinity { get; } + + /// Gets the mathematical constant tau. + static abstract TSelf Tau { get; } + + /// Computes the arc-cosine of a value. + /// The value, in radians, whose arc-cosine is to be computed. + /// The arc-cosine of . + static abstract TSelf Acos(TSelf x); + + /// Computes the hyperbolic arc-cosine of a value. + /// The value, in radians, whose hyperbolic arc-cosine is to be computed. + /// The hyperbolic arc-cosine of . + static abstract TSelf Acosh(TSelf x); + + /// Computes the arc-sine of a value. + /// The value, in radians, whose arc-sine is to be computed. + /// The arc-sine of . + static abstract TSelf Asin(TSelf x); + + /// Computes the hyperbolic arc-sine of a value. + /// The value, in radians, whose hyperbolic arc-sine is to be computed. + /// The hyperbolic arc-sine of . + static abstract TSelf Asinh(TSelf x); + + /// Computes the arc-tangent of a value. + /// The value, in radians, whose arc-tangent is to be computed. + /// The arc-tangent of . + static abstract TSelf Atan(TSelf x); + + /// Computes the arc-tangent of the quotient of two values. + /// The y-coordinate of a point. + /// The x-coordinate of a point. + /// The arc-tangent of divided-by . + static abstract TSelf Atan2(TSelf y, TSelf x); + + /// Computes the hyperbolic arc-tangent of a value. + /// The value, in radians, whose hyperbolic arc-tangent is to be computed. + /// The hyperbolic arc-tangent of . + static abstract TSelf Atanh(TSelf x); + + /// Decrements a value to the smallest value that compares less than a given value. + /// The value to be bitwise decremented. + /// The smallest value that compares less than . + static abstract TSelf BitDecrement(TSelf x); + + /// Increments a value to the smallest value that compares greater than a given value. + /// The value to be bitwise incremented. + /// The smallest value that compares greater than . + static abstract TSelf BitIncrement(TSelf x); + + /// Computes the cube-root of a value. + /// The value whose cube-root is to be computed. + /// The cube-root of . + static abstract TSelf Cbrt(TSelf x); + + /// Computes the ceiling of a value. + /// The value whose ceiling is to be computed. + /// The ceiling of . + static abstract TSelf Ceiling(TSelf x); + + /// Copies the sign of a value to the sign of another value.. + /// The value whose magnitude is used in the result. + /// The value whose sign is used in the result. + /// A value with the magnitude of and the sign of . + static abstract TSelf CopySign(TSelf x, TSelf y); + + /// Computes the cosine of a value. + /// The value, in radians, whose cosine is to be computed. + /// The cosine of . + static abstract TSelf Cos(TSelf x); + + /// Computes the hyperbolic cosine of a value. + /// The value, in radians, whose hyperbolic cosine is to be computed. + /// The hyperbolic cosine of . + static abstract TSelf Cosh(TSelf x); + + /// Computes raised to a given power. + /// The power to which is raised. + /// raised to the power of . + static abstract TSelf Exp(TSelf x); + + /// Computes the floor of a value. + /// The value whose floor is to be computed. + /// The floor of . + static abstract TSelf Floor(TSelf x); + + /// Computes the fused multiply-add of three values. + /// The value which multiplies. + /// The value which multiplies . + /// The value that is added to the product of and . + /// The result of times plus computed as one ternary operation. + static abstract TSelf FusedMultiplyAdd(TSelf left, TSelf right, TSelf addend); + + /// Computes the remainder of two values as specified by IEEE 754. + /// The value which divides. + /// The value which divides . + /// The remainder of divided-by as specified by IEEE 754. + static abstract TSelf IEEERemainder(TSelf left, TSelf right); + + /// Computes the integer logarithm of a value. + /// The value whose integer logarithm is to be computed. + /// The integer logarithm of . + static abstract TInteger ILogB(TSelf x) + where TInteger : IBinaryInteger; + + /// Determines if a value is finite. + /// The value to be checked. + /// true if is finite; otherwise, false. + static abstract bool IsFinite(TSelf value); + + /// Determines if a value is infinite. + /// The value to be checked. + /// true if is infinite; otherwise, false. + static abstract bool IsInfinity(TSelf value); + + /// Determines if a value is NaN. + /// The value to be checked. + /// true if is NaN; otherwise, false. + static abstract bool IsNaN(TSelf value); + + /// Determines if a value is negative. + /// The value to be checked. + /// true if is negative; otherwise, false. + static abstract bool IsNegative(TSelf value); + + /// Determines if a value is negative infinity. + /// The value to be checked. + /// true if is negative infinity; otherwise, false. + static abstract bool IsNegativeInfinity(TSelf value); + + /// Determines if a value is normal. + /// The value to be checked. + /// true if is normal; otherwise, false. + static abstract bool IsNormal(TSelf value); + + /// Determines if a value is positive infinity. + /// The value to be checked. + /// true if is positive infinity; otherwise, false. + static abstract bool IsPositiveInfinity(TSelf value); + + /// Determines if a value is subnormal. + /// The value to be checked. + /// true if is subnormal; otherwise, false. + static abstract bool IsSubnormal(TSelf value); + + /// Computes the natural (base- logarithm of a value. + /// The value whose natural logarithm is to be computed. + /// The natural logarithm of . + static abstract TSelf Log(TSelf x); + + /// Computes the logarithm of a value in the specified base. + /// The value whose logarithm is to be computed. + /// The base in which the logarithm is to be computed. + /// The base- logarithm of . + static abstract TSelf Log(TSelf x, TSelf newBase); + + /// Computes the base-2 logarithm of a value. + /// The value whose base-2 logarithm is to be computed. + /// The base-2 logarithm of . + static abstract TSelf Log2(TSelf x); + + /// Computes the base-10 logarithm of a value. + /// The value whose base-10 logarithm is to be computed. + /// The base-10 logarithm of . + static abstract TSelf Log10(TSelf x); + + /// Compares two values to compute which is greater. + /// The value to compare with . + /// The value to compare with . + /// if it is greater than ; otherwise, . + /// For this method matches the IEEE 754:2019 maximumMagnitude function. This requires NaN inputs to not be propagated back to the caller and for -0.0 to be treated as less than +0.0. + static abstract TSelf MaxMagnitude(TSelf x, TSelf y); + + /// Compares two values to compute which is lesser. + /// The value to compare with . + /// The value to compare with . + /// if it is less than ; otherwise, . + /// For this method matches the IEEE 754:2019 minimumMagnitude function. This requires NaN inputs to not be propagated back to the caller and for -0.0 to be treated as less than +0.0. + static abstract TSelf MinMagnitude(TSelf x, TSelf y); + + /// Computes a value raised to a given power. + /// The value which is raised to the power of . + /// The power to which is raised. + /// raised to the power of . + static abstract TSelf Pow(TSelf x, TSelf y); + + /// Rounds a value to the nearest integer using the default rounding mode (). + /// The value to round. + /// The result of rounding to the nearest integer using the default rounding mode. + static abstract TSelf Round(TSelf x); + + /// Rounds a value to a specified number of fractional-digits using the default rounding mode (). + /// The value to round. + /// The number of fractional digits to which should be rounded. + /// The result of rounding to fractional-digits using the default rounding mode. + static abstract TSelf Round(TSelf x, TInteger digits) + where TInteger : IBinaryInteger; + + /// Rounds a value to the nearest integer using the specified rounding mode. + /// The value to round. + /// The mode under which should be rounded. + /// The result of rounding to the nearest integer using . + static abstract TSelf Round(TSelf x, MidpointRounding mode); + + /// Rounds a value to a specified number of fractional-digits using the default rounding mode (). + /// The value to round. + /// The number of fractional digits to which should be rounded. + /// The mode under which should be rounded. + /// The result of rounding to fractional-digits using . + static abstract TSelf Round(TSelf x, TInteger digits, MidpointRounding mode) + where TInteger : IBinaryInteger; + + /// Computes the product of a value and its base-radix raised to the specified power. + /// The value which base-radix raised to the power of multiplies. + /// The value to which base-radix is raised before multipliying . + /// The product of and base-radix raised to the power of . + static abstract TSelf ScaleB(TSelf x, TInteger n) + where TInteger : IBinaryInteger; + + /// Computes the sine of a value. + /// The value, in radians, whose sine is to be computed. + /// The sine of . + static abstract TSelf Sin(TSelf x); + + /// Computes the hyperbolic sine of a value. + /// The value, in radians, whose hyperbolic sine is to be computed. + /// The hyperbolic sine of . + static abstract TSelf Sinh(TSelf x); + + /// Computes the square-root of a value. + /// The value whose square-root is to be computed. + /// The square-root of . + static abstract TSelf Sqrt(TSelf x); + + /// Computes the tangent of a value. + /// The value, in radians, whose tangent is to be computed. + /// The tangent of . + static abstract TSelf Tan(TSelf x); + + /// Computes the hyperbolic tangent of a value. + /// The value, in radians, whose hyperbolic tangent is to be computed. + /// The hyperbolic tangent of . + static abstract TSelf Tanh(TSelf x); + + /// Truncates a value. + /// The value to truncate. + /// The truncation of . + static abstract TSelf Truncate(TSelf x); + + // static abstract TSelf AcosPi(TSelf x); + // + // static abstract TSelf AsinPi(TSelf x); + // + // static abstract TSelf AtanPi(TSelf x); + // + // static abstract TSelf Atan2Pi(TSelf y, TSelf x); + // + // static abstract TSelf Compound(TSelf x, TSelf n); + // + // static abstract TSelf CosPi(TSelf x); + // + // static abstract TSelf ExpM1(TSelf x); + // + // static abstract TSelf Exp2(TSelf x); + // + // static abstract TSelf Exp2M1(TSelf x); + // + // static abstract TSelf Exp10(TSelf x); + // + // static abstract TSelf Exp10M1(TSelf x); + // + // static abstract TSelf Hypot(TSelf x, TSelf y); + // + // static abstract TSelf LogP1(TSelf x); + // + // static abstract TSelf Log2P1(TSelf x); + // + // static abstract TSelf Log10P1(TSelf x); + // + // static abstract TSelf MaxMagnitudeNumber(TSelf x, TSelf y); + // + // static abstract TSelf MaxNumber(TSelf x, TSelf y); + // + // static abstract TSelf MinMagnitudeNumber(TSelf x, TSelf y); + // + // static abstract TSelf MinNumber(TSelf x, TSelf y); + // + // static abstract TSelf Root(TSelf x, TSelf n); + // + // static abstract TSelf SinPi(TSelf x); + // + // static abstract TSelf TanPi(TSelf x); + } + + /// Defines a floating-point type that is represented in a base-2 format. + /// The type that implements the interface. + [RequiresPreviewFeatures] + public interface IBinaryFloatingPoint + : IBinaryNumber, + IFloatingPoint + where TSelf : IBinaryFloatingPoint + { + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/IIncrementOperators.cs b/src/libraries/System.Private.CoreLib/src/System/IIncrementOperators.cs new file mode 100644 index 0000000000000..5b4986a5fc22a --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IIncrementOperators.cs @@ -0,0 +1,29 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for incrementing a given value. + /// The type that implements this interface. + [RequiresPreviewFeatures] + public interface IIncrementOperators + where TSelf : IIncrementOperators + { + /// Increments a value. + /// The value to increment. + /// The result of incrementing . + static abstract TSelf operator ++(TSelf value); + + // /// Increments a value. + // /// The value to increment. + // /// The result of incrementing . + // /// The result of incrementing is not representable by . + // static abstract checked TSelf operator ++(TSelf value); + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/IInteger.cs b/src/libraries/System.Private.CoreLib/src/System/IInteger.cs new file mode 100644 index 0000000000000..a93b439625e98 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IInteger.cs @@ -0,0 +1,47 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines an integer type that is represented in a base-2 format. + /// The type that implements the interface. + [RequiresPreviewFeatures] + public interface IBinaryInteger + : IBinaryNumber, + IShiftOperators + where TSelf : IBinaryInteger + { + /// Computes the number of leading zeros in a value. + /// The value whose leading zeroes are to be counted. + /// The number of leading zeros in . + static abstract TSelf LeadingZeroCount(TSelf value); + + /// Computes the number of bits that are set in a value. + /// The value whose set bits are to be counted. + /// The number of set bits in . + static abstract TSelf PopCount(TSelf value); + + /// Rotates a value left by a given amount. + /// The value which is rotated left by . + /// The amount by which is rotated left. + /// The result of rotating left by . + static abstract TSelf RotateLeft(TSelf value, TSelf rotateAmount); + + /// Rotates a value right by a given amount. + /// The value which is rotated right by . + /// The amount by which is rotated right. + /// The result of rotating right by . + static abstract TSelf RotateRight(TSelf value, TSelf rotateAmount); + + /// Computes the number of trailing zeros in a value. + /// The value whose trailing zeroes are to be counted. + /// The number of trailing zeros in . + static abstract TSelf TrailingZeroCount(TSelf value); + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/IMinMaxValue.cs b/src/libraries/System.Private.CoreLib/src/System/IMinMaxValue.cs new file mode 100644 index 0000000000000..cc1eae3787394 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IMinMaxValue.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for getting the minimum and maximum value of a type. + /// The type that implements this interface. + [RequiresPreviewFeatures] + public interface IMinMaxValue + where TSelf : IMinMaxValue + { + /// Gets the minimum value of the current type. + static abstract TSelf MinValue { get; } + + /// Gets the maximum value of the current type. + static abstract TSelf MaxValue { get; } + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/IModulusOperators.cs b/src/libraries/System.Private.CoreLib/src/System/IModulusOperators.cs new file mode 100644 index 0000000000000..24b5beae107e2 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IModulusOperators.cs @@ -0,0 +1,34 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for computing the modulus or remainder of two values. + /// The type that implements this interface. + /// The type that will divide . + /// The type that contains the modulus or remainder of and . + /// This type represents the % in C# which is often used to compute the remainder and may differ from an actual modulo operation depending on the type that implements the interface. + [RequiresPreviewFeatures] + public interface IModulusOperators + where TSelf : IModulusOperators + { + /// Divides two values together to compute their modulus or remainder. + /// The value which divides. + /// The value which divides . + /// The modulus or remainder of divided-by . + static abstract TResult operator %(TSelf left, TOther right); + + // /// Divides two values together to compute their modulus or remainder. + // /// The value which divides. + // /// The value which divides . + // /// The modulus or remainder of divided-by . + // /// The modulus or remainder of divided-by is not representable by . + // static abstract checked TResult operator %(TSelf left, TOther right); + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/IMultiplicativeIdentity.cs b/src/libraries/System.Private.CoreLib/src/System/IMultiplicativeIdentity.cs new file mode 100644 index 0000000000000..9560071ae51c9 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IMultiplicativeIdentity.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for getting the multiplicative identity of a given type. + /// The type that implements this interface. + /// The type that contains the multiplicative identify of . + [RequiresPreviewFeatures] + public interface IMultiplicativeIdentity + where TSelf : IMultiplicativeIdentity + { + /// Gets the multiplicative identity of the current type. + static abstract TResult MultiplicativeIdentity { get; } + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/IMultiplyOperators.cs b/src/libraries/System.Private.CoreLib/src/System/IMultiplyOperators.cs new file mode 100644 index 0000000000000..e9fc0fc1c1943 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IMultiplyOperators.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for computing the product of two values. + /// The type that implements this interface. + /// The type that will multiply . + /// The type that contains the product of and . + [RequiresPreviewFeatures] + public interface IMultiplyOperators + where TSelf : IMultiplyOperators + { + /// Multiplies two values together to compute their product. + /// The value which multiplies. + /// The value which multiplies . + /// The product of divided-by . + static abstract TResult operator *(TSelf left, TOther right); + + // /// Multiplies two values together to compute their product. + // /// The value which multiplies. + // /// The value which multiplies . + // /// The product of divided-by . + // /// The product of multiplied-by is not representable by . + // static abstract checked TResult operator *(TSelf left, TOther right); + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/INumber.cs b/src/libraries/System.Private.CoreLib/src/System/INumber.cs new file mode 100644 index 0000000000000..c1a4f8b109c34 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/INumber.cs @@ -0,0 +1,192 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a number type. + /// The type that implements the interface. + [RequiresPreviewFeatures] + public interface INumber + : IAdditionOperators, + IAdditiveIdentity, + IComparisonOperators, // implies IEquatableOperators + IDecrementOperators, + IDivisionOperators, + IIncrementOperators, + IModulusOperators, + IMultiplicativeIdentity, + IMultiplyOperators, + ISpanFormattable, // implies IFormattable + ISpanParseable, // implies IParseable + ISubtractionOperators, + IUnaryNegationOperators, + IUnaryPlusOperators + where TSelf : INumber + { + /// Gets the value 1 for the type. + static abstract TSelf One { get; } + + /// Gets the value 0 for the type. + static abstract TSelf Zero { get; } + + /// Computes the absolute of a value. + /// The value for which to get its absolute. + /// The absolute of . + /// The absolute of is not representable by . + static abstract TSelf Abs(TSelf value); + + /// Clamps a value to an inclusive minimum and maximum value. + /// The value to clamp. + /// The inclusive minimum to which should clamp. + /// The inclusive maximum to which should clamp. + /// The result of clamping to the inclusive range of and . + /// is greater than . + static abstract TSelf Clamp(TSelf value, TSelf min, TSelf max); + + /// Creates an instance of the current type from a value. + /// The type of . + /// The value which is used to create the instance of . + /// An instance of created from . + /// is not supported. + /// is not representable by . + static abstract TSelf Create(TOther value) + where TOther : INumber; + + /// Creates an instance of the current type from a value, saturating any values that fall outside the representable range of the current type. + /// The type of . + /// The value which is used to create the instance of . + /// An instance of created from , saturating if falls outside the representable range of . + /// is not supported. + static abstract TSelf CreateSaturating(TOther value) + where TOther : INumber; + + /// Creates an instance of the current type from a value, truncating any values that fall outside the representable range of the current type. + /// The type of . + /// The value which is used to create the instance of . + /// An instance of created from , truncating if falls outside the representable range of . + /// is not supported. + static abstract TSelf CreateTruncating(TOther value) + where TOther : INumber; + + /// Computes the quotient and remainder of two values. + /// The value which divides. + /// The value which divides . + /// The quotient and remainder of divided-by . + static abstract (TSelf Quotient, TSelf Remainder) DivRem(TSelf left, TSelf right); + + /// Compares two values to compute which is greater. + /// The value to compare with . + /// The value to compare with . + /// if it is greater than ; otherwise, . + /// For this method matches the IEEE 754:2019 maximum function. This requires NaN inputs to be propagated back to the caller and for -0.0 to be treated as less than +0.0. + static abstract TSelf Max(TSelf x, TSelf y); + + /// Compares two values to compute which is lesser. + /// The value to compare with . + /// The value to compare with . + /// if it is less than ; otherwise, . + /// For this method matches the IEEE 754:2019 minimum function. This requires NaN inputs to be propagated back to the caller and for -0.0 to be treated as less than +0.0. + static abstract TSelf Min(TSelf x, TSelf y); + + /// Parses a string into a value. + /// The string to parse. + /// A bitwise combination of number styles that can be present in . + /// An object that provides culture-specific formatting information about . + /// The result of parsing . + /// is not a supported value. + /// is null. + /// is not in the correct format. + /// is not representable by . + static abstract TSelf Parse(string s, NumberStyles style, IFormatProvider? provider); + + /// Parses a span of characters into a value. + /// The span of characters to parse. + /// A bitwise combination of number styles that can be present in . + /// An object that provides culture-specific formatting information about . + /// The result of parsing . + /// is not a supported value. + /// is not in the correct format. + /// is not representable by . + static abstract TSelf Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider); + + /// Computes the sign of a value. + /// The value whose sign is to be computed. + /// A positive value if is positive, if is zero, and a negative value if is negative. + /// It is recommended that a function return 1, 0, and -1, respectively. + static abstract TSelf Sign(TSelf value); + + /// Tries to create an instance of the current type from a value. + /// The type of . + /// The value which is used to create the instance of . + /// On return, contains the result of succesfully creating an instance of from or an undefined value on failure. + /// true if an instance of the current type was succesfully created from ; otherwise, false. + /// is not supported. + static abstract bool TryCreate(TOther value, out TSelf result) + where TOther : INumber; + + /// Tries to parses a string into a value. + /// The string to parse. + /// A bitwise combination of number styles that can be present in . + /// An object that provides culture-specific formatting information about . + /// On return, contains the result of succesfully parsing or an undefined value on failure. + /// true if was successfully parsed; otherwise, false. + /// is not a supported value. + static abstract bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out TSelf result); + + /// Tries to parses a span of characters into a value. + /// The span of characters to parse. + /// A bitwise combination of number styles that can be present in . + /// An object that provides culture-specific formatting information about . + /// On return, contains the result of succesfully parsing or an undefined value on failure. + /// true if was successfully parsed; otherwise, false. + /// is not a supported value. + static abstract bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out TSelf result); + } + + /// Defines a number that is represented in a base-2 format. + /// The type that implements the interface. + [RequiresPreviewFeatures] + public interface IBinaryNumber + : IBitwiseOperators, + INumber + where TSelf : IBinaryNumber + { + /// Determines if a value is a power of two. + /// The value to be checked. + /// true if is a power of two; otherwise, false. + static abstract bool IsPow2(TSelf value); + + /// Computes the log2 of a value. + /// The value whose log2 is to be computed. + /// The log2 of . + static abstract TSelf Log2(TSelf value); + } + + /// Defines a number type which can represent both positive and negative values. + /// The type that implements the interface. + [RequiresPreviewFeatures] + public interface ISignedNumber + : INumber + where TSelf : ISignedNumber + { + /// Gets the value -1 for the type. + static abstract TSelf NegativeOne { get; } + } + + /// Defines a number type which can only represent positive values, that is it cannot represent negative values. + /// The type that implements the interface. + [RequiresPreviewFeatures] + public interface IUnsignedNumber + : INumber + where TSelf : IUnsignedNumber + { + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/IParseable.cs b/src/libraries/System.Private.CoreLib/src/System/IParseable.cs new file mode 100644 index 0000000000000..77064639e368a --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IParseable.cs @@ -0,0 +1,35 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Diagnostics.CodeAnalysis; +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for parsing a string to a value. + /// The type that implements this interface. + [RequiresPreviewFeatures] + public interface IParseable + where TSelf : IParseable + { + /// Parses a string into a value. + /// The string to parse. + /// An object that provides culture-specific formatting information about . + /// The result of parsing . + /// is null. + /// is not in the correct format. + /// is not representable by . + static abstract TSelf Parse(string s, IFormatProvider? provider); + + /// Tries to parses a string into a value. + /// The string to parse. + /// An object that provides culture-specific formatting information about . + /// On return, contains the result of succesfully parsing or an undefined value on failure. + /// true if was successfully parsed; otherwise, false. + static abstract bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out TSelf result); + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/IShiftOperators.cs b/src/libraries/System.Private.CoreLib/src/System/IShiftOperators.cs new file mode 100644 index 0000000000000..8ba4d810233dc --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IShiftOperators.cs @@ -0,0 +1,39 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for shifting a value by another value. + /// The type that implements this interface. + /// The type that contains the result of shifting by . + [RequiresPreviewFeatures] + public interface IShiftOperators + where TSelf : IShiftOperators + { + /// Shifts a value left by a given amount. + /// The value which is shifted left by . + /// The amount by which is shifted left. + /// The result of shifting left by . + static abstract TResult operator <<(TSelf value, int shiftAmount); // TODO_GENERIC_MATH: shiftAmount should be TOther + + /// Shifts a value right by a given amount. + /// The value which is shifted right by . + /// The amount by which is shifted right. + /// The result of shifting right by . + /// This operation is meant to perform a signed (otherwise known as an arithmetic) right shift on signed types. + static abstract TResult operator >>(TSelf value, int shiftAmount); // TODO_GENERIC_MATH: shiftAmount should be TOther + + // /// Shifts a value right by a given amount. + // /// The value which is shifted right by . + // /// The amount by which is shifted right. + // /// The result of shifting right by . + // /// This operation is meant to perform n unsigned (otherwise known as a logical) right shift on all types. + // static abstract TResult operator >>>(TSelf value, int shiftAmount); // TODO_GENERIC_MATH: shiftAmount should be TOther + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/ISpanParseable.cs b/src/libraries/System.Private.CoreLib/src/System/ISpanParseable.cs new file mode 100644 index 0000000000000..6264fe1580292 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/ISpanParseable.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for parsing a span of characters to a value. + /// The type that implements this interface. + [RequiresPreviewFeatures] + public interface ISpanParseable : IParseable + where TSelf : ISpanParseable + { + /// Parses a span of characters into a value. + /// The span of characters to parse. + /// An object that provides culture-specific formatting information about . + /// The result of parsing . + /// is not in the correct format. + /// is not representable by . + static abstract TSelf Parse(ReadOnlySpan s, IFormatProvider? provider); + + /// Tries to parses a span of characters into a value. + /// The span of characters to parse. + /// An object that provides culture-specific formatting information about . + /// On return, contains the result of succesfully parsing or an undefined value on failure. + /// true if was successfully parsed; otherwise, false. + static abstract bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out TSelf result); + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/ISubtractionOperators.cs b/src/libraries/System.Private.CoreLib/src/System/ISubtractionOperators.cs new file mode 100644 index 0000000000000..f11da9d2f9812 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/ISubtractionOperators.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for computing the difference of two values. + /// The type that implements this interface. + /// The type that will be subtracted from . + /// The type that contains the difference of subtracted from . + [RequiresPreviewFeatures] + public interface ISubtractionOperators + where TSelf : ISubtractionOperators + { + /// Subtracts two values to compute their difference. + /// The value from which is subtracted. + /// The value which is subtracted from . + /// The difference of subtracted from . + static abstract TResult operator -(TSelf left, TOther right); + + // /// Subtracts two values to compute their difference. + // /// The value from which is subtracted. + // /// The value which is subtracted from . + // /// The difference of subtracted from . + // /// The difference of subtracted from is not representable by . + // static abstract checked TResult operator -(TSelf left, TOther right); + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/IUnaryNegationOperators.cs b/src/libraries/System.Private.CoreLib/src/System/IUnaryNegationOperators.cs new file mode 100644 index 0000000000000..686887ce9c8fd --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IUnaryNegationOperators.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for computing the unary negation of a value. + /// The type that implements this interface. + /// The type that contains the result of negating . + [RequiresPreviewFeatures] + public interface IUnaryNegationOperators + where TSelf : IUnaryNegationOperators + { + /// Computes the unary negation of a value. + /// The value for which to compute its unary negation. + /// The unary negation of . + static abstract TResult operator -(TSelf value); + + // /// Computes the unary negation of a value. + // /// The value for which to compute its unary negation. + // /// The unary negation of . + // /// The unary negation of is not representable by . + // static abstract checked TResult operator -(TSelf value); + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/IUnaryPlusOperators.cs b/src/libraries/System.Private.CoreLib/src/System/IUnaryPlusOperators.cs new file mode 100644 index 0000000000000..a719ff5d0b11e --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IUnaryPlusOperators.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Versioning; + +#if !FEATURE_GENERIC_MATH +#error FEATURE_GENERIC_MATH is not defined +#endif + +namespace System +{ + /// Defines a mechanism for computing the unary plus of a value. + /// The type that implements this interface. + /// The type that contains the result of negating . + [RequiresPreviewFeatures] + public interface IUnaryPlusOperators + where TSelf : IUnaryPlusOperators + { + /// Computes the unary plus of a value. + /// The value for which to compute its unary plus. + /// The unary plus of . + static abstract TResult operator +(TSelf value); + + // /// Computes the unary plus of a value. + // /// The value for which to compute its unary plus. + // /// The unary plus of . + // /// The unary plus of is not representable by . + // static abstract checked TResult operator +(TSelf value); + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/Int16.cs b/src/libraries/System.Private.CoreLib/src/System/Int16.cs index 8f33d790699e9..f42c84de2bd87 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Int16.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Int16.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -13,6 +14,13 @@ namespace System [StructLayout(LayoutKind.Sequential)] [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public readonly struct Int16 : IComparable, IConvertible, ISpanFormattable, IComparable, IEquatable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IBinaryInteger, + IMinMaxValue, + ISignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly short m_value; // Do not rename (binary serialization) @@ -274,5 +282,718 @@ object IConvertible.ToType(Type type, IFormatProvider? provider) { return Convert.DefaultToType((IConvertible)this, type, provider); } + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static short IAdditionOperators.operator +(short left, short right) + => (short)(left + right); + + // [RequiresPreviewFeatures] + // static checked short IAdditionOperators.operator +(short left, short right) + // => checked((short)(left + right)); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static short IAdditiveIdentity.AdditiveIdentity => 0; + + // + // IBinaryInteger + // + + [RequiresPreviewFeatures] + static short IBinaryInteger.LeadingZeroCount(short value) + => (short)(BitOperations.LeadingZeroCount((ushort)value) - 16); + + [RequiresPreviewFeatures] + static short IBinaryInteger.PopCount(short value) + => (short)BitOperations.PopCount((ushort)value); + + [RequiresPreviewFeatures] + static short IBinaryInteger.RotateLeft(short value, short rotateAmount) + => (short)((value << (rotateAmount & 15)) | (value >> ((16 - rotateAmount) & 15))); + + [RequiresPreviewFeatures] + static short IBinaryInteger.RotateRight(short value, short rotateAmount) + => (short)((value >> (rotateAmount & 15)) | (value << ((16 - rotateAmount) & 15))); + + [RequiresPreviewFeatures] + static short IBinaryInteger.TrailingZeroCount(short value) + => (byte)(BitOperations.TrailingZeroCount(value << 16) - 16); + + // + // IBinaryNumber + // + + [RequiresPreviewFeatures] + static bool IBinaryNumber.IsPow2(short value) + => BitOperations.IsPow2(value); + + [RequiresPreviewFeatures] + static short IBinaryNumber.Log2(short value) + { + if (value < 0) + { + ThrowHelper.ThrowValueArgumentOutOfRange_NeedNonNegNumException(); + } + return (short)BitOperations.Log2((ushort)value); + } + + // + // IBitwiseOperators + // + + [RequiresPreviewFeatures] + static short IBitwiseOperators.operator &(short left, short right) + => (short)(left & right); + + [RequiresPreviewFeatures] + static short IBitwiseOperators.operator |(short left, short right) + => (short)(left | right); + + [RequiresPreviewFeatures] + static short IBitwiseOperators.operator ^(short left, short right) + => (short)(left ^ right); + + [RequiresPreviewFeatures] + static short IBitwiseOperators.operator ~(short value) + => (short)(~value); + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(short left, short right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(short left, short right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(short left, short right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(short left, short right) + => left >= right; + + // + // IDecrementOperators + // + + [RequiresPreviewFeatures] + static short IDecrementOperators.operator --(short value) + => value--; + + // [RequiresPreviewFeatures] + // static checked short IDecrementOperators.operator --(short value) + // => checked(value--); + + // + // IDivisionOperators + // + + [RequiresPreviewFeatures] + static short IDivisionOperators.operator /(short left, short right) + => (short)(left / right); + + // [RequiresPreviewFeatures] + // static checked short IDivisionOperators.operator /(short left, short right) + // => checked((short)(left / right)); + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(short left, short right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(short left, short right) + => left != right; + + // + // IIncrementOperators + // + + [RequiresPreviewFeatures] + static short IIncrementOperators.operator ++(short value) + => value++; + + // [RequiresPreviewFeatures] + // static checked short IIncrementOperators.operator ++(short value) + // => checked(value++); + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static short IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static short IMinMaxValue.MaxValue => MaxValue; + + // + // IModulusOperators + // + + [RequiresPreviewFeatures] + static short IModulusOperators.operator %(short left, short right) + => (short)(left % right); + + // [RequiresPreviewFeatures] + // static checked short IModulusOperators.operator %(short left, short right) + // => checked((short)(left % right)); + + // + // IMultiplicativeIdentity + // + + [RequiresPreviewFeatures] + static short IMultiplicativeIdentity.MultiplicativeIdentity => 1; + + // + // IMultiplyOperators + // + + [RequiresPreviewFeatures] + static short IMultiplyOperators.operator *(short left, short right) + => (short)(left * right); + + // [RequiresPreviewFeatures] + // static checked short IMultiplyOperators.operator *(short left, short right) + // => checked((short)(left * right)); + + // + // INumber + // + + [RequiresPreviewFeatures] + static short INumber.One => 1; + + [RequiresPreviewFeatures] + static short INumber.Zero => 0; + + [RequiresPreviewFeatures] + static short INumber.Abs(short value) + => Math.Abs(value); + + [RequiresPreviewFeatures] + static short INumber.Clamp(short value, short min, short max) + => Math.Clamp(value, min, max); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static short INumber.Create(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return checked((short)(char)(object)value); + } + else if (typeof(TOther) == typeof(decimal)) + { + return checked((short)(decimal)(object)value); + } + else if (typeof(TOther) == typeof(double)) + { + return checked((short)(double)(object)value); + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return checked((short)(int)(object)value); + } + else if (typeof(TOther) == typeof(long)) + { + return checked((short)(long)(object)value); + } + else if (typeof(TOther) == typeof(nint)) + { + return checked((short)(nint)(object)value); + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return checked((short)(float)(object)value); + } + else if (typeof(TOther) == typeof(ushort)) + { + return checked((short)(ushort)(object)value); + } + else if (typeof(TOther) == typeof(uint)) + { + return checked((short)(uint)(object)value); + } + else if (typeof(TOther) == typeof(ulong)) + { + return checked((short)(ulong)(object)value); + } + else if (typeof(TOther) == typeof(nuint)) + { + return checked((short)(nuint)(object)value); + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static short INumber.CreateSaturating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + var actualValue = (char)(object)value; + return (actualValue > MaxValue) ? MaxValue : (short)actualValue; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (short)actualValue; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (short)actualValue; + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + var actualValue = (int)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (short)actualValue; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (short)actualValue; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (short)actualValue; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (short)actualValue; + } + else if (typeof(TOther) == typeof(ushort)) + { + var actualValue = (ushort)(object)value; + return (actualValue > MaxValue) ? MaxValue : (short)actualValue; + } + else if (typeof(TOther) == typeof(uint)) + { + var actualValue = (uint)(object)value; + return (actualValue > MaxValue) ? MaxValue : (short)actualValue; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + return (actualValue > (uint)MaxValue) ? MaxValue : (short)actualValue; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + return (actualValue > (uint)MaxValue) ? MaxValue : (short)actualValue; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static short INumber.CreateTruncating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (short)(char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (short)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (short)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (short)(int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (short)(long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (short)(nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (short)(float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (short)(ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (short)(uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (short)(ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (short)(nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + static (short Quotient, short Remainder) INumber.DivRem(short left, short right) + => Math.DivRem(left, right); + + [RequiresPreviewFeatures] + static short INumber.Max(short x, short y) + => Math.Max(x, y); + + [RequiresPreviewFeatures] + static short INumber.Min(short x, short y) + => Math.Min(x, y); + + [RequiresPreviewFeatures] + static short INumber.Parse(string s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static short INumber.Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static short INumber.Sign(short value) + => (short)Math.Sign(value); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static bool INumber.TryCreate(TOther value, out short result) + { + if (typeof(TOther) == typeof(byte)) + { + result = (byte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + var actualValue = (char)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (short)actualValue; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (short)actualValue; + return true; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (short)actualValue; + return true; + } + else if (typeof(TOther) == typeof(short)) + { + result = (short)(object)value; + return true; + } + else if (typeof(TOther) == typeof(int)) + { + var actualValue = (int)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (short)actualValue; + return true; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (short)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (short)actualValue; + return true; + } + else if (typeof(TOther) == typeof(sbyte)) + { + result = (sbyte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (short)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + var actualValue = (ushort)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (short)actualValue; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + var actualValue = (uint)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (short)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + + if (actualValue > (uint)MaxValue) + { + result = default; + return false; + } + + result = (short)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + + if (actualValue > (uint)MaxValue) + { + result = default; + return false; + } + + result = (short)actualValue; + return true; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + result = default; + return false; + } + } + + [RequiresPreviewFeatures] + static bool INumber.TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out short result) + => TryParse(s, style, provider, out result); + + [RequiresPreviewFeatures] + static bool INumber.TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out short result) + => TryParse(s, style, provider, out result); + + // + // IParseable + // + + [RequiresPreviewFeatures] + static short IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out short result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // IShiftOperators + // + + [RequiresPreviewFeatures] + static short IShiftOperators.operator <<(short value, int shiftAmount) + => (short)(value << shiftAmount); + + [RequiresPreviewFeatures] + static short IShiftOperators.operator >>(short value, int shiftAmount) + => (short)(value >> shiftAmount); + + // [RequiresPreviewFeatures] + // static short IShiftOperators.operator >>>(short value, int shiftAmount) + // => (short)((ushort)value >> shiftAmount); + + // + // ISignedNumber + // + + [RequiresPreviewFeatures] + static short ISignedNumber.NegativeOne => -1; + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static short ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, NumberStyles.Integer, provider); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static short ISubtractionOperators.operator -(short left, short right) + => (short)(left - right); + + // [RequiresPreviewFeatures] + // static checked short ISubtractionOperators.operator -(short left, short right) + // => checked((short)(left - right)); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static short IUnaryNegationOperators.operator -(short value) + => (short)(-value); + + // [RequiresPreviewFeatures] + // static checked short IUnaryNegationOperators.operator -(short value) + // => checked((short)(-value)); + + // + // IUnaryPlusOperators + // + + [RequiresPreviewFeatures] + static short IUnaryPlusOperators.operator +(short value) + => (short)(+value); + + // [RequiresPreviewFeatures] + // static checked short IUnaryPlusOperators.operator +(short value) + // => checked((short)(+value)); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Int32.cs b/src/libraries/System.Private.CoreLib/src/System/Int32.cs index 3c46f513dc5a8..d8514bc89f7e7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Int32.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Int32.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -13,6 +14,13 @@ namespace System [StructLayout(LayoutKind.Sequential)] [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public readonly struct Int32 : IComparable, IConvertible, ISpanFormattable, IComparable, IEquatable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IBinaryInteger, + IMinMaxValue, + ISignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly int m_value; // Do not rename (binary serialization) @@ -266,5 +274,695 @@ object IConvertible.ToType(Type type, IFormatProvider? provider) { return Convert.DefaultToType((IConvertible)this, type, provider); } + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static int IAdditionOperators.operator +(int left, int right) + => left + right; + + // [RequiresPreviewFeatures] + // static checked int IAdditionOperators.operator +(int left, int right) + // => checked(left + right); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static int IAdditiveIdentity.AdditiveIdentity => 0; + + // + // IBinaryInteger + // + + [RequiresPreviewFeatures] + static int IBinaryInteger.LeadingZeroCount(int value) + => BitOperations.LeadingZeroCount((uint)value); + + [RequiresPreviewFeatures] + static int IBinaryInteger.PopCount(int value) + => BitOperations.PopCount((uint)value); + + [RequiresPreviewFeatures] + static int IBinaryInteger.RotateLeft(int value, int rotateAmount) + => (int)BitOperations.RotateLeft((uint)value, rotateAmount); + + [RequiresPreviewFeatures] + static int IBinaryInteger.RotateRight(int value, int rotateAmount) + => (int)BitOperations.RotateRight((uint)value, rotateAmount); + + [RequiresPreviewFeatures] + static int IBinaryInteger.TrailingZeroCount(int value) + => BitOperations.TrailingZeroCount(value); + + // + // IBinaryNumber + // + + [RequiresPreviewFeatures] + static bool IBinaryNumber.IsPow2(int value) + => BitOperations.IsPow2(value); + + [RequiresPreviewFeatures] + static int IBinaryNumber.Log2(int value) + { + if (value < 0) + { + ThrowHelper.ThrowValueArgumentOutOfRange_NeedNonNegNumException(); + } + return BitOperations.Log2((uint)value); + } + + // + // IBitwiseOperators + // + + [RequiresPreviewFeatures] + static int IBitwiseOperators.operator &(int left, int right) + => left & right; + + [RequiresPreviewFeatures] + static int IBitwiseOperators.operator |(int left, int right) + => left | right; + + [RequiresPreviewFeatures] + static int IBitwiseOperators.operator ^(int left, int right) + => left ^ right; + + [RequiresPreviewFeatures] + static int IBitwiseOperators.operator ~(int value) + => ~value; + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(int left, int right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(int left, int right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(int left, int right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(int left, int right) + => left >= right; + + // + // IDecrementOperators + // + + [RequiresPreviewFeatures] + static int IDecrementOperators.operator --(int value) + => value--; + + // [RequiresPreviewFeatures] + // static checked int IDecrementOperators.operator --(int value) + // => checked(value--); + + // + // IDivisionOperators + // + + [RequiresPreviewFeatures] + static int IDivisionOperators.operator /(int left, int right) + => left / right; + + // [RequiresPreviewFeatures] + // static checked int IDivisionOperators.operator /(int left, int right) + // => checked(left / right); + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(int left, int right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(int left, int right) + => left != right; + + // + // IIncrementOperators + // + + [RequiresPreviewFeatures] + static int IIncrementOperators.operator ++(int value) + => value++; + + // [RequiresPreviewFeatures] + // static checked int IIncrementOperators.operator ++(int value) + // => checked(value++); + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static int IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static int IMinMaxValue.MaxValue => MaxValue; + + // + // IModulusOperators + // + + [RequiresPreviewFeatures] + static int IModulusOperators.operator %(int left, int right) + => left % right; + + // [RequiresPreviewFeatures] + // static checked int IModulusOperators.operator %(int left, int right) + // => checked(left % right); + + // + // IMultiplicativeIdentity + // + + [RequiresPreviewFeatures] + static int IMultiplicativeIdentity.MultiplicativeIdentity => 1; + + // + // IMultiplyOperators + // + + [RequiresPreviewFeatures] + static int IMultiplyOperators.operator *(int left, int right) + => left * right; + + // [RequiresPreviewFeatures] + // static checked int IMultiplyOperators.operator *(int left, int right) + // => checked(left * right); + + // + // INumber + // + + [RequiresPreviewFeatures] + static int INumber.One => 1; + + [RequiresPreviewFeatures] + static int INumber.Zero => 0; + + [RequiresPreviewFeatures] + static int INumber.Abs(int value) + => Math.Abs(value); + + [RequiresPreviewFeatures] + static int INumber.Clamp(int value, int min, int max) + => Math.Clamp(value, min, max); + + [RequiresPreviewFeatures] + internal static int Create(TOther value) + where TOther : INumber + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return checked((int)(decimal)(object)value); + } + else if (typeof(TOther) == typeof(double)) + { + return checked((int)(double)(object)value); + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return checked((int)(long)(object)value); + } + else if (typeof(TOther) == typeof(nint)) + { + return checked((int)(nint)(object)value); + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return checked((int)(float)(object)value); + } + else if (typeof(TOther) == typeof(ushort)) + { + return checked((int)(ushort)(object)value); + } + else if (typeof(TOther) == typeof(uint)) + { + return checked((int)(uint)(object)value); + } + else if (typeof(TOther) == typeof(ulong)) + { + return checked((int)(ulong)(object)value); + } + else if (typeof(TOther) == typeof(nuint)) + { + return checked((int)(nuint)(object)value); + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static int INumber.Create(TOther value) + => Create(value); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static int INumber.CreateSaturating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (int)actualValue; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (int)actualValue; + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (int)actualValue; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (int)actualValue; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (int)actualValue; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + var actualValue = (uint)(object)value; + return (actualValue > MaxValue) ? MaxValue : (int)actualValue; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + return (actualValue > MaxValue) ? MaxValue : (int)actualValue; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + return (actualValue > MaxValue) ? MaxValue : (int)actualValue; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static int INumber.CreateTruncating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (int)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (int)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (int)(long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (int)(nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (int)(float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (int)(uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (int)(ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (int)(nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + static (int Quotient, int Remainder) INumber.DivRem(int left, int right) + => Math.DivRem(left, right); + + [RequiresPreviewFeatures] + static int INumber.Max(int x, int y) + => Math.Max(x, y); + + [RequiresPreviewFeatures] + static int INumber.Min(int x, int y) + => Math.Min(x, y); + + [RequiresPreviewFeatures] + static int INumber.Parse(string s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static int INumber.Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static int INumber.Sign(int value) + => Math.Sign(value); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static bool INumber.TryCreate(TOther value, out int result) + { + if (typeof(TOther) == typeof(byte)) + { + result = (byte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + result = (char)(object)value; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (int)actualValue; + return true; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (int)actualValue; + return true; + } + else if (typeof(TOther) == typeof(short)) + { + result = (short)(object)value; + return true; + } + else if (typeof(TOther) == typeof(int)) + { + result = (int)(object)value; + return true; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (int)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (int)actualValue; + return true; + } + else if (typeof(TOther) == typeof(sbyte)) + { + result = (sbyte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (int)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + result = (ushort)(object)value; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + var actualValue = (uint)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (int)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (int)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (int)actualValue; + return true; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + result = default; + return false; + } + } + + [RequiresPreviewFeatures] + static bool INumber.TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out int result) + => TryParse(s, style, provider, out result); + + [RequiresPreviewFeatures] + static bool INumber.TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out int result) + => TryParse(s, style, provider, out result); + + // + // IParseable + // + + [RequiresPreviewFeatures] + static int IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out int result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // IShiftOperators + // + + [RequiresPreviewFeatures] + static int IShiftOperators.operator <<(int value, int shiftAmount) + => value << shiftAmount; + + [RequiresPreviewFeatures] + static int IShiftOperators.operator >>(int value, int shiftAmount) + => value >> shiftAmount; + + // [RequiresPreviewFeatures] + // static int IShiftOperators.operator >>>(int value, int shiftAmount) + // => (int)((uint)value >> shiftAmount); + + // + // ISignedNumber + // + + [RequiresPreviewFeatures] + static int ISignedNumber.NegativeOne => -1; + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static int ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, NumberStyles.Integer, provider); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static int ISubtractionOperators.operator -(int left, int right) + => left - right; + + // [RequiresPreviewFeatures] + // static checked int ISubtractionOperators.operator -(int left, int right) + // => checked(left - right); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static int IUnaryNegationOperators.operator -(int value) + => -value; + + // [RequiresPreviewFeatures] + // static checked int IUnaryNegationOperators.operator -(int value) + // => checked(-value); + + // + // IUnaryPlusOperators + // + + [RequiresPreviewFeatures] + static int IUnaryPlusOperators.operator +(int value) + => +value; + + // [RequiresPreviewFeatures] + // static checked int IUnaryPlusOperators.operator +(int value) + // => checked(+value); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Int64.cs b/src/libraries/System.Private.CoreLib/src/System/Int64.cs index 2c53290de5976..c0420f5052e5b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Int64.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Int64.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -13,6 +14,13 @@ namespace System [StructLayout(LayoutKind.Sequential)] [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public readonly struct Int64 : IComparable, IConvertible, ISpanFormattable, IComparable, IEquatable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IBinaryInteger, + IMinMaxValue, + ISignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly long m_value; // Do not rename (binary serialization) @@ -253,5 +261,661 @@ object IConvertible.ToType(Type type, IFormatProvider? provider) { return Convert.DefaultToType((IConvertible)this, type, provider); } + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static long IAdditionOperators.operator +(long left, long right) + => left + right; + + // [RequiresPreviewFeatures] + // static checked long IAdditionOperators.operator +(long left, long right) + // => checked(left + right); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static long IAdditiveIdentity.AdditiveIdentity => 0; + + // + // IBinaryInteger + // + + [RequiresPreviewFeatures] + static long IBinaryInteger.LeadingZeroCount(long value) + => BitOperations.LeadingZeroCount((ulong)value); + + [RequiresPreviewFeatures] + static long IBinaryInteger.PopCount(long value) + => BitOperations.PopCount((ulong)value); + + [RequiresPreviewFeatures] + static long IBinaryInteger.RotateLeft(long value, long rotateAmount) + => (long)BitOperations.RotateLeft((ulong)value, (int)rotateAmount); + + [RequiresPreviewFeatures] + static long IBinaryInteger.RotateRight(long value, long rotateAmount) + => (long)BitOperations.RotateRight((ulong)value, (int)rotateAmount); + + [RequiresPreviewFeatures] + static long IBinaryInteger.TrailingZeroCount(long value) + => BitOperations.TrailingZeroCount(value); + + // + // IBinaryNumber + // + + [RequiresPreviewFeatures] + static bool IBinaryNumber.IsPow2(long value) + => BitOperations.IsPow2(value); + + [RequiresPreviewFeatures] + static long IBinaryNumber.Log2(long value) + { + if (value < 0) + { + ThrowHelper.ThrowValueArgumentOutOfRange_NeedNonNegNumException(); + } + return BitOperations.Log2((ulong)value); + } + + // + // IBitwiseOperators + // + + [RequiresPreviewFeatures] + static long IBitwiseOperators.operator &(long left, long right) + => left & right; + + [RequiresPreviewFeatures] + static long IBitwiseOperators.operator |(long left, long right) + => left | right; + + [RequiresPreviewFeatures] + static long IBitwiseOperators.operator ^(long left, long right) + => left ^ right; + + [RequiresPreviewFeatures] + static long IBitwiseOperators.operator ~(long value) + => ~value; + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(long left, long right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(long left, long right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(long left, long right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(long left, long right) + => left >= right; + + // + // IDecrementOperators + // + + [RequiresPreviewFeatures] + static long IDecrementOperators.operator --(long value) + => value--; + + // [RequiresPreviewFeatures] + // static checked long IDecrementOperators.operator --(long value) + // => checked(value--); + + // + // IDivisionOperators + // + + [RequiresPreviewFeatures] + static long IDivisionOperators.operator /(long left, long right) + => left / right; + + // [RequiresPreviewFeatures] + // static checked long IDivisionOperators.operator /(long left, long right) + // => checked(left / right); + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(long left, long right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(long left, long right) + => left != right; + + // + // IIncrementOperators + // + + [RequiresPreviewFeatures] + static long IIncrementOperators.operator ++(long value) + => value++; + + // [RequiresPreviewFeatures] + // static checked long IIncrementOperators.operator ++(long value) + // => checked(value++); + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static long IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static long IMinMaxValue.MaxValue => MaxValue; + + // + // IModulusOperators + // + + [RequiresPreviewFeatures] + static long IModulusOperators.operator %(long left, long right) + => left % right; + + // [RequiresPreviewFeatures] + // static checked long IModulusOperators.operator %(long left, long right) + // => checked(left % right); + + // + // IMultiplicativeIdentity + // + + [RequiresPreviewFeatures] + static long IMultiplicativeIdentity.MultiplicativeIdentity => 1; + + // + // IMultiplyOperators + // + + [RequiresPreviewFeatures] + static long IMultiplyOperators.operator *(long left, long right) + => left * right; + + // [RequiresPreviewFeatures] + // static checked long IMultiplyOperators.operator *(long left, long right) + // => checked(left * right); + + // + // INumber + // + + [RequiresPreviewFeatures] + static long INumber.One => 1; + + [RequiresPreviewFeatures] + static long INumber.Zero => 0; + + [RequiresPreviewFeatures] + static long INumber.Abs(long value) + => Math.Abs(value); + + [RequiresPreviewFeatures] + static long INumber.Clamp(long value, long min, long max) + => Math.Clamp(value, min, max); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static long INumber.Create(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return checked((long)(decimal)(object)value); + } + else if (typeof(TOther) == typeof(double)) + { + return checked((long)(double)(object)value); + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return checked((long)(float)(object)value); + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return checked((long)(ulong)(object)value); + } + else if (typeof(TOther) == typeof(nuint)) + { + return checked((long)(nuint)(object)value); + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static long INumber.CreateSaturating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (long)actualValue; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (long)actualValue; + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (long)actualValue; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + return (actualValue > MaxValue) ? MaxValue : (long)actualValue; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + return (actualValue > MaxValue) ? MaxValue : (long)actualValue; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static long INumber.CreateTruncating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (long)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (long)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (long)(float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (long)(ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (long)(nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + static (long Quotient, long Remainder) INumber.DivRem(long left, long right) + => Math.DivRem(left, right); + + [RequiresPreviewFeatures] + static long INumber.Max(long x, long y) + => Math.Max(x, y); + + [RequiresPreviewFeatures] + static long INumber.Min(long x, long y) + => Math.Min(x, y); + + [RequiresPreviewFeatures] + static long INumber.Parse(string s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static long INumber.Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static long INumber.Sign(long value) + => Math.Sign(value); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static bool INumber.TryCreate(TOther value, out long result) + { + if (typeof(TOther) == typeof(byte)) + { + result = (byte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + result = (char)(object)value; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (long)actualValue; + return true; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (long)actualValue; + return true; + } + else if (typeof(TOther) == typeof(short)) + { + result = (short)(object)value; + return true; + } + else if (typeof(TOther) == typeof(int)) + { + result = (int)(object)value; + return true; + } + else if (typeof(TOther) == typeof(long)) + { + result = (long)(object)value; + return true; + } + else if (typeof(TOther) == typeof(nint)) + { + result = (nint)(object)value; + return true; + } + else if (typeof(TOther) == typeof(sbyte)) + { + result = (sbyte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (long)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + result = (ushort)(object)value; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + result = (uint)(object)value; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (long)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (long)actualValue; + return true; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + result = default; + return false; + } + } + + [RequiresPreviewFeatures] + static bool INumber.TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out long result) + => TryParse(s, style, provider, out result); + + [RequiresPreviewFeatures] + static bool INumber.TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out long result) + => TryParse(s, style, provider, out result); + + // + // IParseable + // + + [RequiresPreviewFeatures] + static long IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out long result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // IShiftOperators + // + + [RequiresPreviewFeatures] + static long IShiftOperators.operator <<(long value, int shiftAmount) + => value << (int)shiftAmount; + + [RequiresPreviewFeatures] + static long IShiftOperators.operator >>(long value, int shiftAmount) + => value >> (int)shiftAmount; + + // [RequiresPreviewFeatures] + // static long IShiftOperators.operator >>>(long value, int shiftAmount) + // => (long)((ulong)value >> (int)shiftAmount); + + // + // ISignedNumber + // + + [RequiresPreviewFeatures] + static long ISignedNumber.NegativeOne => -1; + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static long ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, NumberStyles.Integer, provider); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static long ISubtractionOperators.operator -(long left, long right) + => left - right; + + // [RequiresPreviewFeatures] + // static checked long ISubtractionOperators.operator -(long left, long right) + // => checked(left - right); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static long IUnaryNegationOperators.operator -(long value) + => -value; + + // [RequiresPreviewFeatures] + // static checked long IUnaryNegationOperators.operator -(long value) + // => checked(-value); + + // + // IUnaryPlusOperators + // + + [RequiresPreviewFeatures] + static long IUnaryPlusOperators.operator +(long value) + => +value; + + // [RequiresPreviewFeatures] + // static checked long IUnaryPlusOperators.operator +(long value) + // => checked(+value); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs b/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs index 16735ffc4210a..f64effb167adf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; @@ -21,7 +22,14 @@ namespace System [Serializable] [StructLayout(LayoutKind.Sequential)] [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] - public readonly struct IntPtr : IEquatable, IComparable, IComparable, ISpanFormattable, ISerializable + public readonly struct IntPtr : IEquatable, IComparable, IComparable, ISpanFormattable, ISerializable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IBinaryInteger, + IMinMaxValue, + ISignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { // WARNING: We allow diagnostic tools to directly inspect this member (_value). // See https://github.com/dotnet/corert/blob/master/Documentation/design-docs/diagnostics/diagnostics-tools-contract.md for more details. @@ -240,5 +248,734 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro Unsafe.SkipInit(out result); return nint_t.TryParse(s, style, provider, out Unsafe.As(ref result)); } + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static nint IAdditionOperators.operator +(nint left, nint right) + => left + right; + + // [RequiresPreviewFeatures] + // static checked nint IAdditionOperators.operator +(nint left, nint right) + // => checked(left + right); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static nint IAdditiveIdentity.AdditiveIdentity => 0; + + // + // IBinaryInteger + // + + [RequiresPreviewFeatures] + static nint IBinaryInteger.LeadingZeroCount(nint value) + { + if (Environment.Is64BitProcess) + { + return BitOperations.LeadingZeroCount((uint)value); + } + else + { + return BitOperations.LeadingZeroCount((ulong)value); + } + } + + [RequiresPreviewFeatures] + static nint IBinaryInteger.PopCount(nint value) + { + if (Environment.Is64BitProcess) + { + return BitOperations.PopCount((uint)value); + } + else + { + return BitOperations.PopCount((ulong)value); + } + } + + [RequiresPreviewFeatures] + static nint IBinaryInteger.RotateLeft(nint value, nint rotateAmount) + { + if (Environment.Is64BitProcess) + { + return (nint)BitOperations.RotateLeft((uint)value, (int)rotateAmount); + } + else + { + return (nint)BitOperations.RotateLeft((ulong)value, (int)rotateAmount); + } + } + + [RequiresPreviewFeatures] + static nint IBinaryInteger.RotateRight(nint value, nint rotateAmount) + + { + if (Environment.Is64BitProcess) + { + return (nint)BitOperations.RotateRight((uint)value, (int)rotateAmount); + } + else + { + return (nint)BitOperations.RotateRight((ulong)value, (int)rotateAmount); + } + } + + [RequiresPreviewFeatures] + static nint IBinaryInteger.TrailingZeroCount(nint value) + { + if (Environment.Is64BitProcess) + { + return BitOperations.TrailingZeroCount((uint)value); + } + else + { + return BitOperations.TrailingZeroCount((ulong)value); + } + } + + // + // IBinaryNumber + // + + [RequiresPreviewFeatures] + static bool IBinaryNumber.IsPow2(nint value) + => BitOperations.IsPow2(value); + + [RequiresPreviewFeatures] + static nint IBinaryNumber.Log2(nint value) + { + if (value < 0) + { + ThrowHelper.ThrowValueArgumentOutOfRange_NeedNonNegNumException(); + } + + if (Environment.Is64BitProcess) + { + return BitOperations.Log2((uint)value); + } + else + { + return BitOperations.Log2((ulong)value); + } + } + + // + // IBitwiseOperators + // + + [RequiresPreviewFeatures] + static nint IBitwiseOperators.operator &(nint left, nint right) + => left & right; + + [RequiresPreviewFeatures] + static nint IBitwiseOperators.operator |(nint left, nint right) + => left | right; + + [RequiresPreviewFeatures] + static nint IBitwiseOperators.operator ^(nint left, nint right) + => left ^ right; + + [RequiresPreviewFeatures] + static nint IBitwiseOperators.operator ~(nint value) + => ~value; + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(nint left, nint right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(nint left, nint right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(nint left, nint right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(nint left, nint right) + => left >= right; + + // + // IDecrementOperators + // + + [RequiresPreviewFeatures] + static nint IDecrementOperators.operator --(nint value) + => value--; + + // [RequiresPreviewFeatures] + // static checked nint IDecrementOperators.operator --(nint value) + // => checked(value--); + + // + // IDivisionOperators + // + + [RequiresPreviewFeatures] + static nint IDivisionOperators.operator /(nint left, nint right) + => left / right; + + // [RequiresPreviewFeatures] + // static checked nint IDivisionOperators.operator /(nint left, nint right) + // => checked(left / right); + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(nint left, nint right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(nint left, nint right) + => left != right; + + // + // IIncrementOperators + // + + [RequiresPreviewFeatures] + static nint IIncrementOperators.operator ++(nint value) + => value++; + + // [RequiresPreviewFeatures] + // static checked nint IIncrementOperators.operator ++(nint value) + // => checked(value++); + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static nint IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static nint IMinMaxValue.MaxValue => MaxValue; + + // + // IModulusOperators + // + + [RequiresPreviewFeatures] + static nint IModulusOperators.operator %(nint left, nint right) + => left % right; + + // [RequiresPreviewFeatures] + // static checked nint IModulusOperators.operator %(nint left, nint right) + // => checked(left % right); + + // + // IMultiplicativeIdentity + // + + [RequiresPreviewFeatures] + static nint IMultiplicativeIdentity.MultiplicativeIdentity => 1; + + // + // IMultiplyOperators + // + + [RequiresPreviewFeatures] + static nint IMultiplyOperators.operator *(nint left, nint right) + => left * right; + + // [RequiresPreviewFeatures] + // static checked nint IMultiplyOperators.operator *(nint left, nint right) + // => checked(left * right); + + // + // INumber + // + + [RequiresPreviewFeatures] + static nint INumber.One => 1; + + [RequiresPreviewFeatures] + static nint INumber.Zero => 0; + + [RequiresPreviewFeatures] + static nint INumber.Abs(nint value) + => Math.Abs(value); + + [RequiresPreviewFeatures] + static nint INumber.Clamp(nint value, nint min, nint max) + => Math.Clamp(value, min, max); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static nint INumber.Create(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return checked((nint)(decimal)(object)value); + } + else if (typeof(TOther) == typeof(double)) + { + return checked((nint)(double)(object)value); + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return checked((nint)(long)(object)value); + } + else if (typeof(TOther) == typeof(nint)) + { + return (nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return checked((nint)(float)(object)value); + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return checked((nint)(uint)(object)value); + } + else if (typeof(TOther) == typeof(ulong)) + { + return checked((nint)(ulong)(object)value); + } + else if (typeof(TOther) == typeof(nuint)) + { + return checked((nint)(nuint)(object)value); + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static nint INumber.CreateSaturating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (nint)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + return (actualValue > nint.MaxValue) ? MaxValue : + (actualValue < nint.MinValue) ? MinValue : (nint)actualValue; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + return (actualValue > nint.MaxValue) ? MaxValue : + (actualValue < nint.MinValue) ? MinValue : (nint)actualValue; + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + return (actualValue > nint.MaxValue) ? MaxValue : + (actualValue < nint.MinValue) ? MinValue : (nint)actualValue; + } + else if (typeof(TOther) == typeof(nint)) + { + return (nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + return (actualValue > nint.MaxValue) ? MaxValue : + (actualValue < nint.MinValue) ? MinValue : (nint)actualValue; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + var actualValue = (uint)(object)value; + return (actualValue > nint.MaxValue) ? MaxValue : (nint)actualValue; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + return (actualValue > (nuint)nint.MaxValue) ? MaxValue : (nint)actualValue; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + return (actualValue > (nuint)nint.MaxValue) ? MaxValue : (nint)actualValue; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static nint INumber.CreateTruncating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (nint)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (nint)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (nint)(long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (nint)(float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (nint)(uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (nint)(ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (nint)(nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + static (nint Quotient, nint Remainder) INumber.DivRem(nint left, nint right) + => Math.DivRem(left, right); + + [RequiresPreviewFeatures] + static nint INumber.Max(nint x, nint y) + => Math.Max(x, y); + + [RequiresPreviewFeatures] + static nint INumber.Min(nint x, nint y) + => Math.Min(x, y); + + [RequiresPreviewFeatures] + static nint INumber.Parse(string s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static nint INumber.Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static nint INumber.Sign(nint value) + => Math.Sign(value); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static bool INumber.TryCreate(TOther value, out nint result) + { + if (typeof(TOther) == typeof(byte)) + { + result = (byte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + result = (char)(object)value; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + + if ((actualValue < nint.MinValue) || (actualValue > nint.MaxValue)) + { + result = default; + return false; + } + + result = (nint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + + if ((actualValue < nint.MinValue) || (actualValue > nint.MaxValue)) + { + result = default; + return false; + } + + result = (nint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(short)) + { + result = (short)(object)value; + return true; + } + else if (typeof(TOther) == typeof(int)) + { + result = (int)(object)value; + return true; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + + if ((actualValue < nint.MinValue) || (actualValue > nint.MaxValue)) + { + result = default; + return false; + } + + result = (nint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nint)) + { + result = (nint)(object)value; + return true; + } + else if (typeof(TOther) == typeof(sbyte)) + { + result = (sbyte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + + if ((actualValue < nint.MinValue) || (actualValue > nint.MaxValue)) + { + result = default; + return false; + } + + result = (nint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + result = (ushort)(object)value; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + var actualValue = (uint)(object)value; + + if (actualValue > nint.MaxValue) + { + result = default; + return false; + } + + result = (nint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + + if (actualValue > (nuint)nint.MaxValue) + { + result = default; + return false; + } + + result = (nint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + + if (actualValue > (nuint)nint.MaxValue) + { + result = default; + return false; + } + + result = (nint)actualValue; + return true; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + result = default; + return false; + } + } + + [RequiresPreviewFeatures] + static bool INumber.TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out nint result) + => TryParse(s, style, provider, out result); + + [RequiresPreviewFeatures] + static bool INumber.TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out nint result) + => TryParse(s, style, provider, out result); + + // + // IParseable + // + + [RequiresPreviewFeatures] + static nint IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out nint result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // IShiftOperators + // + + [RequiresPreviewFeatures] + static nint IShiftOperators.operator <<(nint value, int shiftAmount) + => value << (int)shiftAmount; + + [RequiresPreviewFeatures] + static nint IShiftOperators.operator >>(nint value, int shiftAmount) + => value >> (int)shiftAmount; + + // [RequiresPreviewFeatures] + // static nint IShiftOperators.operator >>>(nint value, int shiftAmount) + // => (nint)((nuint)value >> (int)shiftAmount); + + // + // ISignedNumber + // + + [RequiresPreviewFeatures] + static nint ISignedNumber.NegativeOne => -1; + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static nint ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, NumberStyles.Integer, provider); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static nint ISubtractionOperators.operator -(nint left, nint right) + => left - right; + + // [RequiresPreviewFeatures] + // static checked nint ISubtractionOperators.operator -(nint left, nint right) + // => checked(left - right); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static nint IUnaryNegationOperators.operator -(nint value) + => -value; + + // [RequiresPreviewFeatures] + // static checked nint IUnaryNegationOperators.operator -(nint value) + // => checked(-value); + + // + // IUnaryPlusOperators + // + + [RequiresPreviewFeatures] + static nint IUnaryPlusOperators.operator +(nint value) + => +value; + + // [RequiresPreviewFeatures] + // static checked nint IUnaryPlusOperators.operator +(nint value) + // => checked(+value); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/SByte.cs b/src/libraries/System.Private.CoreLib/src/System/SByte.cs index 880492a459757..cec0716214ffb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SByte.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SByte.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -14,6 +15,13 @@ namespace System [StructLayout(LayoutKind.Sequential)] [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public readonly struct SByte : IComparable, IConvertible, ISpanFormattable, IComparable, IEquatable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IBinaryInteger, + IMinMaxValue, + ISignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly sbyte m_value; // Do not rename (binary serialization) @@ -283,5 +291,737 @@ object IConvertible.ToType(Type type, IFormatProvider? provider) { return Convert.DefaultToType((IConvertible)this, type, provider); } + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static sbyte IAdditionOperators.operator +(sbyte left, sbyte right) + => (sbyte)(left + right); + + // [RequiresPreviewFeatures] + // static checked sbyte IAdditionOperators.operator +(sbyte left, sbyte right) + // => checked((sbyte)(left + right)); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static sbyte IAdditiveIdentity.AdditiveIdentity => 0; + + // + // IBinaryInteger + // + + [RequiresPreviewFeatures] + static sbyte IBinaryInteger.LeadingZeroCount(sbyte value) + => (sbyte)(BitOperations.LeadingZeroCount((byte)value) - 16); + + [RequiresPreviewFeatures] + static sbyte IBinaryInteger.PopCount(sbyte value) + => (sbyte)BitOperations.PopCount((byte)value); + + [RequiresPreviewFeatures] + static sbyte IBinaryInteger.RotateLeft(sbyte value, sbyte rotateAmount) + => (sbyte)((value << (rotateAmount & 7)) | (value >> ((8 - rotateAmount) & 7))); + + [RequiresPreviewFeatures] + static sbyte IBinaryInteger.RotateRight(sbyte value, sbyte rotateAmount) + => (sbyte)((value >> (rotateAmount & 7)) | (value << ((8 - rotateAmount) & 7))); + + [RequiresPreviewFeatures] + static sbyte IBinaryInteger.TrailingZeroCount(sbyte value) + => (sbyte)(BitOperations.TrailingZeroCount(value << 24) - 24); + + // + // IBinaryNumber + // + + [RequiresPreviewFeatures] + static bool IBinaryNumber.IsPow2(sbyte value) + => BitOperations.IsPow2(value); + + [RequiresPreviewFeatures] + static sbyte IBinaryNumber.Log2(sbyte value) + { + if (value < 0) + { + ThrowHelper.ThrowValueArgumentOutOfRange_NeedNonNegNumException(); + } + return (sbyte)BitOperations.Log2((byte)value); + } + + // + // IBitwiseOperators + // + + [RequiresPreviewFeatures] + static sbyte IBitwiseOperators.operator &(sbyte left, sbyte right) + => (sbyte)(left & right); + + [RequiresPreviewFeatures] + static sbyte IBitwiseOperators.operator |(sbyte left, sbyte right) + => (sbyte)(left | right); + + [RequiresPreviewFeatures] + static sbyte IBitwiseOperators.operator ^(sbyte left, sbyte right) + => (sbyte)(left ^ right); + + [RequiresPreviewFeatures] + static sbyte IBitwiseOperators.operator ~(sbyte value) + => (sbyte)(~value); + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(sbyte left, sbyte right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(sbyte left, sbyte right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(sbyte left, sbyte right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(sbyte left, sbyte right) + => left >= right; + + // + // IDecrementOperators + // + + [RequiresPreviewFeatures] + static sbyte IDecrementOperators.operator --(sbyte value) + => value--; + + // [RequiresPreviewFeatures] + // static checked sbyte IDecrementOperators.operator --(sbyte value) + // => checked(value--); + + // + // IDivisionOperators + // + + [RequiresPreviewFeatures] + static sbyte IDivisionOperators.operator /(sbyte left, sbyte right) + => (sbyte)(left / right); + + // [RequiresPreviewFeatures] + // static checked sbyte IDivisionOperators.operator /(sbyte left, sbyte right) + // => checked((sbyte)(left / right)); + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(sbyte left, sbyte right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(sbyte left, sbyte right) + => left != right; + + // + // IIncrementOperators + // + + [RequiresPreviewFeatures] + static sbyte IIncrementOperators.operator ++(sbyte value) + => value++; + + // [RequiresPreviewFeatures] + // static checked sbyte IIncrementOperators.operator ++(sbyte value) + // => checked(value++); + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static sbyte IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static sbyte IMinMaxValue.MaxValue => MaxValue; + + // + // IModulusOperators + // + + [RequiresPreviewFeatures] + static sbyte IModulusOperators.operator %(sbyte left, sbyte right) + => (sbyte)(left % right); + + // [RequiresPreviewFeatures] + // static checked sbyte IModulusOperators.operator %(sbyte left, sbyte right) + // => checked((sbyte)(left % right)); + + // + // IMultiplicativeIdentity + // + + [RequiresPreviewFeatures] + static sbyte IMultiplicativeIdentity.MultiplicativeIdentity => 1; + + // + // IMultiplyOperators + // + + [RequiresPreviewFeatures] + static sbyte IMultiplyOperators.operator *(sbyte left, sbyte right) + => (sbyte)(left * right); + + // [RequiresPreviewFeatures] + // static checked sbyte IMultiplyOperators.operator *(sbyte left, sbyte right) + // => checked((sbyte)(left * right)); + + // + // INumber + // + + [RequiresPreviewFeatures] + static sbyte INumber.One => 1; + + [RequiresPreviewFeatures] + static sbyte INumber.Zero => 0; + + [RequiresPreviewFeatures] + static sbyte INumber.Abs(sbyte value) + => Math.Abs(value); + + [RequiresPreviewFeatures] + static sbyte INumber.Clamp(sbyte value, sbyte min, sbyte max) + => Math.Clamp(value, min, max); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static sbyte INumber.Create(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return checked((sbyte)(byte)(object)value); + } + else if (typeof(TOther) == typeof(char)) + { + return checked((sbyte)(char)(object)value); + } + else if (typeof(TOther) == typeof(decimal)) + { + return checked((sbyte)(decimal)(object)value); + } + else if (typeof(TOther) == typeof(double)) + { + return checked((sbyte)(double)(object)value); + } + else if (typeof(TOther) == typeof(short)) + { + return checked((sbyte)(short)(object)value); + } + else if (typeof(TOther) == typeof(int)) + { + return checked((sbyte)(int)(object)value); + } + else if (typeof(TOther) == typeof(long)) + { + return checked((sbyte)(long)(object)value); + } + else if (typeof(TOther) == typeof(nint)) + { + return checked((sbyte)(nint)(object)value); + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return checked((sbyte)(float)(object)value); + } + else if (typeof(TOther) == typeof(ushort)) + { + return checked((sbyte)(ushort)(object)value); + } + else if (typeof(TOther) == typeof(uint)) + { + return checked((sbyte)(uint)(object)value); + } + else if (typeof(TOther) == typeof(ulong)) + { + return checked((sbyte)(ulong)(object)value); + } + else if (typeof(TOther) == typeof(nuint)) + { + return checked((sbyte)(nuint)(object)value); + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static sbyte INumber.CreateSaturating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + var actualValue = (byte)(object)value; + return (actualValue > MaxValue) ? MaxValue : (sbyte)actualValue; + } + else if (typeof(TOther) == typeof(char)) + { + var actualValue = (char)(object)value; + return (actualValue > MaxValue) ? MaxValue : (sbyte)actualValue; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (sbyte)actualValue; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (sbyte)actualValue; + } + else if (typeof(TOther) == typeof(short)) + { + var actualValue = (short)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (sbyte)actualValue; + } + else if (typeof(TOther) == typeof(int)) + { + var actualValue = (int)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (sbyte)actualValue; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (sbyte)actualValue; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (sbyte)actualValue; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < MinValue) ? MinValue : (sbyte)actualValue; + } + else if (typeof(TOther) == typeof(ushort)) + { + var actualValue = (ushort)(object)value; + return (actualValue > MaxValue) ? MaxValue : (sbyte)actualValue; + } + else if (typeof(TOther) == typeof(uint)) + { + var actualValue = (uint)(object)value; + return (actualValue > MaxValue) ? MaxValue : (sbyte)actualValue; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + return (actualValue > (uint)MaxValue) ? MaxValue : (sbyte)actualValue; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + return (actualValue > (uint)MaxValue) ? MaxValue : (sbyte)actualValue; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static sbyte INumber.CreateTruncating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (sbyte)(byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (sbyte)(char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (sbyte)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (sbyte)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (sbyte)(short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (sbyte)(int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (sbyte)(long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (sbyte)(nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (sbyte)(float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (sbyte)(ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (sbyte)(uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (sbyte)(ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (sbyte)(nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + static (sbyte Quotient, sbyte Remainder) INumber.DivRem(sbyte left, sbyte right) + => Math.DivRem(left, right); + + [RequiresPreviewFeatures] + static sbyte INumber.Max(sbyte x, sbyte y) + => Math.Max(x, y); + + [RequiresPreviewFeatures] + static sbyte INumber.Min(sbyte x, sbyte y) + => Math.Min(x, y); + + [RequiresPreviewFeatures] + static sbyte INumber.Parse(string s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static sbyte INumber.Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static sbyte INumber.Sign(sbyte value) + => (sbyte)Math.Sign(value); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static bool INumber.TryCreate(TOther value, out sbyte result) + { + if (typeof(TOther) == typeof(byte)) + { + var actualValue = (byte)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (sbyte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + var actualValue = (char)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (sbyte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (sbyte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (sbyte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(short)) + { + var actualValue = (short)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (sbyte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(int)) + { + var actualValue = (int)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (sbyte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (sbyte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (sbyte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(sbyte)) + { + result = (sbyte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (sbyte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + var actualValue = (ushort)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (sbyte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + var actualValue = (uint)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (sbyte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + + if (actualValue > (uint)MaxValue) + { + result = default; + return false; + } + + result = (sbyte)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + + if (actualValue > (uint)MaxValue) + { + result = default; + return false; + } + + result = (sbyte)actualValue; + return true; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + result = default; + return false; + } + } + + [RequiresPreviewFeatures] + static bool INumber.TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out sbyte result) + => TryParse(s, style, provider, out result); + + [RequiresPreviewFeatures] + static bool INumber.TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out sbyte result) + => TryParse(s, style, provider, out result); + + // + // IParseable + // + + [RequiresPreviewFeatures] + static sbyte IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out sbyte result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // IShiftOperators + // + + [RequiresPreviewFeatures] + static sbyte IShiftOperators.operator <<(sbyte value, int shiftAmount) + => (sbyte)(value << shiftAmount); + + [RequiresPreviewFeatures] + static sbyte IShiftOperators.operator >>(sbyte value, int shiftAmount) + => (sbyte)(value >> shiftAmount); + + // [RequiresPreviewFeatures] + // static sbyte IShiftOperators.operator >>>(sbyte value, int shiftAmount) + // => (sbyte)((byte)value >> shiftAmount); + + // + // ISignedNumber + // + + [RequiresPreviewFeatures] + static sbyte ISignedNumber.NegativeOne => -1; + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static sbyte ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, NumberStyles.Integer, provider); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static sbyte ISubtractionOperators.operator -(sbyte left, sbyte right) + => (sbyte)(left - right); + + // [RequiresPreviewFeatures] + // static checked sbyte ISubtractionOperators.operator -(sbyte left, sbyte right) + // => checked((sbyte)(left - right)); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static sbyte IUnaryNegationOperators.operator -(sbyte value) + => (sbyte)(-value); + + // [RequiresPreviewFeatures] + // static checked sbyte IUnaryNegationOperators.operator -(sbyte value) + // => checked((sbyte)(-value)); + + // + // IUnaryPlusOperators + // + + [RequiresPreviewFeatures] + static sbyte IUnaryPlusOperators.operator +(sbyte value) + => (sbyte)(+value); + + // [RequiresPreviewFeatures] + // static checked sbyte IUnaryPlusOperators.operator +(sbyte value) + // => checked((sbyte)(+value)); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Single.cs b/src/libraries/System.Private.CoreLib/src/System/Single.cs index 8ba2e6e1496dc..92dc3a9b6dfb5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Single.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Single.cs @@ -24,6 +24,12 @@ namespace System [StructLayout(LayoutKind.Sequential)] [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public readonly struct Single : IComparable, IConvertible, ISpanFormattable, IComparable, IEquatable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IBinaryFloatingPoint, + IMinMaxValue +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly float m_value; // Do not rename (binary serialization) @@ -46,11 +52,11 @@ namespace System internal const uint SignMask = 0x8000_0000; internal const int SignShift = 31; - internal const int ShiftedSignMask = (int)(SignMask >> SignShift); + internal const uint ShiftedSignMask = SignMask >> SignShift; internal const uint ExponentMask = 0x7F80_0000; internal const int ExponentShift = 23; - internal const int ShiftedExponentMask = (int)(ExponentMask >> ExponentShift); + internal const uint ShiftedExponentMask = ExponentMask >> ExponentShift; internal const uint SignificandMask = 0x007F_FFFF; @@ -140,7 +146,7 @@ public static unsafe bool IsSubnormal(float f) internal static int ExtractExponentFromBits(uint bits) { - return (int)(bits >> ExponentShift) & ShiftedExponentMask; + return (int)(bits >> ExponentShift) & (int)ShiftedExponentMask; } internal static uint ExtractSignificandFromBits(uint bits) @@ -436,5 +442,826 @@ object IConvertible.ToType(Type type, IFormatProvider? provider) { return Convert.DefaultToType((IConvertible)this, type, provider); } + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static float IAdditionOperators.operator +(float left, float right) + => left + right; + + // [RequiresPreviewFeatures] + // static checked float IAdditionOperators.operator +(float left, float right) + // => checked(left + right); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static float IAdditiveIdentity.AdditiveIdentity => 0.0f; + + // + // IBinaryNumber + // + + [RequiresPreviewFeatures] + static bool IBinaryNumber.IsPow2(float value) + { + uint bits = BitConverter.SingleToUInt32Bits(value); + + uint exponent = (bits >> ExponentShift) & ShiftedExponentMask; + uint significand = bits & SignificandMask; + + return (value > 0) + && (exponent != MinExponent) && (exponent != MaxExponent) + && (significand == MinSignificand); + } + + [RequiresPreviewFeatures] + static float IBinaryNumber.Log2(float value) + => MathF.Log2(value); + + // + // IBitwiseOperators + // + + [RequiresPreviewFeatures] + static float IBitwiseOperators.operator &(float left, float right) + { + uint bits = BitConverter.SingleToUInt32Bits(left) & BitConverter.SingleToUInt32Bits(right); + return BitConverter.UInt32BitsToSingle(bits); + } + + [RequiresPreviewFeatures] + static float IBitwiseOperators.operator |(float left, float right) + { + uint bits = BitConverter.SingleToUInt32Bits(left) | BitConverter.SingleToUInt32Bits(right); + return BitConverter.UInt32BitsToSingle(bits); + } + + [RequiresPreviewFeatures] + static float IBitwiseOperators.operator ^(float left, float right) + { + uint bits = BitConverter.SingleToUInt32Bits(left) ^ BitConverter.SingleToUInt32Bits(right); + return BitConverter.UInt32BitsToSingle(bits); + } + + [RequiresPreviewFeatures] + static float IBitwiseOperators.operator ~(float value) + { + uint bits = ~BitConverter.SingleToUInt32Bits(value); + return BitConverter.UInt32BitsToSingle(bits); + } + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(float left, float right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(float left, float right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(float left, float right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(float left, float right) + => left >= right; + + // + // IDecrementOperators + // + + [RequiresPreviewFeatures] + static float IDecrementOperators.operator --(float value) + => value--; + + // [RequiresPreviewFeatures] + // static checked float IDecrementOperators.operator --(float value) + // => checked(value--); + + // + // IDivisionOperators + // + + [RequiresPreviewFeatures] + static float IDivisionOperators.operator /(float left, float right) + => left / right; + + // [RequiresPreviewFeatures] + // static checked float IDivisionOperators.operator /(float left, float right) + // => checked(left / right); + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(float left, float right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(float left, float right) + => left != right; + + // + // IFloatingPoint + // + + [RequiresPreviewFeatures] + static float IFloatingPoint.E => MathF.E; + + [RequiresPreviewFeatures] + static float IFloatingPoint.Epsilon => Epsilon; + + [RequiresPreviewFeatures] + static float IFloatingPoint.NaN => NaN; + + [RequiresPreviewFeatures] + static float IFloatingPoint.NegativeInfinity => NegativeInfinity; + + [RequiresPreviewFeatures] + static float IFloatingPoint.NegativeZero => -0.0f; + + [RequiresPreviewFeatures] + static float IFloatingPoint.Pi => MathF.PI; + + [RequiresPreviewFeatures] + static float IFloatingPoint.PositiveInfinity => PositiveInfinity; + + [RequiresPreviewFeatures] + static float IFloatingPoint.Tau => MathF.Tau; + + [RequiresPreviewFeatures] + static float IFloatingPoint.Acos(float x) + => MathF.Acos(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Acosh(float x) + => MathF.Acosh(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Asin(float x) + => MathF.Asin(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Asinh(float x) + => MathF.Asinh(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Atan(float x) + => MathF.Atan(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Atan2(float y, float x) + => MathF.Atan2(y, x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Atanh(float x) + => MathF.Atanh(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.BitIncrement(float x) + => MathF.BitIncrement(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.BitDecrement(float x) + => MathF.BitDecrement(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Cbrt(float x) + => MathF.Cbrt(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Ceiling(float x) + => MathF.Ceiling(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.CopySign(float x, float y) + => MathF.CopySign(x, y); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Cos(float x) + => MathF.Cos(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Cosh(float x) + => MathF.Cosh(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Exp(float x) + => MathF.Exp(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Floor(float x) + => MathF.Floor(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.FusedMultiplyAdd(float left, float right, float addend) + => MathF.FusedMultiplyAdd(left, right, addend); + + [RequiresPreviewFeatures] + static float IFloatingPoint.IEEERemainder(float left, float right) + => MathF.IEEERemainder(left, right); + + [RequiresPreviewFeatures] + static TInteger IFloatingPoint.ILogB(float x) + => TInteger.Create(MathF.ILogB(x)); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Log(float x) + => MathF.Log(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Log(float x, float newBase) + => MathF.Log(x, newBase); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Log2(float x) + => MathF.Log2(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Log10(float x) + => MathF.Log10(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.MaxMagnitude(float x, float y) + => MathF.MaxMagnitude(x, y); + + [RequiresPreviewFeatures] + static float IFloatingPoint.MinMagnitude(float x, float y) + => MathF.MinMagnitude(x, y); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Pow(float x, float y) + => MathF.Pow(x, y); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Round(float x) + => MathF.Round(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Round(float x, TInteger digits) + => MathF.Round(x, int.Create(digits)); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Round(float x, MidpointRounding mode) + => MathF.Round(x, mode); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Round(float x, TInteger digits, MidpointRounding mode) + => MathF.Round(x, int.Create(digits), mode); + + [RequiresPreviewFeatures] + static float IFloatingPoint.ScaleB(float x, TInteger n) + => MathF.ScaleB(x, int.Create(n)); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Sin(float x) + => MathF.Sin(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Sinh(float x) + => MathF.Sinh(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Sqrt(float x) + => MathF.Sqrt(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Tan(float x) + => MathF.Tan(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Tanh(float x) + => MathF.Tanh(x); + + [RequiresPreviewFeatures] + static float IFloatingPoint.Truncate(float x) + => MathF.Truncate(x); + + // static float IFloatingPoint.AcosPi(float x) + // => MathF.AcosPi(x); + // + // static float IFloatingPoint.AsinPi(float x) + // => MathF.AsinPi(x); + // + // static float IFloatingPoint.AtanPi(float x) + // => MathF.AtanPi(x); + // + // static float IFloatingPoint.Atan2Pi(float y, float x) + // => MathF.Atan2Pi(y, x); + // + // static float IFloatingPoint.Compound(float x, float n) + // => MathF.Compound(x, n); + // + // static float IFloatingPoint.CosPi(float x) + // => MathF.CosPi(x); + // + // static float IFloatingPoint.ExpM1(float x) + // => MathF.ExpM1(x); + // + // static float IFloatingPoint.Exp2(float x) + // => MathF.Exp2(x); + // + // static float IFloatingPoint.Exp2M1(float x) + // => MathF.Exp2M1(x); + // + // static float IFloatingPoint.Exp10(float x) + // => MathF.Exp10(x); + // + // static float IFloatingPoint.Exp10M1(float x) + // => MathF.Exp10M1(x); + // + // static float IFloatingPoint.Hypot(float x, float y) + // => MathF.Hypot(x, y); + // + // static float IFloatingPoint.LogP1(float x) + // => MathF.LogP1(x); + // + // static float IFloatingPoint.Log2P1(float x) + // => MathF.Log2P1(x); + // + // static float IFloatingPoint.Log10P1(float x) + // => MathF.Log10P1(x); + // + // static float IFloatingPoint.MaxMagnitudeNumber(float x, float y) + // => MathF.MaxMagnitudeNumber(x, y); + // + // static float IFloatingPoint.MaxNumber(float x, float y) + // => MathF.MaxNumber(x, y); + // + // static float IFloatingPoint.MinMagnitudeNumber(float x, float y) + // => MathF.MinMagnitudeNumber(x, y); + // + // static float IFloatingPoint.MinNumber(float x, float y) + // => MathF.MinNumber(x, y); + // + // static float IFloatingPoint.Root(float x, float n) + // => MathF.Root(x, n); + // + // static float IFloatingPoint.SinPi(float x) + // => MathF.SinPi(x, y); + // + // static float TanPi(float x) + // => MathF.TanPi(x, y); + + // + // IIncrementOperators + // + + [RequiresPreviewFeatures] + static float IIncrementOperators.operator ++(float value) + => value++; + + // [RequiresPreviewFeatures] + // static checked float IIncrementOperators.operator ++(float value) + // => checked(value++); + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static float IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static float IMinMaxValue.MaxValue => MaxValue; + + // + // IModulusOperators + // + + [RequiresPreviewFeatures] + static float IModulusOperators.operator %(float left, float right) + => left % right; + + // [RequiresPreviewFeatures] + // static checked float IModulusOperators.operator %(float left, float right) + // => checked(left % right); + + // + // IMultiplicativeIdentity + // + + [RequiresPreviewFeatures] + static float IMultiplicativeIdentity.MultiplicativeIdentity => 1.0f; + + // + // IMultiplyOperators + // + + [RequiresPreviewFeatures] + static float IMultiplyOperators.operator *(float left, float right) + => (float)(left * right); + + // [RequiresPreviewFeatures] + // static checked float IMultiplyOperators.operator *(float left, float right) + // => checked((float)(left * right)); + + // + // INumber + // + + [RequiresPreviewFeatures] + static float INumber.One => 1.0f; + + [RequiresPreviewFeatures] + static float INumber.Zero => 0.0f; + + [RequiresPreviewFeatures] + static float INumber.Abs(float value) + => MathF.Abs(value); + + [RequiresPreviewFeatures] + static float INumber.Clamp(float value, float min, float max) + => Math.Clamp(value, min, max); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static float INumber.Create(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (float)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (float)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static float INumber.CreateSaturating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (float)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (float)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static float INumber.CreateTruncating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (float)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (float)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + static (float Quotient, float Remainder) INumber.DivRem(float left, float right) + => (left / right, left % right); + + [RequiresPreviewFeatures] + static float INumber.Max(float x, float y) + => MathF.Max(x, y); + + [RequiresPreviewFeatures] + static float INumber.Min(float x, float y) + => MathF.Min(x, y); + + [RequiresPreviewFeatures] + static float INumber.Parse(string s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static float INumber.Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static float INumber.Sign(float value) + => MathF.Sign(value); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static bool INumber.TryCreate(TOther value, out float result) + { + if (typeof(TOther) == typeof(byte)) + { + result = (byte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + result = (char)(object)value; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + result = (float)(decimal)(object)value; + return true; + } + else if (typeof(TOther) == typeof(double)) + { + result = (float)(double)(object)value; + return true; + } + else if (typeof(TOther) == typeof(short)) + { + result = (short)(object)value; + return true; + } + else if (typeof(TOther) == typeof(int)) + { + result = (int)(object)value; + return true; + } + else if (typeof(TOther) == typeof(long)) + { + result = (long)(object)value; + return true; + } + else if (typeof(TOther) == typeof(nint)) + { + result = (nint)(object)value; + return true; + } + else if (typeof(TOther) == typeof(sbyte)) + { + result = (sbyte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(float)) + { + result = (float)(object)value; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + result = (ushort)(object)value; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + result = (uint)(object)value; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + result = (ulong)(object)value; + return true; + } + else if (typeof(TOther) == typeof(nuint)) + { + result = (nuint)(object)value; + return true; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + result = default; + return false; + } + } + + [RequiresPreviewFeatures] + static bool INumber.TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out float result) + => TryParse(s, style, provider, out result); + + [RequiresPreviewFeatures] + static bool INumber.TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out float result) + => TryParse(s, style, provider, out result); + + // + // IParseable + // + + [RequiresPreviewFeatures] + static float IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out float result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // ISignedNumber + // + + [RequiresPreviewFeatures] + static float ISignedNumber.NegativeOne => -1; + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static float ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, NumberStyles.Integer, provider); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out float result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static float ISubtractionOperators.operator -(float left, float right) + => (float)(left - right); + + // [RequiresPreviewFeatures] + // static checked float ISubtractionOperators.operator -(float left, float right) + // => checked((float)(left - right)); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static float IUnaryNegationOperators.operator -(float value) => (float)(-value); + + // [RequiresPreviewFeatures] + // static checked float IUnaryNegationOperators.operator -(float value) => checked((float)(-value)); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static float IUnaryPlusOperators.operator +(float value) => (float)(+value); + + // [RequiresPreviewFeatures] + // static checked float IUnaryPlusOperators.operator +(float value) => checked((float)(+value)); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeOnly.cs b/src/libraries/System.Private.CoreLib/src/System/TimeOnly.cs index 22426e0aa71f6..554cc3a41cfd8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/TimeOnly.cs +++ b/src/libraries/System.Private.CoreLib/src/System/TimeOnly.cs @@ -2,8 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; -using System.Globalization; using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Runtime.Versioning; namespace System { @@ -11,6 +12,14 @@ namespace System /// Represents a time of day, as would be read from a clock, within the range 00:00:00 to 23:59:59.9999999. /// public readonly struct TimeOnly : IComparable, IComparable, IEquatable, ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IComparisonOperators, + IMinMaxValue, + ISpanParseable, + ISubtractionOperators +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { // represent the number of ticks map to the time of the day. 1 ticks = 100-nanosecond in time measurements. private readonly long _ticks; @@ -896,5 +905,75 @@ public string ToString(string? format, IFormatProvider? provider) return DateTimeFormat.TryFormat(ToDateTime(), destination, out charsWritten, format, provider); } + +#if FEATURE_GENERIC_MATH + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(TimeOnly left, TimeOnly right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(TimeOnly left, TimeOnly right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(TimeOnly left, TimeOnly right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(TimeOnly left, TimeOnly right) + => left >= right; + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(TimeOnly left, TimeOnly right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(TimeOnly left, TimeOnly right) + => left != right; + + // + // IParseable + // + + [RequiresPreviewFeatures] + static TimeOnly IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider, DateTimeStyles.None); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out TimeOnly result) + => TryParse(s, provider, DateTimeStyles.None, out result); + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static TimeOnly ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, provider, DateTimeStyles.None); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out TimeOnly result) + => TryParse(s, provider, DateTimeStyles.None, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static TimeSpan ISubtractionOperators.operator -(TimeOnly left, TimeOnly right) + => left - right; + + // [RequiresPreviewFeatures] + // static checked TimeSpan ISubtractionOperators.operator -(TimeOnly left, TimeOnly right) + // => checked(left - right); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeSpan.cs b/src/libraries/System.Private.CoreLib/src/System/TimeSpan.cs index b0634677650b4..6bc5341c8cc94 100644 --- a/src/libraries/System.Private.CoreLib/src/System/TimeSpan.cs +++ b/src/libraries/System.Private.CoreLib/src/System/TimeSpan.cs @@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.CompilerServices; +using System.Runtime.Versioning; namespace System { @@ -26,6 +27,22 @@ namespace System // [Serializable] public readonly struct TimeSpan : IComparable, IComparable, IEquatable, ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IAdditionOperators, + IAdditiveIdentity, + IComparisonOperators, + IDivisionOperators, + IDivisionOperators, + IMinMaxValue, + IMultiplyOperators, + IMultiplicativeIdentity, + ISpanParseable, + ISubtractionOperators, + IUnaryNegationOperators, + IUnaryPlusOperators +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { public const long TicksPerMillisecond = 10000; @@ -487,5 +504,167 @@ public bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan public static bool operator >(TimeSpan t1, TimeSpan t2) => t1._ticks > t2._ticks; public static bool operator >=(TimeSpan t1, TimeSpan t2) => t1._ticks >= t2._ticks; + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static TimeSpan IAdditionOperators.operator +(TimeSpan left, TimeSpan right) + => left + right; + + // [RequiresPreviewFeatures] + // static checked TimeSpan IAdditionOperators.operator +(TimeSpan left, TimeSpan right) + // => checked(left + right); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static TimeSpan IAdditiveIdentity.AdditiveIdentity => default; + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(TimeSpan left, TimeSpan right) + => left.operator <=(TimeSpan left, TimeSpan right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(TimeSpan left, TimeSpan right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(TimeSpan left, TimeSpan right) + => left >= right; + + // + // IDivisionOperators + // + + [RequiresPreviewFeatures] + static TimeSpan IDivisionOperators.operator /(TimeSpan left, double right) + => left / right; + + // [RequiresPreviewFeatures] + // static checked TimeSpan IDivisionOperators.operator /(TimeSpan left, double right) + // => checked(left / right); + + [RequiresPreviewFeatures] + static double IDivisionOperators.operator /(TimeSpan left, TimeSpan right) + => left / right; + + // [RequiresPreviewFeatures] + // static checked double IDivisionOperators.operator /(TimeSpan left, TimeSpan right) + // => checked(left / right); + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(TimeSpan left, TimeSpan right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(TimeSpan left, TimeSpan right) + => left != right; + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static TimeSpan IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static TimeSpan IMinMaxValue.MaxValue => MaxValue; + + // + // IMultiplicativeIdentity + // + + [RequiresPreviewFeatures] + static double IMultiplicativeIdentity.MultiplicativeIdentity => 1.0; + + // + // IMultiplyOperators + // + + [RequiresPreviewFeatures] + static TimeSpan IMultiplyOperators.operator *(TimeSpan left, double right) + => left * right; + + // [RequiresPreviewFeatures] + // static checked TimeSpan IMultiplyOperators.operator *(TimeSpan left, double right) + // => checked(left * right); + + // + // IParseable + // + + [RequiresPreviewFeatures] + static TimeSpan IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out TimeSpan result) + => TryParse(s, provider, out result); + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static TimeSpan ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out TimeSpan result) + => TryParse(s, provider, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static TimeSpan ISubtractionOperators.operator -(TimeSpan left, TimeSpan right) + => left - right; + + // [RequiresPreviewFeatures] + // static checked TimeSpan ISubtractionOperators.operator -(TimeSpan left, TimeSpan right) + // => checked(left - right); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static TimeSpan IUnaryNegationOperators.operator -(TimeSpan value) + => -value; + + // [RequiresPreviewFeatures] + // static checked TimeSpan IUnaryNegationOperators.operator -(TimeSpan value) + // => checked(-value); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static TimeSpan IUnaryPlusOperators.operator +(TimeSpan value) + => +value; + + // [RequiresPreviewFeatures] + // static checked TimeSpan IUnaryPlusOperators.operator +(TimeSpan value) + // => checked(+value); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/UInt16.cs b/src/libraries/System.Private.CoreLib/src/System/UInt16.cs index 35dff0a957a0d..218c092ed1927 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UInt16.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UInt16.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -14,6 +15,13 @@ namespace System [StructLayout(LayoutKind.Sequential)] [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public readonly struct UInt16 : IComparable, IConvertible, ISpanFormattable, IComparable, IEquatable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IBinaryInteger, + IMinMaxValue, + IUnsignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly ushort m_value; // Do not rename (binary serialization) @@ -265,5 +273,705 @@ object IConvertible.ToType(Type type, IFormatProvider? provider) { return Convert.DefaultToType((IConvertible)this, type, provider); } + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static ushort IAdditionOperators.operator +(ushort left, ushort right) + => (ushort)(left + right); + + // [RequiresPreviewFeatures] + // static checked ushort IAdditionOperators.operator +(ushort left, ushort right) + // => checked((ushort)(left + right)); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static ushort IAdditiveIdentity.AdditiveIdentity => 0; + + // + // IBinaryInteger + // + + [RequiresPreviewFeatures] + static ushort IBinaryInteger.LeadingZeroCount(ushort value) + => (ushort)(BitOperations.LeadingZeroCount(value) - 16); + + [RequiresPreviewFeatures] + static ushort IBinaryInteger.PopCount(ushort value) + => (ushort)BitOperations.PopCount(value); + + [RequiresPreviewFeatures] + static ushort IBinaryInteger.RotateLeft(ushort value, ushort rotateAmount) + => (ushort)((value << (rotateAmount & 15)) | (value >> ((16 - rotateAmount) & 15))); + + [RequiresPreviewFeatures] + static ushort IBinaryInteger.RotateRight(ushort value, ushort rotateAmount) + => (ushort)((value >> (rotateAmount & 15)) | (value << ((16 - rotateAmount) & 15))); + + [RequiresPreviewFeatures] + static ushort IBinaryInteger.TrailingZeroCount(ushort value) + => (ushort)(BitOperations.TrailingZeroCount(value << 16) - 16); + + // + // IBinaryNumber + // + + [RequiresPreviewFeatures] + static bool IBinaryNumber.IsPow2(ushort value) + => BitOperations.IsPow2((uint)value); + + [RequiresPreviewFeatures] + static ushort IBinaryNumber.Log2(ushort value) + => (ushort)BitOperations.Log2(value); + + // + // IBitwiseOperators + // + + [RequiresPreviewFeatures] + static ushort IBitwiseOperators.operator &(ushort left, ushort right) + => (ushort)(left & right); + + [RequiresPreviewFeatures] + static ushort IBitwiseOperators.operator |(ushort left, ushort right) + => (ushort)(left | right); + + [RequiresPreviewFeatures] + static ushort IBitwiseOperators.operator ^(ushort left, ushort right) + => (ushort)(left ^ right); + + [RequiresPreviewFeatures] + static ushort IBitwiseOperators.operator ~(ushort value) + => (ushort)(~value); + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(ushort left, ushort right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(ushort left, ushort right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(ushort left, ushort right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(ushort left, ushort right) + => left >= right; + + // + // IDecrementOperators + // + + [RequiresPreviewFeatures] + static ushort IDecrementOperators.operator --(ushort value) + => value--; + + // [RequiresPreviewFeatures] + // static checked ushort IDecrementOperators.operator --(ushort value) + // => checked(value--); + + // + // IDivisionOperators + // + + [RequiresPreviewFeatures] + static ushort IDivisionOperators.operator /(ushort left, ushort right) + => (ushort)(left / right); + + // [RequiresPreviewFeatures] + // static checked ushort IDivisionOperators.operator /(ushort left, ushort right) + // => checked((ushort)(left / right)); + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(ushort left, ushort right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(ushort left, ushort right) + => left != right; + + // + // IIncrementOperators + // + + [RequiresPreviewFeatures] + static ushort IIncrementOperators.operator ++(ushort value) + => value++; + + // [RequiresPreviewFeatures] + // static checked ushort IIncrementOperators.operator ++(ushort value) + // => checked(value++); + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static ushort IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static ushort IMinMaxValue.MaxValue => MaxValue; + + // + // IModulusOperators + // + + [RequiresPreviewFeatures] + static ushort IModulusOperators.operator %(ushort left, ushort right) + => (ushort)(left % right); + + // [RequiresPreviewFeatures] + // static checked ushort IModulusOperators.operator %(ushort left, ushort right) + // => checked((ushort)(left % right)); + + // + // IMultiplicativeIdentity + // + + [RequiresPreviewFeatures] + static ushort IMultiplicativeIdentity.MultiplicativeIdentity => 1; + + // + // IMultiplyOperators + // + + [RequiresPreviewFeatures] + static ushort IMultiplyOperators.operator *(ushort left, ushort right) + => (ushort)(left * right); + + // [RequiresPreviewFeatures] + // static checked ushort IMultiplyOperators.operator *(ushort left, ushort right) + // => checked((ushort)(left * right)); + + // + // INumber + // + + [RequiresPreviewFeatures] + static ushort INumber.One => 1; + + [RequiresPreviewFeatures] + static ushort INumber.Zero => 0; + + [RequiresPreviewFeatures] + static ushort INumber.Abs(ushort value) + => value; + + [RequiresPreviewFeatures] + static ushort INumber.Clamp(ushort value, ushort min, ushort max) + => Math.Clamp(value, min, max); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static ushort INumber.Create(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return checked((ushort)(decimal)(object)value); + } + else if (typeof(TOther) == typeof(double)) + { + return checked((ushort)(double)(object)value); + } + else if (typeof(TOther) == typeof(short)) + { + return checked((ushort)(short)(object)value); + } + else if (typeof(TOther) == typeof(int)) + { + return checked((ushort)(int)(object)value); + } + else if (typeof(TOther) == typeof(long)) + { + return checked((ushort)(long)(object)value); + } + else if (typeof(TOther) == typeof(nint)) + { + return checked((ushort)(nint)(object)value); + } + else if (typeof(TOther) == typeof(sbyte)) + { + return checked((ushort)(sbyte)(object)value); + } + else if (typeof(TOther) == typeof(float)) + { + return checked((ushort)(float)(object)value); + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return checked((ushort)(uint)(object)value); + } + else if (typeof(TOther) == typeof(ulong)) + { + return checked((ushort)(ulong)(object)value); + } + else if (typeof(TOther) == typeof(nuint)) + { + return checked((ushort)(nuint)(object)value); + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static ushort INumber.CreateSaturating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (ushort)actualValue; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (ushort)actualValue; + } + else if (typeof(TOther) == typeof(short)) + { + var actualValue = (short)(object)value; + return (actualValue < 0) ? MinValue : (ushort)actualValue; + } + else if (typeof(TOther) == typeof(int)) + { + var actualValue = (int)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (ushort)actualValue; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (ushort)actualValue; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (ushort)actualValue; + } + else if (typeof(TOther) == typeof(sbyte)) + { + var actualValue = (sbyte)(object)value; + return (actualValue < 0) ? MinValue : (ushort)actualValue; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (ushort)actualValue; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + var actualValue = (uint)(object)value; + return (actualValue > MaxValue) ? MaxValue : (ushort)actualValue; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + return (actualValue > MaxValue) ? MaxValue : (ushort)actualValue; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + return (actualValue > MaxValue) ? MaxValue : (ushort)actualValue; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static ushort INumber.CreateTruncating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (ushort)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (ushort)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (ushort)(short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (ushort)(int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (ushort)(long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (ushort)(nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (ushort)(sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (ushort)(float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (ushort)(uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (ushort)(ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (ushort)(nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + static (ushort Quotient, ushort Remainder) INumber.DivRem(ushort left, ushort right) + => Math.DivRem(left, right); + + [RequiresPreviewFeatures] + static ushort INumber.Max(ushort x, ushort y) + => Math.Max(x, y); + + [RequiresPreviewFeatures] + static ushort INumber.Min(ushort x, ushort y) + => Math.Min(x, y); + + [RequiresPreviewFeatures] + static ushort INumber.Parse(string s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static ushort INumber.Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static ushort INumber.Sign(ushort value) + => (ushort)((value == 0) ? 0 : 1); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static bool INumber.TryCreate(TOther value, out ushort result) + { + if (typeof(TOther) == typeof(byte)) + { + result = (byte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + result = (char)(object)value; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (ushort)actualValue; + return true; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (ushort)actualValue; + return true; + } + else if (typeof(TOther) == typeof(short)) + { + var actualValue = (short)(object)value; + + if (actualValue < 0) + { + result = default; + return false; + } + + result = (ushort)actualValue; + return true; + } + else if (typeof(TOther) == typeof(int)) + { + var actualValue = (int)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (ushort)actualValue; + return true; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (ushort)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (ushort)actualValue; + return true; + } + else if (typeof(TOther) == typeof(sbyte)) + { + var actualValue = (sbyte)(object)value; + + if (actualValue < 0) + { + result = default; + return false; + } + + result = (ushort)actualValue; + return true; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (ushort)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + result = (ushort)(object)value; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + var actualValue = (uint)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (ushort)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (ushort)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (ushort)actualValue; + return true; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + result = default; + return false; + } + } + + [RequiresPreviewFeatures] + static bool INumber.TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out ushort result) + => TryParse(s, style, provider, out result); + + [RequiresPreviewFeatures] + static bool INumber.TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ushort result) + => TryParse(s, style, provider, out result); + + // + // IParseable + // + + [RequiresPreviewFeatures] + static ushort IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out ushort result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // IShiftOperators + // + + [RequiresPreviewFeatures] + static ushort IShiftOperators.operator <<(ushort value, int shiftAmount) + => (ushort)(value << shiftAmount); + + [RequiresPreviewFeatures] + static ushort IShiftOperators.operator >>(ushort value, int shiftAmount) + => (ushort)(value >> shiftAmount); + + // [RequiresPreviewFeatures] + // static ushort IShiftOperators.operator >>>(ushort value, int shiftAmount) + // => (ushort)(value >> shiftAmount); + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static ushort ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, NumberStyles.Integer, provider); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static ushort ISubtractionOperators.operator -(ushort left, ushort right) + => (ushort)(left - right); + + // [RequiresPreviewFeatures] + // static checked ushort ISubtractionOperators.operator -(ushort left, ushort right) + // => checked((ushort)(left - right)); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static ushort IUnaryNegationOperators.operator -(ushort value) + => (ushort)(-value); + + // [RequiresPreviewFeatures] + // static checked ushort IUnaryNegationOperators.operator -(ushort value) + // => checked((ushort)(-value)); + + // + // IUnaryPlusOperators + // + + [RequiresPreviewFeatures] + static ushort IUnaryPlusOperators.operator +(ushort value) + => (ushort)(+value); + + // [RequiresPreviewFeatures] + // static checked ushort IUnaryPlusOperators.operator +(ushort value) + // => checked((ushort)(+value)); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/UInt32.cs b/src/libraries/System.Private.CoreLib/src/System/UInt32.cs index fd1f741345fe7..14d06e9b0eff2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UInt32.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UInt32.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -14,6 +15,13 @@ namespace System [StructLayout(LayoutKind.Sequential)] [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public readonly struct UInt32 : IComparable, IConvertible, ISpanFormattable, IComparable, IEquatable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IBinaryInteger, + IMinMaxValue, + IUnsignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly uint m_value; // Do not rename (binary serialization) @@ -251,5 +259,695 @@ object IConvertible.ToType(Type type, IFormatProvider? provider) { return Convert.DefaultToType((IConvertible)this, type, provider); } + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static uint IAdditionOperators.operator +(uint left, uint right) + => left + right; + + // [RequiresPreviewFeatures] + // static checked uint IAdditionOperators.operator +(uint left, uint right) + // => checked(left + right); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static uint IAdditiveIdentity.AdditiveIdentity => 0; + + // + // IBinaryInteger + // + + [RequiresPreviewFeatures] + static uint IBinaryInteger.LeadingZeroCount(uint value) + => (uint)BitOperations.LeadingZeroCount(value); + + [RequiresPreviewFeatures] + static uint IBinaryInteger.PopCount(uint value) + => (uint)BitOperations.PopCount(value); + + [RequiresPreviewFeatures] + static uint IBinaryInteger.RotateLeft(uint value, uint rotateAmount) + => BitOperations.RotateLeft(value, (int)rotateAmount); + + [RequiresPreviewFeatures] + static uint IBinaryInteger.RotateRight(uint value, uint rotateAmount) + => BitOperations.RotateRight(value, (int)rotateAmount); + + [RequiresPreviewFeatures] + static uint IBinaryInteger.TrailingZeroCount(uint value) + => (uint)BitOperations.TrailingZeroCount(value); + + // + // IBinaryNumber + // + + [RequiresPreviewFeatures] + static bool IBinaryNumber.IsPow2(uint value) + => BitOperations.IsPow2(value); + + [RequiresPreviewFeatures] + static uint IBinaryNumber.Log2(uint value) + => (uint)BitOperations.Log2(value); + + // + // IBitwiseOperators + // + + [RequiresPreviewFeatures] + static uint IBitwiseOperators.operator &(uint left, uint right) + => left & right; + + [RequiresPreviewFeatures] + static uint IBitwiseOperators.operator |(uint left, uint right) + => left | right; + + [RequiresPreviewFeatures] + static uint IBitwiseOperators.operator ^(uint left, uint right) + => left ^ right; + + [RequiresPreviewFeatures] + static uint IBitwiseOperators.operator ~(uint value) + => ~value; + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(uint left, uint right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(uint left, uint right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(uint left, uint right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(uint left, uint right) + => left >= right; + + // + // IDecrementOperators + // + + [RequiresPreviewFeatures] + static uint IDecrementOperators.operator --(uint value) + => value--; + + // [RequiresPreviewFeatures] + // static checked uint IDecrementOperators.operator --(uint value) + // => checked(value--); + + // + // IDivisionOperators + // + + [RequiresPreviewFeatures] + static uint IDivisionOperators.operator /(uint left, uint right) + => left / right; + + // [RequiresPreviewFeatures] + // static checked uint IDivisionOperators.operator /(uint left, uint right) + // => checked(left / right); + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(uint left, uint right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(uint left, uint right) + => left != right; + + // + // IIncrementOperators + // + + [RequiresPreviewFeatures] + static uint IIncrementOperators.operator ++(uint value) + => value++; + + // [RequiresPreviewFeatures] + // static checked uint IIncrementOperators.operator ++(uint value) + // => checked(value++); + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static uint IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static uint IMinMaxValue.MaxValue => MaxValue; + + // + // IModulusOperators + // + + [RequiresPreviewFeatures] + static uint IModulusOperators.operator %(uint left, uint right) + => left % right; + + // [RequiresPreviewFeatures] + // static checked uint IModulusOperators.operator %(uint left, uint right) + // => checked(left % right); + + // + // IMultiplicativeIdentity + // + + [RequiresPreviewFeatures] + static uint IMultiplicativeIdentity.MultiplicativeIdentity => 1; + + // + // IMultiplyOperators + // + + [RequiresPreviewFeatures] + static uint IMultiplyOperators.operator *(uint left, uint right) + => left * right; + + // [RequiresPreviewFeatures] + // static checked uint IMultiplyOperators.operator *(uint left, uint right) + // => checked(left * right); + + // + // INumber + // + + [RequiresPreviewFeatures] + static uint INumber.One => 1; + + [RequiresPreviewFeatures] + static uint INumber.Zero => 0; + + [RequiresPreviewFeatures] + static uint INumber.Abs(uint value) + => value; + + [RequiresPreviewFeatures] + static uint INumber.Clamp(uint value, uint min, uint max) + => Math.Clamp(value, min, max); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static uint INumber.Create(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return checked((uint)(decimal)(object)value); + } + else if (typeof(TOther) == typeof(double)) + { + return checked((uint)(double)(object)value); + } + else if (typeof(TOther) == typeof(short)) + { + return checked((uint)(short)(object)value); + } + else if (typeof(TOther) == typeof(int)) + { + return checked((uint)(int)(object)value); + } + else if (typeof(TOther) == typeof(long)) + { + return checked((uint)(long)(object)value); + } + else if (typeof(TOther) == typeof(nint)) + { + return checked((uint)(nint)(object)value); + } + else if (typeof(TOther) == typeof(sbyte)) + { + return checked((uint)(sbyte)(object)value); + } + else if (typeof(TOther) == typeof(float)) + { + return checked((uint)(float)(object)value); + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return checked((uint)(ulong)(object)value); + } + else if (typeof(TOther) == typeof(nuint)) + { + return checked((uint)(nuint)(object)value); + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static uint INumber.CreateSaturating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (uint)actualValue; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (uint)actualValue; + } + else if (typeof(TOther) == typeof(short)) + { + var actualValue = (short)(object)value; + return (actualValue < 0) ? MinValue : (uint)actualValue; + } + else if (typeof(TOther) == typeof(int)) + { + var actualValue = (int)(object)value; + return (actualValue < 0) ? MinValue : (uint)actualValue; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (uint)actualValue; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (uint)actualValue; + } + else if (typeof(TOther) == typeof(sbyte)) + { + var actualValue = (sbyte)(object)value; + return (actualValue < 0) ? MinValue : (uint)actualValue; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (uint)actualValue; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + return (actualValue > MaxValue) ? MaxValue : (uint)actualValue; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + return (actualValue > MaxValue) ? MaxValue : (uint)actualValue; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static uint INumber.CreateTruncating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (uint)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (uint)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (uint)(short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (uint)(int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (uint)(long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (uint)(nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (uint)(sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (uint)(float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (uint)(ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (uint)(nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + static (uint Quotient, uint Remainder) INumber.DivRem(uint left, uint right) + => Math.DivRem(left, right); + + [RequiresPreviewFeatures] + static uint INumber.Max(uint x, uint y) + => Math.Max(x, y); + + [RequiresPreviewFeatures] + static uint INumber.Min(uint x, uint y) + => Math.Min(x, y); + + [RequiresPreviewFeatures] + static uint INumber.Parse(string s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static uint INumber.Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static uint INumber.Sign(uint value) + => (uint)((value == 0) ? 0 : 1); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static bool INumber.TryCreate(TOther value, out uint result) + { + if (typeof(TOther) == typeof(byte)) + { + result = (byte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + result = (char)(object)value; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (uint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (uint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(short)) + { + var actualValue = (short)(object)value; + + if (actualValue < 0) + { + result = default; + return false; + } + + result = (uint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(int)) + { + var actualValue = (int)(object)value; + + if (actualValue < 0) + { + result = default; + return false; + } + + result = (uint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (uint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (uint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(sbyte)) + { + var actualValue = (sbyte)(object)value; + + if (actualValue < 0) + { + result = default; + return false; + } + + result = (uint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + + if ((actualValue < 0) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (uint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + result = (ushort)(object)value; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + result = (uint)(object)value; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (uint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nuint)) + { + var actualValue = (nuint)(object)value; + + if (actualValue > MaxValue) + { + result = default; + return false; + } + + result = (uint)actualValue; + return true; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + result = default; + return false; + } + } + + [RequiresPreviewFeatures] + static bool INumber.TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out uint result) + => TryParse(s, style, provider, out result); + + [RequiresPreviewFeatures] + static bool INumber.TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out uint result) + => TryParse(s, style, provider, out result); + + // + // IParseable + // + + [RequiresPreviewFeatures] + static uint IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out uint result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // IShiftOperators + // + + [RequiresPreviewFeatures] + static uint IShiftOperators.operator <<(uint value, int shiftAmount) + => value << (int)shiftAmount; + + [RequiresPreviewFeatures] + static uint IShiftOperators.operator >>(uint value, int shiftAmount) + => value >> (int)shiftAmount; + + // [RequiresPreviewFeatures] + // static uint IShiftOperators.operator >>>(uint value, int shiftAmount) + // => value >> (int)shiftAmount; + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static uint ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, NumberStyles.Integer, provider); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static uint ISubtractionOperators.operator -(uint left, uint right) + => left - right; + + // [RequiresPreviewFeatures] + // static checked uint ISubtractionOperators.operator -(uint left, uint right) + // => checked(left - right); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static uint IUnaryNegationOperators.operator -(uint value) + => 0u - value; + + // [RequiresPreviewFeatures] + // static checked uint IUnaryNegationOperators.operator -(uint value) + // => checked(0u - value); + + // + // IUnaryPlusOperators + // + + [RequiresPreviewFeatures] + static uint IUnaryPlusOperators.operator +(uint value) + => +value; + + // [RequiresPreviewFeatures] + // static checked uint IUnaryPlusOperators.operator +(uint value) + // => checked(+value); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/UInt64.cs b/src/libraries/System.Private.CoreLib/src/System/UInt64.cs index da6773eaa8aba..e341b0bee93a0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UInt64.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UInt64.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -14,6 +15,13 @@ namespace System [StructLayout(LayoutKind.Sequential)] [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public readonly struct UInt64 : IComparable, IConvertible, ISpanFormattable, IComparable, IEquatable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IBinaryInteger, + IMinMaxValue, + IUnsignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly ulong m_value; // Do not rename (binary serialization) @@ -250,5 +258,675 @@ object IConvertible.ToType(Type type, IFormatProvider? provider) { return Convert.DefaultToType((IConvertible)this, type, provider); } + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static ulong IAdditionOperators.operator +(ulong left, ulong right) + => left + right; + + // [RequiresPreviewFeatures] + // static checked ulong IAdditionOperators.operator +(ulong left, ulong right) + // => checked(left + right); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static ulong IAdditiveIdentity.AdditiveIdentity => 0; + + // + // IBinaryInteger + // + + [RequiresPreviewFeatures] + static ulong IBinaryInteger.LeadingZeroCount(ulong value) + => (ulong)BitOperations.LeadingZeroCount(value); + + [RequiresPreviewFeatures] + static ulong IBinaryInteger.PopCount(ulong value) + => (ulong)BitOperations.PopCount(value); + + [RequiresPreviewFeatures] + static ulong IBinaryInteger.RotateLeft(ulong value, ulong rotateAmount) + => BitOperations.RotateLeft(value, (int)rotateAmount); + + [RequiresPreviewFeatures] + static ulong IBinaryInteger.RotateRight(ulong value, ulong rotateAmount) + => BitOperations.RotateRight(value, (int)rotateAmount); + + [RequiresPreviewFeatures] + static ulong IBinaryInteger.TrailingZeroCount(ulong value) + => (ulong)BitOperations.TrailingZeroCount(value); + + // + // IBinaryNumber + // + + [RequiresPreviewFeatures] + static bool IBinaryNumber.IsPow2(ulong value) + => BitOperations.IsPow2(value); + + [RequiresPreviewFeatures] + static ulong IBinaryNumber.Log2(ulong value) + => (ulong)BitOperations.Log2(value); + + // + // IBitwiseOperators + // + + [RequiresPreviewFeatures] + static ulong IBitwiseOperators.operator &(ulong left, ulong right) + => left & right; + + [RequiresPreviewFeatures] + static ulong IBitwiseOperators.operator |(ulong left, ulong right) + => left | right; + + [RequiresPreviewFeatures] + static ulong IBitwiseOperators.operator ^(ulong left, ulong right) + => left ^ right; + + [RequiresPreviewFeatures] + static ulong IBitwiseOperators.operator ~(ulong value) + => ~value; + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(ulong left, ulong right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(ulong left, ulong right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(ulong left, ulong right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(ulong left, ulong right) + => left >= right; + + // + // IDecrementOperators + // + + [RequiresPreviewFeatures] + static ulong IDecrementOperators.operator --(ulong value) + => value--; + + // [RequiresPreviewFeatures] + // static checked ulong IDecrementOperators.operator --(ulong value) + // => checked(value--); + + // + // IDivisionOperators + // + + [RequiresPreviewFeatures] + static ulong IDivisionOperators.operator /(ulong left, ulong right) + => left / right; + + // [RequiresPreviewFeatures] + // static checked ulong IDivisionOperators.operator /(ulong left, ulong right) + // => checked(left / right); + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(ulong left, ulong right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(ulong left, ulong right) + => left != right; + + // + // IIncrementOperators + // + + [RequiresPreviewFeatures] + static ulong IIncrementOperators.operator ++(ulong value) + => value++; + + // [RequiresPreviewFeatures] + // static checked ulong IIncrementOperators.operator ++(ulong value) + // => checked(value++); + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static ulong IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static ulong IMinMaxValue.MaxValue => MaxValue; + + // + // IModulusOperators + // + + [RequiresPreviewFeatures] + static ulong IModulusOperators.operator %(ulong left, ulong right) + => left % right; + + // [RequiresPreviewFeatures] + // static checked ulong IModulusOperators.operator %(ulong left, ulong right) + // => checked(left % right); + + // + // IMultiplicativeIdentity + // + + [RequiresPreviewFeatures] + static ulong IMultiplicativeIdentity.MultiplicativeIdentity => 1; + + // + // IMultiplyOperators + // + + [RequiresPreviewFeatures] + static ulong IMultiplyOperators.operator *(ulong left, ulong right) + => left * right; + + // [RequiresPreviewFeatures] + // static checked ulong IMultiplyOperators.operator *(ulong left, ulong right) + // => checked(left * right); + + // + // INumber + // + + [RequiresPreviewFeatures] + static ulong INumber.One => 1; + + [RequiresPreviewFeatures] + static ulong INumber.Zero => 0; + + [RequiresPreviewFeatures] + static ulong INumber.Abs(ulong value) + => value; + + [RequiresPreviewFeatures] + static ulong INumber.Clamp(ulong value, ulong min, ulong max) + => Math.Clamp(value, min, max); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static ulong INumber.Create(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return checked((ulong)(decimal)(object)value); + } + else if (typeof(TOther) == typeof(double)) + { + return checked((ulong)(double)(object)value); + } + else if (typeof(TOther) == typeof(short)) + { + return checked((ulong)(short)(object)value); + } + else if (typeof(TOther) == typeof(int)) + { + return checked((ulong)(int)(object)value); + } + else if (typeof(TOther) == typeof(long)) + { + return checked((ulong)(long)(object)value); + } + else if (typeof(TOther) == typeof(nint)) + { + return checked((ulong)(nint)(object)value); + } + else if (typeof(TOther) == typeof(sbyte)) + { + return checked((ulong)(sbyte)(object)value); + } + else if (typeof(TOther) == typeof(float)) + { + return checked((ulong)(float)(object)value); + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static ulong INumber.CreateSaturating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (ulong)actualValue; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (ulong)actualValue; + } + else if (typeof(TOther) == typeof(short)) + { + var actualValue = (short)(object)value; + return (actualValue < 0) ? MinValue : (ulong)actualValue; + } + else if (typeof(TOther) == typeof(int)) + { + var actualValue = (int)(object)value; + return (actualValue < 0) ? MinValue : (ulong)actualValue; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + return (actualValue < 0) ? MinValue : (ulong)actualValue; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + return (actualValue < 0) ? MinValue : (ulong)actualValue; + } + else if (typeof(TOther) == typeof(sbyte)) + { + var actualValue = (sbyte)(object)value; + return (actualValue < 0) ? MinValue : (ulong)actualValue; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + return (actualValue > MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (ulong)actualValue; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static ulong INumber.CreateTruncating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (ulong)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (ulong)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (ulong)(short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (ulong)(int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (ulong)(long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (ulong)(nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (ulong)(sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (ulong)(float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + static (ulong Quotient, ulong Remainder) INumber.DivRem(ulong left, ulong right) + => Math.DivRem(left, right); + + [RequiresPreviewFeatures] + static ulong INumber.Max(ulong x, ulong y) + => Math.Max(x, y); + + [RequiresPreviewFeatures] + static ulong INumber.Min(ulong x, ulong y) + => Math.Min(x, y); + + [RequiresPreviewFeatures] + static ulong INumber.Parse(string s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static ulong INumber.Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static ulong INumber.Sign(ulong value) + => (ulong)((value == 0) ? 0 : 1); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static bool INumber.TryCreate(TOther value, out ulong result) + { + if (typeof(TOther) == typeof(byte)) + { + result = (byte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + result = (char)(object)value; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (ulong)actualValue; + return true; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (ulong)actualValue; + return true; + } + else if (typeof(TOther) == typeof(short)) + { + var actualValue = (short)(object)value; + + if (actualValue < 0) + { + result = default; + return false; + } + + result = (ulong)actualValue; + return true; + } + else if (typeof(TOther) == typeof(int)) + { + var actualValue = (int)(object)value; + + if (actualValue < 0) + { + result = default; + return false; + } + + result = (ulong)actualValue; + return true; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + + if (actualValue < 0) + { + result = default; + return false; + } + + result = (ulong)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + + if (actualValue < 0) + { + result = default; + return false; + } + + result = (ulong)actualValue; + return true; + } + else if (typeof(TOther) == typeof(sbyte)) + { + var actualValue = (sbyte)(object)value; + + if (actualValue < 0) + { + result = default; + return false; + } + + result = (ulong)actualValue; + return true; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + + if ((actualValue < MinValue) || (actualValue > MaxValue)) + { + result = default; + return false; + } + + result = (ulong)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + result = (ushort)(object)value; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + result = (uint)(object)value; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + result = (ulong)(object)value; + return true; + } + else if (typeof(TOther) == typeof(nuint)) + { + result = (nuint)(object)value; + return true; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + result = default; + return false; + } + } + + [RequiresPreviewFeatures] + static bool INumber.TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out ulong result) + => TryParse(s, style, provider, out result); + + [RequiresPreviewFeatures] + static bool INumber.TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ulong result) + => TryParse(s, style, provider, out result); + + // + // IParseable + // + + [RequiresPreviewFeatures] + static ulong IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out ulong result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // IShiftOperators + // + + [RequiresPreviewFeatures] + static ulong IShiftOperators.operator <<(ulong value, int shiftAmount) + => value << (int)shiftAmount; + + [RequiresPreviewFeatures] + static ulong IShiftOperators.operator >>(ulong value, int shiftAmount) + => value >> (int)shiftAmount; + + // [RequiresPreviewFeatures] + // static ulong IShiftOperators.operator >>>(ulong value, int shiftAmount) + // => value >> (int)shiftAmount; + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static ulong ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, NumberStyles.Integer, provider); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static ulong ISubtractionOperators.operator -(ulong left, ulong right) + => left - right; + + // [RequiresPreviewFeatures] + // static checked ulong ISubtractionOperators.operator -(ulong left, ulong right) + // => checked(left - right); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static ulong IUnaryNegationOperators.operator -(ulong value) + => 0UL - value; + + // [RequiresPreviewFeatures] + // static checked ulong IUnaryNegationOperators.operator -(ulong value) + // => checked(0UL - value); + + // + // IUnaryPlusOperators + // + + [RequiresPreviewFeatures] + static ulong IUnaryPlusOperators.operator +(ulong value) + => +value; + + // [RequiresPreviewFeatures] + // static checked ulong IUnaryPlusOperators.operator +(ulong value) + // => checked(+value); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs b/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs index dcb2ce79c9c2f..43c549fe94e39 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; @@ -22,7 +23,14 @@ namespace System [CLSCompliant(false)] [StructLayout(LayoutKind.Sequential)] [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] - public readonly struct UIntPtr : IEquatable, IComparable, IComparable, ISpanFormattable, ISerializable + public readonly struct UIntPtr : IEquatable, IComparable, IComparable, ISpanFormattable, ISerializable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , IBinaryInteger, + IMinMaxValue, + IUnsignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly unsafe void* _value; // Do not rename (binary serialization) @@ -232,5 +240,749 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro Unsafe.SkipInit(out result); return nuint_t.TryParse(s, style, provider, out Unsafe.As(ref result)); } + +#if FEATURE_GENERIC_MATH + // + // IAdditionOperators + // + + [RequiresPreviewFeatures] + static nuint IAdditionOperators.operator +(nuint left, nuint right) + => (nuint)(left + right); + + // [RequiresPreviewFeatures] + // static checked nuint IAdditionOperators.operator +(nuint left, nuint right) + // => checked((nuint)(left + right)); + + // + // IAdditiveIdentity + // + + [RequiresPreviewFeatures] + static nuint IAdditiveIdentity.AdditiveIdentity => 0; + + // + // IBinaryInteger + // + + [RequiresPreviewFeatures] + static nuint IBinaryInteger.LeadingZeroCount(nuint value) + { + if (Environment.Is64BitProcess) + { + return (nuint)BitOperations.LeadingZeroCount((uint)value); + } + else + { + return (nuint)BitOperations.LeadingZeroCount((ulong)value); + } + } + + [RequiresPreviewFeatures] + static nuint IBinaryInteger.PopCount(nuint value) + { + if (Environment.Is64BitProcess) + { + return (nuint)BitOperations.PopCount((uint)value); + } + else + { + return (nuint)BitOperations.PopCount((ulong)value); + } + } + + [RequiresPreviewFeatures] + static nuint IBinaryInteger.RotateLeft(nuint value, nuint rotateAmount) + { + if (Environment.Is64BitProcess) + { + return (nuint)BitOperations.RotateLeft((uint)value, (int)rotateAmount); + } + else + { + return (nuint)BitOperations.RotateLeft((ulong)value, (int)rotateAmount); + } + } + + [RequiresPreviewFeatures] + static nuint IBinaryInteger.RotateRight(nuint value, nuint rotateAmount) + { + if (Environment.Is64BitProcess) + { + return (nuint)BitOperations.RotateRight((uint)value, (int)rotateAmount); + } + else + { + return (nuint)BitOperations.RotateRight((ulong)value, (int)rotateAmount); + } + } + + [RequiresPreviewFeatures] + static nuint IBinaryInteger.TrailingZeroCount(nuint value) + { + if (Environment.Is64BitProcess) + { + return (nuint)BitOperations.TrailingZeroCount((uint)value); + } + else + { + return (nuint)BitOperations.TrailingZeroCount((ulong)value); + } + } + + // + // IBinaryNumber + // + + [RequiresPreviewFeatures] + static bool IBinaryNumber.IsPow2(nuint value) + { + if (Environment.Is64BitProcess) + { + return BitOperations.IsPow2((uint)value); + } + else + { + return BitOperations.IsPow2((ulong)value); + } + } + + [RequiresPreviewFeatures] + static nuint IBinaryNumber.Log2(nuint value) + { + if (Environment.Is64BitProcess) + { + return (nuint)BitOperations.Log2((uint)value); + } + else + { + return (nuint)BitOperations.Log2((ulong)value); + } + } + + // + // IBitwiseOperators + // + + [RequiresPreviewFeatures] + static nuint IBitwiseOperators.operator &(nuint left, nuint right) + => left & right; + + [RequiresPreviewFeatures] + static nuint IBitwiseOperators.operator |(nuint left, nuint right) + => left | right; + + [RequiresPreviewFeatures] + static nuint IBitwiseOperators.operator ^(nuint left, nuint right) + => left ^ right; + + [RequiresPreviewFeatures] + static nuint IBitwiseOperators.operator ~(nuint value) + => ~value; + + // + // IComparisonOperators + // + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <(nuint left, nuint right) + => left < right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator <=(nuint left, nuint right) + => left <= right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >(nuint left, nuint right) + => left > right; + + [RequiresPreviewFeatures] + static bool IComparisonOperators.operator >=(nuint left, nuint right) + => left >= right; + + // + // IDecrementOperators + // + + [RequiresPreviewFeatures] + static nuint IDecrementOperators.operator --(nuint value) + => value--; + + // [RequiresPreviewFeatures] + // static checked nuint IDecrementOperators.operator --(nuint value) + // => checked(value--); + + // + // IDivisionOperators + // + + [RequiresPreviewFeatures] + static nuint IDivisionOperators.operator /(nuint left, nuint right) + => left / right; + + // [RequiresPreviewFeatures] + // static checked nuint IDivisionOperators.operator /(nuint left, nuint right) + // => checked(left / right); + + // + // IEqualityOperators + // + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator ==(nuint left, nuint right) + => left == right; + + [RequiresPreviewFeatures] + static bool IEqualityOperators.operator !=(nuint left, nuint right) + => left != right; + + // + // IIncrementOperators + // + + [RequiresPreviewFeatures] + static nuint IIncrementOperators.operator ++(nuint value) + => value++; + + // [RequiresPreviewFeatures] + // static checked nuint IIncrementOperators.operator ++(nuint value) + // => checked(value++); + + // + // IMinMaxValue + // + + [RequiresPreviewFeatures] + static nuint IMinMaxValue.MinValue => MinValue; + + [RequiresPreviewFeatures] + static nuint IMinMaxValue.MaxValue => MaxValue; + + // + // IModulusOperators + // + + [RequiresPreviewFeatures] + static nuint IModulusOperators.operator %(nuint left, nuint right) + => left % right; + + // [RequiresPreviewFeatures] + // static checked nuint IModulusOperators.operator %(nuint left, nuint right) + // => checked(left % right); + + // + // IMultiplicativeIdentity + // + + [RequiresPreviewFeatures] + static nuint IMultiplicativeIdentity.MultiplicativeIdentity => 1; + + // + // IMultiplyOperators + // + + [RequiresPreviewFeatures] + static nuint IMultiplyOperators.operator *(nuint left, nuint right) + => left * right; + + // [RequiresPreviewFeatures] + // static checked nuint IMultiplyOperators.operator *(nuint left, nuint right) + // => checked(left * right); + + // + // INumber + // + + [RequiresPreviewFeatures] + static nuint INumber.One => 1; + + [RequiresPreviewFeatures] + static nuint INumber.Zero => 0; + + [RequiresPreviewFeatures] + static nuint INumber.Abs(nuint value) + => value; + + [RequiresPreviewFeatures] + static nuint INumber.Clamp(nuint value, nuint min, nuint max) + => Math.Clamp(value, min, max); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static nuint INumber.Create(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return checked((nuint)(decimal)(object)value); + } + else if (typeof(TOther) == typeof(double)) + { + return checked((nuint)(double)(object)value); + } + else if (typeof(TOther) == typeof(short)) + { + return checked((nuint)(short)(object)value); + } + else if (typeof(TOther) == typeof(int)) + { + return checked((nuint)(int)(object)value); + } + else if (typeof(TOther) == typeof(long)) + { + return checked((nuint)(long)(object)value); + } + else if (typeof(TOther) == typeof(nint)) + { + return checked((nuint)(nint)(object)value); + } + else if (typeof(TOther) == typeof(sbyte)) + { + return checked((nuint)(sbyte)(object)value); + } + else if (typeof(TOther) == typeof(float)) + { + return checked((nuint)(float)(object)value); + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return checked((nuint)(ulong)(object)value); + } + else if (typeof(TOther) == typeof(nuint)) + { + return (nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static nuint INumber.CreateSaturating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (byte)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + return (actualValue > nuint.MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (nuint)actualValue; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + return (actualValue > nuint.MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (nuint)actualValue; + } + else if (typeof(TOther) == typeof(short)) + { + var actualValue = (short)(object)value; + return (actualValue < 0) ? MinValue : (nuint)actualValue; + } + else if (typeof(TOther) == typeof(int)) + { + var actualValue = (int)(object)value; + return (actualValue < 0) ? MinValue : (nuint)actualValue; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + + return ((Size == 4) && (actualValue > uint.MaxValue)) ? MaxValue : + (actualValue < 0) ? MinValue : (nuint)actualValue; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + return (actualValue < 0) ? MinValue : (nuint)actualValue; + } + else if (typeof(TOther) == typeof(sbyte)) + { + var actualValue = (sbyte)(object)value; + return (actualValue < 0) ? MinValue : (nuint)actualValue; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + return (actualValue > nuint.MaxValue) ? MaxValue : + (actualValue < 0) ? MinValue : (nuint)actualValue; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + return (actualValue > nuint.MaxValue) ? MaxValue : (nuint)actualValue; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static nuint INumber.CreateTruncating(TOther value) + { + if (typeof(TOther) == typeof(byte)) + { + return (nuint)(object)value; + } + else if (typeof(TOther) == typeof(char)) + { + return (char)(object)value; + } + else if (typeof(TOther) == typeof(decimal)) + { + return (nuint)(decimal)(object)value; + } + else if (typeof(TOther) == typeof(double)) + { + return (nuint)(double)(object)value; + } + else if (typeof(TOther) == typeof(short)) + { + return (nuint)(short)(object)value; + } + else if (typeof(TOther) == typeof(int)) + { + return (nuint)(int)(object)value; + } + else if (typeof(TOther) == typeof(long)) + { + return (nuint)(long)(object)value; + } + else if (typeof(TOther) == typeof(nint)) + { + return (nuint)(nint)(object)value; + } + else if (typeof(TOther) == typeof(sbyte)) + { + return (nuint)(sbyte)(object)value; + } + else if (typeof(TOther) == typeof(float)) + { + return (nuint)(float)(object)value; + } + else if (typeof(TOther) == typeof(ushort)) + { + return (ushort)(object)value; + } + else if (typeof(TOther) == typeof(uint)) + { + return (uint)(object)value; + } + else if (typeof(TOther) == typeof(ulong)) + { + return (nuint)(ulong)(object)value; + } + else if (typeof(TOther) == typeof(nuint)) + { + return (nuint)(object)value; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + return default; + } + } + + [RequiresPreviewFeatures] + static (nuint Quotient, nuint Remainder) INumber.DivRem(nuint left, nuint right) + => Math.DivRem(left, right); + + [RequiresPreviewFeatures] + static nuint INumber.Max(nuint x, nuint y) + => Math.Max(x, y); + + [RequiresPreviewFeatures] + static nuint INumber.Min(nuint x, nuint y) + => Math.Min(x, y); + + [RequiresPreviewFeatures] + static nuint INumber.Parse(string s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static nuint INumber.Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) + => Parse(s, style, provider); + + [RequiresPreviewFeatures] + static nuint INumber.Sign(nuint value) + => (nuint)((value == 0) ? 0 : 1); + + [RequiresPreviewFeatures] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static bool INumber.TryCreate(TOther value, out nuint result) + { + if (typeof(TOther) == typeof(byte)) + { + result = (byte)(object)value; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + result = (char)(object)value; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + var actualValue = (decimal)(object)value; + + if ((actualValue < 0) || (actualValue > nuint.MaxValue)) + { + result = default; + return false; + } + + result = (nuint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(double)) + { + var actualValue = (double)(object)value; + + if ((actualValue < 0) || (actualValue > nuint.MaxValue)) + { + result = default; + return false; + } + + result = (nuint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(short)) + { + var actualValue = (short)(object)value; + + if (actualValue < 0) + { + result = default; + return false; + } + + result = (nuint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(int)) + { + var actualValue = (int)(object)value; + + if (actualValue < 0) + { + result = default; + return false; + } + + result = (nuint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(long)) + { + var actualValue = (long)(object)value; + + if ((actualValue < 0) || ((Size == 4) && (actualValue > uint.MaxValue))) + { + result = default; + return false; + } + + result = (nuint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nint)) + { + var actualValue = (nint)(object)value; + + if (actualValue < 0) + { + result = default; + return false; + } + + result = (nuint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(sbyte)) + { + var actualValue = (sbyte)(object)value; + + if (actualValue < 0) + { + result = default; + return false; + } + + result = (nuint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(float)) + { + var actualValue = (float)(object)value; + + if ((actualValue < 0) || (actualValue > nuint.MaxValue)) + { + result = default; + return false; + } + + result = (nuint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + result = (ushort)(object)value; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + result = (uint)(object)value; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + var actualValue = (ulong)(object)value; + + if (actualValue > nuint.MaxValue) + { + result = default; + return false; + } + + result = (nuint)actualValue; + return true; + } + else if (typeof(TOther) == typeof(nuint)) + { + result = (nuint)(object)value; + return true; + } + else + { + ThrowHelper.ThrowNotSupportedException(); + result = default; + return false; + } + } + + [RequiresPreviewFeatures] + static bool INumber.TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out nuint result) + => TryParse(s, style, provider, out result); + + [RequiresPreviewFeatures] + static bool INumber.TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out nuint result) + => TryParse(s, style, provider, out result); + + // + // IParseable + // + + [RequiresPreviewFeatures] + static nuint IParseable.Parse(string s, IFormatProvider? provider) + => Parse(s, provider); + + [RequiresPreviewFeatures] + static bool IParseable.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out nuint result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // IShiftOperators + // + + [RequiresPreviewFeatures] + static nuint IShiftOperators.operator <<(nuint value, int shiftAmount) + => value << (int)shiftAmount; + + [RequiresPreviewFeatures] + static nuint IShiftOperators.operator >>(nuint value, int shiftAmount) + => value >> (int)shiftAmount; + + // [RequiresPreviewFeatures] + // static nuint IShiftOperators.operator >>>(nuint value, int shiftAmount) + // => value >> (int)shiftAmount; + + // + // ISpanParseable + // + + [RequiresPreviewFeatures] + static nuint ISpanParseable.Parse(ReadOnlySpan s, IFormatProvider? provider) + => Parse(s, NumberStyles.Integer, provider); + + [RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) + => TryParse(s, NumberStyles.Integer, provider, out result); + + // + // ISubtractionOperators + // + + [RequiresPreviewFeatures] + static nuint ISubtractionOperators.operator -(nuint left, nuint right) + => left - right; + + // [RequiresPreviewFeatures] + // static checked nuint ISubtractionOperators.operator -(nuint left, nuint right) + // => checked(left - right); + + // + // IUnaryNegationOperators + // + + [RequiresPreviewFeatures] + static nuint IUnaryNegationOperators.operator -(nuint value) + => (nuint)0 - value; + + // [RequiresPreviewFeatures] + // static checked nuint IUnaryNegationOperators.operator -(nuint value) + // => checked((nuint)0 - value); + + // + // IUnaryPlusOperators + // + + [RequiresPreviewFeatures] + static nuint IUnaryPlusOperators.operator +(nuint value) + => +value; + + // [RequiresPreviewFeatures] + // static checked nuint IUnaryPlusOperators.operator +(nuint value) + // => checked(+value); +#endif // FEATURE_GENERIC_MATH } } diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index 47e45170b40c9..67adfd0c6d35c 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -705,6 +705,13 @@ public unsafe static void MemoryCopy(void* source, void* destination, ulong dest public static void SetByte(System.Array array, int index, byte value) { } } public readonly partial struct Byte : System.IComparable, System.IComparable, System.IConvertible, System.IEquatable, System.ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IBinaryInteger, + System.IMinMaxValue, + System.IUnsignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly byte _dummyPrimitive; public const byte MaxValue = (byte)255; @@ -744,6 +751,134 @@ public static void SetByte(System.Array array, int index, byte value) { } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Byte result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.Byte result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Byte result) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte INumber.One { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte INumber.Zero { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IAdditionOperators.operator +(byte left, byte right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IBinaryInteger.LeadingZeroCount(byte value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IBinaryInteger.PopCount(byte value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IBinaryInteger.RotateLeft(byte value, byte rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IBinaryInteger.RotateRight(byte value, byte rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IBinaryInteger.TrailingZeroCount(byte value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IBinaryNumber.IsPow2(byte value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IBinaryNumber.Log2(byte value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IBitwiseOperators.operator &(byte left, byte right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IBitwiseOperators.operator |(byte left, byte right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IBitwiseOperators.operator ^(byte left, byte right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IBitwiseOperators.operator ~(byte value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(byte left, byte right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(byte left, byte right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(byte left, byte right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(byte left, byte right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IDecrementOperators.operator --(byte value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IDivisionOperators.operator /(byte left, byte right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(byte left, byte right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(byte left, byte right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IIncrementOperators.operator ++(byte value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IModulusOperators.operator %(byte left, byte right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IMultiplyOperators.operator *(byte left, byte right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte INumber.Abs(byte value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte INumber.Clamp(byte value, byte min, byte max) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte INumber.Create(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte INumber.CreateSaturating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte INumber.CreateTruncating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static (byte Quotient, byte Remainder) INumber.DivRem(byte left, byte right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte INumber.Max(byte x, byte y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte INumber.Min(byte x, byte y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte INumber.Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte INumber.Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte INumber.Sign(byte value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryCreate(TOther value, out byte result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out byte result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out byte result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out byte result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static byte IShiftOperators.operator <<(byte value, int shiftAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeatures] + static byte IShiftOperators.operator >>(byte value, int shiftAmount) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte ISpanParseable.Parse(System.ReadOnlySpan s, IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out byte result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte ISubtractionOperators.operator -(byte left, byte right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IUnaryNegationOperators.operator -(byte value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static byte IUnaryPlusOperators.operator +(byte value) { throw null; } +#endif // FEATURE_GENERIC_MATH } public partial class CannotUnloadAppDomainException : System.SystemException { @@ -753,6 +888,13 @@ public CannotUnloadAppDomainException(string? message) { } public CannotUnloadAppDomainException(string? message, System.Exception? innerException) { } } public readonly partial struct Char : System.IComparable, System.IComparable, System.IConvertible, System.IEquatable, System.ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IBinaryInteger, + System.IMinMaxValue, + System.IUnsignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly char _dummyPrimitive; public const char MaxValue = '\uFFFF'; @@ -829,6 +971,134 @@ public CannotUnloadAppDomainException(string? message, System.Exception? innerEx public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.Char result) { throw null; } bool System.ISpanFormattable.TryFormat(System.Span destination, out int charsWritten, System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } string System.IFormattable.ToString(string? format, IFormatProvider? formatProvider) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char INumber.One { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char INumber.Zero { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IAdditionOperators.operator +(char left, char right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IBinaryInteger.LeadingZeroCount(char value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IBinaryInteger.PopCount(char value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IBinaryInteger.RotateLeft(char value, char rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IBinaryInteger.RotateRight(char value, char rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IBinaryInteger.TrailingZeroCount(char value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IBinaryNumber.IsPow2(char value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IBinaryNumber.Log2(char value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IBitwiseOperators.operator &(char left, char right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IBitwiseOperators.operator |(char left, char right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IBitwiseOperators.operator ^(char left, char right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IBitwiseOperators.operator ~(char value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(char left, char right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(char left, char right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(char left, char right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(char left, char right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IDecrementOperators.operator --(char value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IDivisionOperators.operator /(char left, char right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(char left, char right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(char left, char right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IIncrementOperators.operator ++(char value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IModulusOperators.operator %(char left, char right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IMultiplyOperators.operator *(char left, char right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char INumber.Abs(char value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char INumber.Clamp(char value, char min, char max) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char INumber.Create(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char INumber.CreateSaturating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char INumber.CreateTruncating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static (char Quotient, char Remainder) INumber.DivRem(char left, char right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char INumber.Max(char x, char y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char INumber.Min(char x, char y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char INumber.Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char INumber.Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char INumber.Sign(char value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryCreate(TOther value, out char result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out char result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out char result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out char result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static char IShiftOperators.operator <<(char value, int shiftAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeatures, System.Runtime.CompilerServices.SpecialNameAttribute] + static char IShiftOperators.operator >>(char value, int shiftAmount) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char ISpanParseable.Parse(System.ReadOnlySpan s, IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out char result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char ISubtractionOperators.operator -(char left, char right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IUnaryNegationOperators.operator -(char value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static char IUnaryPlusOperators.operator +(char value) { throw null; } +#endif // FEATURE_GENERIC_MATH } public sealed partial class CharEnumerator : System.Collections.Generic.IEnumerator, System.Collections.IEnumerator, System.ICloneable, System.IDisposable { @@ -1317,7 +1587,14 @@ public static partial class Convert public static bool TryToBase64Chars(System.ReadOnlySpan bytes, System.Span chars, out int charsWritten, System.Base64FormattingOptions options = System.Base64FormattingOptions.None) { throw null; } } public delegate TOutput Converter(TInput input); - public readonly struct DateOnly : System.IComparable, System.IComparable, System.IEquatable, System.ISpanFormattable + public readonly partial struct DateOnly : System.IComparable, System.IComparable, System.IEquatable, System.ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IComparisonOperators, + System.IMinMaxValue, + System.ISpanParseable +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { public static DateOnly MinValue { get { throw null; } } public static DateOnly MaxValue { get { throw null; } } @@ -1376,8 +1653,50 @@ public static partial class Convert public string ToString(System.IFormatProvider? provider) { throw null; } public string ToString(string? format, System.IFormatProvider? provider) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.DateOnly IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.DateOnly IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(System.DateOnly left, System.DateOnly right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(System.DateOnly left, System.DateOnly right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(System.DateOnly left, System.DateOnly right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(System.DateOnly left, System.DateOnly right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(System.DateOnly left, System.DateOnly right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(System.DateOnly left, System.DateOnly right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.DateOnly IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out System.DateOnly result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.DateOnly ISpanParseable.Parse(System.ReadOnlySpan s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out System.DateOnly result) { throw null; } +#endif // FEATURE_GENERIC_MATH } public readonly partial struct DateTime : System.IComparable, System.IComparable, System.IConvertible, System.IEquatable, System.ISpanFormattable, System.Runtime.Serialization.ISerializable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IAdditionOperators, + System.IAdditiveIdentity, + System.IComparisonOperators, + System.IMinMaxValue, + System.ISpanParseable, + System.ISubtractionOperators, + System.ISubtractionOperators +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly int _dummyPrimitive; public static readonly System.DateTime MaxValue; @@ -1498,6 +1817,48 @@ void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Ser public static bool TryParseExact(System.ReadOnlySpan s, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string?[]? formats, System.IFormatProvider? provider, System.Globalization.DateTimeStyles style, out System.DateTime result) { throw null; } public static bool TryParseExact([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? format, System.IFormatProvider? provider, System.Globalization.DateTimeStyles style, out System.DateTime result) { throw null; } public static bool TryParseExact([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string?[]? formats, System.IFormatProvider? provider, System.Globalization.DateTimeStyles style, out System.DateTime result) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.TimeSpan IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.DateTime IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.DateTime IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static System.DateTime IAdditionOperators.operator +(System.DateTime left, System.TimeSpan right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(System.DateTime left, System.DateTime right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(System.DateTime left, System.DateTime right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(System.DateTime left, System.DateTime right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(System.DateTime left, System.DateTime right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(System.DateTime left, System.DateTime right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(System.DateTime left, System.DateTime right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.DateTime IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out System.DateTime result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.DateTime ISpanParseable.Parse(System.ReadOnlySpan s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out System.DateTime result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.DateTime ISubtractionOperators.operator -(System.DateTime left, System.TimeSpan right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.TimeSpan ISubtractionOperators.operator -(System.DateTime left, System.DateTime right) { throw null; } +#endif // FEATURE_GENERIC_MATH } public enum DateTimeKind { @@ -1506,6 +1867,16 @@ public enum DateTimeKind Local = 2, } public readonly partial struct DateTimeOffset : System.IComparable, System.IComparable, System.IEquatable, System.ISpanFormattable, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IAdditionOperators, + System.IAdditiveIdentity, + System.IComparisonOperators, + System.IMinMaxValue, System.ISpanParseable, + System.ISubtractionOperators, + System.ISubtractionOperators +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly int _dummyPrimitive; public static readonly System.DateTimeOffset MaxValue; @@ -1598,6 +1969,48 @@ void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Ser public static bool TryParseExact(System.ReadOnlySpan input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string?[]? formats, System.IFormatProvider? formatProvider, System.Globalization.DateTimeStyles styles, out System.DateTimeOffset result) { throw null; } public static bool TryParseExact([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? format, System.IFormatProvider? formatProvider, System.Globalization.DateTimeStyles styles, out System.DateTimeOffset result) { throw null; } public static bool TryParseExact([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string?[]? formats, System.IFormatProvider? formatProvider, System.Globalization.DateTimeStyles styles, out System.DateTimeOffset result) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.TimeSpan IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.DateTimeOffset IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.DateTimeOffset IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static System.DateTimeOffset IAdditionOperators.operator +(System.DateTimeOffset left, System.TimeSpan right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(System.DateTimeOffset left, System.DateTimeOffset right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(System.DateTimeOffset left, System.DateTimeOffset right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(System.DateTimeOffset left, System.DateTimeOffset right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(System.DateTimeOffset left, System.DateTimeOffset right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(System.DateTimeOffset left, System.DateTimeOffset right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(System.DateTimeOffset left, System.DateTimeOffset right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.DateTimeOffset IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out System.DateTimeOffset result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.DateTimeOffset ISpanParseable.Parse(System.ReadOnlySpan s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out System.DateTimeOffset result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static System.DateTimeOffset ISubtractionOperators.operator -(System.DateTimeOffset left, System.TimeSpan right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeatures] + static System.TimeSpan ISubtractionOperators.operator -(System.DateTimeOffset left, System.DateTimeOffset right) { throw null; } +#endif // FEATURE_GENERIC_MATH } public enum DayOfWeek { @@ -1634,6 +2047,12 @@ public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, S public string ToString(System.IFormatProvider? provider) { throw null; } } public readonly partial struct Decimal : System.IComparable, System.IComparable, System.IConvertible, System.IEquatable, System.ISpanFormattable, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IMinMaxValue, + System.ISignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly int _dummyPrimitive; [System.Runtime.CompilerServices.DecimalConstantAttribute((byte)0, (byte)0, (uint)4294967295, (uint)4294967295, (uint)4294967295)] @@ -1773,6 +2192,107 @@ void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Ser public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Decimal result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.Decimal result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Decimal result) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal INumber.One { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal INumber.Zero { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static decimal IAdditionOperators.operator +(decimal left, decimal right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(decimal left, decimal right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(decimal left, decimal right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(decimal left, decimal right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(decimal left, decimal right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static decimal IDecrementOperators.operator --(decimal value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static decimal IDivisionOperators.operator /(decimal left, decimal right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(decimal left, decimal right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(decimal left, decimal right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static decimal IIncrementOperators.operator ++(decimal value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static decimal IModulusOperators.operator %(decimal left, decimal right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static decimal IMultiplyOperators.operator *(decimal left, decimal right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal INumber.Abs(decimal value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal INumber.Clamp(decimal value, decimal min, decimal max) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal INumber.Create(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal INumber.CreateSaturating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal INumber.CreateTruncating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static (decimal Quotient, decimal Remainder) INumber.DivRem(decimal left, decimal right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal INumber.Max(decimal x, decimal y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal INumber.Min(decimal x, decimal y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal INumber.Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal INumber.Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal INumber.Sign(decimal value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryCreate(TOther value, out decimal result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out decimal result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out decimal result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out decimal result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal ISignedNumber.NegativeOne { get; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static decimal ISpanParseable.Parse(System.ReadOnlySpan s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out decimal result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static decimal ISubtractionOperators.operator -(decimal left, decimal right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static decimal IUnaryNegationOperators.operator -(decimal value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static decimal IUnaryPlusOperators.operator +(decimal value) { throw null; } +#endif // FEATURE_GENERIC_MATH } public abstract partial class Delegate : System.ICloneable, System.Runtime.Serialization.ISerializable { @@ -1821,6 +2341,12 @@ public DivideByZeroException(string? message) { } public DivideByZeroException(string? message, System.Exception? innerException) { } } public readonly partial struct Double : System.IComparable, System.IComparable, System.IConvertible, System.IEquatable, System.ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IBinaryFloatingPoint, + System.IMinMaxValue +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly double _dummyPrimitive; public const double Epsilon = 5E-324; @@ -1878,7 +2404,214 @@ public DivideByZeroException(string? message, System.Exception? innerException) public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Double result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.Double result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Double result) { throw null; } - } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.E { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Epsilon { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.NaN { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.NegativeInfinity { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.NegativeZero { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Pi { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.PositiveInfinity { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Tau { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double INumber.One { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double INumber.Zero { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IAdditionOperators.operator +(double left, double right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IBinaryNumber.IsPow2(double value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IBinaryNumber.Log2(double value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IBitwiseOperators.operator &(double left, double right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IBitwiseOperators.operator |(double left, double right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IBitwiseOperators.operator ^(double left, double right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IBitwiseOperators.operator ~(double value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(double left, double right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(double left, double right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(double left, double right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(double left, double right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IDecrementOperators.operator --(double value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IDivisionOperators.operator /(double left, double right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(double left, double right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(double left, double right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Acos(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Acosh(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Asin(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Asinh(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Atan(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Atan2(double y, double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Atanh(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.BitIncrement(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.BitDecrement(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Cbrt(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Ceiling(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.CopySign(double x, double y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Cos(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Cosh(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Exp(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Floor(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.FusedMultiplyAdd(double left, double right, double addend) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.IEEERemainder(double left, double right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static TInteger IFloatingPoint.ILogB(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Log(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Log(double x, double newBase) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Log2(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Log10(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.MaxMagnitude(double x, double y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.MinMagnitude(double x, double y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Pow(double x, double y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Round(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Round(double x, TInteger digits) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Round(double x, System.MidpointRounding mode) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Round(double x, TInteger digits, System.MidpointRounding mode) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.ScaleB(double x, TInteger n) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Sin(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Sinh(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Sqrt(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Tan(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Tanh(double x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IFloatingPoint.Truncate(double x) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IIncrementOperators.operator ++(double value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IModulusOperators.operator %(double left, double right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IMultiplyOperators.operator *(double left, double right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double INumber.Abs(double value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double INumber.Clamp(double value, double min, double max) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double INumber.Create(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double INumber.CreateSaturating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double INumber.CreateTruncating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static (double Quotient, double Remainder) INumber.DivRem(double left, double right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double INumber.Max(double x, double y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double INumber.Min(double x, double y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double INumber.Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double INumber.Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double INumber.Sign(double value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryCreate(TOther value, out double result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out double result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out double result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out double result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double ISignedNumber.NegativeOne { get; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double ISpanParseable.Parse(System.ReadOnlySpan s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out double result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double ISubtractionOperators.operator -(double left, double right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IUnaryNegationOperators.operator -(double value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IUnaryPlusOperators.operator +(double value) { throw null; } +#endif // FEATURE_GENERIC_MATH + } public partial class DuplicateWaitObjectException : System.ArgumentException { public DuplicateWaitObjectException() { } @@ -2270,6 +3003,12 @@ public partial class GopherStyleUriParser : System.UriParser public GopherStyleUriParser() { } } public readonly partial struct Guid : System.IComparable, System.IComparable, System.IEquatable, System.ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IComparisonOperators, + System.ISpanParseable +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly int _dummyPrimitive; public static readonly System.Guid Empty; @@ -2303,8 +3042,40 @@ public GopherStyleUriParser() { } public static bool TryParseExact([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? format, out System.Guid result) { throw null; } public bool TryWriteBytes(System.Span destination) { throw null; } bool System.ISpanFormattable.TryFormat(System.Span destination, out int charsWritten, System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(System.Guid left, System.Guid right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(System.Guid left, System.Guid right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(System.Guid left, System.Guid right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(System.Guid left, System.Guid right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(System.Guid left, System.Guid right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(System.Guid left, System.Guid right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Guid IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out System.Guid result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Guid ISpanParseable.Parse(System.ReadOnlySpan s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out System.Guid result) { throw null; } +#endif // FEATURE_GENERIC_MATH } public readonly partial struct Half : System.IComparable, System.IComparable, System.IEquatable, System.ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IBinaryFloatingPoint, + System.IMinMaxValue +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly int _dummyPrimitive; public static System.Half Epsilon { get { throw null; } } @@ -2350,6 +3121,213 @@ public GopherStyleUriParser() { } public static bool TryParse(System.ReadOnlySpan s, out System.Half result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Half result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.Half result) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.E { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Epsilon { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.NaN { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.NegativeInfinity { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.NegativeZero { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Pi { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.PositiveInfinity { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Tau { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half INumber.One { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half INumber.Zero { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IAdditionOperators.operator +(System.Half left, System.Half right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IBinaryNumber.IsPow2(System.Half value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IBinaryNumber.Log2(System.Half value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IBitwiseOperators.operator &(System.Half left, System.Half right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IBitwiseOperators.operator |(System.Half left, System.Half right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IBitwiseOperators.operator ^(System.Half left, System.Half right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IBitwiseOperators.operator ~(System.Half value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(System.Half left, System.Half right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(System.Half left, System.Half right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(System.Half left, System.Half right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(System.Half left, System.Half right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IDecrementOperators.operator --(System.Half value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IDivisionOperators.operator /(System.Half left, System.Half right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(System.Half left, System.Half right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(System.Half left, System.Half right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Acos(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Acosh(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Asin(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Asinh(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Atan(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Atan2(System.Half y, System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Atanh(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.BitIncrement(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.BitDecrement(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Cbrt(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Ceiling(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.CopySign(System.Half x, System.Half y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Cos(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Cosh(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Exp(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Floor(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.FusedMultiplyAdd(System.Half left, System.Half right, System.Half addend) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.IEEERemainder(System.Half left, System.Half right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static TInteger IFloatingPoint.ILogB(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Log(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Log(System.Half x, System.Half newBase) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Log2(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Log10(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.MaxMagnitude(System.Half x, System.Half y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.MinMagnitude(System.Half x, System.Half y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Pow(System.Half x, System.Half y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Round(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Round(System.Half x, TInteger digits) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Round(System.Half x, System.MidpointRounding mode) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Round(System.Half x, TInteger digits, System.MidpointRounding mode) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.ScaleB(System.Half x, TInteger n) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Sin(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Sinh(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Sqrt(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Tan(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Tanh(System.Half x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IFloatingPoint.Truncate(System.Half x) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IIncrementOperators.operator ++(System.Half value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IModulusOperators.operator %(System.Half left, System.Half right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IMultiplyOperators.operator *(System.Half left, System.Half right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half INumber.Abs(System.Half value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half INumber.Clamp(System.Half value, System.Half min, System.Half max) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half INumber.Create(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half INumber.CreateSaturating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half INumber.CreateTruncating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static (System.Half Quotient, System.Half Remainder) INumber.DivRem(System.Half left, System.Half right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half INumber.Max(System.Half x, System.Half y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half INumber.Min(System.Half x, System.Half y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half INumber.Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half INumber.Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half INumber.Sign(System.Half value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryCreate(TOther value, out System.Half result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Half result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Half result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out System.Half result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half ISignedNumber.NegativeOne { get; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half ISpanParseable.Parse(System.ReadOnlySpan s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out System.Half result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half ISubtractionOperators.operator -(System.Half left, System.Half right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IUnaryNegationOperators.operator -(System.Half value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.Half IUnaryPlusOperators.operator +(System.Half value) { throw null; } +#endif // FEATURE_GENERIC_MATH } public partial struct HashCode { @@ -2377,6 +3355,239 @@ public partial class HttpStyleUriParser : System.UriParser { public HttpStyleUriParser() { } } +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IAdditionOperators + where TSelf : System.IAdditionOperators + { + static abstract TResult operator +(TSelf left, TOther right); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IAdditiveIdentity + where TSelf : System.IAdditiveIdentity + { + static abstract TResult AdditiveIdentity { get; } + } +[System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IBinaryFloatingPoint : System.IBinaryNumber, System.IFloatingPoint + where TSelf : IBinaryFloatingPoint + { + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IBinaryInteger : System.IBinaryNumber, System.IShiftOperators + where TSelf : IBinaryInteger + { + static abstract TSelf LeadingZeroCount(TSelf value); + static abstract TSelf PopCount(TSelf value); + static abstract TSelf RotateLeft(TSelf value, TSelf rotateAmount); + static abstract TSelf RotateRight(TSelf value, TSelf rotateAmount); + static abstract TSelf TrailingZeroCount(TSelf value); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IBinaryNumber : System.IBitwiseOperators, System.INumber + where TSelf : IBinaryNumber + { + static abstract bool IsPow2(TSelf value); + static abstract TSelf Log2(TSelf value); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IBitwiseOperators + where TSelf : System.IBitwiseOperators + { + static abstract TResult operator &(TSelf left, TOther right); + static abstract TResult operator |(TSelf left, TOther right); + static abstract TResult operator ^(TSelf left, TOther right); + static abstract TResult operator ~(TSelf value); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IComparisonOperators : System.IComparable, System.IComparable, System.IEqualityOperators + where TSelf : IComparisonOperators + { + static abstract bool operator <(TSelf left, TOther right); + static abstract bool operator <=(TSelf left, TOther right); + static abstract bool operator >(TSelf left, TOther right); + static abstract bool operator >=(TSelf left, TOther right); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IDecrementOperators + where TSelf : System.IDecrementOperators + { + static abstract TSelf operator --(TSelf value); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IDivisionOperators + where TSelf : System.IDivisionOperators + { + static abstract TResult operator /(TSelf left, TOther right); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IEqualityOperators : IEquatable + where TSelf : System.IEqualityOperators + { + static abstract bool operator ==(TSelf left, TOther right); + static abstract bool operator !=(TSelf left, TOther right); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IFloatingPoint : System.ISignedNumber + where TSelf : System.IFloatingPoint + { + static abstract TSelf E { get; } + static abstract TSelf Epsilon { get; } + static abstract TSelf NaN { get; } + static abstract TSelf NegativeInfinity { get; } + static abstract TSelf NegativeZero { get; } + static abstract TSelf Pi { get; } + static abstract TSelf PositiveInfinity { get; } + static abstract TSelf Tau { get; } + static abstract TSelf Acos(TSelf x); + static abstract TSelf Acosh(TSelf x); + static abstract TSelf Asin(TSelf x); + static abstract TSelf Asinh(TSelf x); + static abstract TSelf Atan(TSelf x); + static abstract TSelf Atan2(TSelf y, TSelf x); + static abstract TSelf Atanh(TSelf x); + static abstract TSelf BitIncrement(TSelf x); + static abstract TSelf BitDecrement(TSelf x); + static abstract TSelf Cbrt(TSelf x); + static abstract TSelf Ceiling(TSelf x); + static abstract TSelf CopySign(TSelf x, TSelf y); + static abstract TSelf Cos(TSelf x); + static abstract TSelf Cosh(TSelf x); + static abstract TSelf Exp(TSelf x); + static abstract TSelf Floor(TSelf x); + static abstract TSelf FusedMultiplyAdd(TSelf left, TSelf right, TSelf addend); + static abstract TSelf IEEERemainder(TSelf left, TSelf right); + static abstract TInteger ILogB(TSelf x) where TInteger : IBinaryInteger; + static abstract bool IsFinite(TSelf value); + static abstract bool IsInfinity(TSelf value); + static abstract bool IsNaN(TSelf value); + static abstract bool IsNegative(TSelf value); + static abstract bool IsNegativeInfinity(TSelf value); + static abstract bool IsNormal(TSelf value); + static abstract bool IsPositiveInfinity(TSelf value); + static abstract bool IsSubnormal(TSelf value); + static abstract TSelf Log(TSelf x); + static abstract TSelf Log(TSelf x, TSelf newBase); + static abstract TSelf Log2(TSelf x); + static abstract TSelf Log10(TSelf x); + static abstract TSelf MaxMagnitude(TSelf x, TSelf y); + static abstract TSelf MinMagnitude(TSelf x, TSelf y); + static abstract TSelf Pow(TSelf x, TSelf y); + static abstract TSelf Round(TSelf x); + static abstract TSelf Round(TSelf x, TInteger digits) where TInteger : IBinaryInteger; + static abstract TSelf Round(TSelf x, MidpointRounding mode); + static abstract TSelf Round(TSelf x, TInteger digits, MidpointRounding mode) where TInteger : IBinaryInteger; + static abstract TSelf ScaleB(TSelf x, TInteger n) where TInteger : IBinaryInteger; + static abstract TSelf Sin(TSelf x); + static abstract TSelf Sinh(TSelf x); + static abstract TSelf Sqrt(TSelf x); + static abstract TSelf Tan(TSelf x); + static abstract TSelf Tanh(TSelf x); + static abstract TSelf Truncate(TSelf x); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IIncrementOperators + where TSelf : System.IIncrementOperators + { + static abstract TSelf operator ++(TSelf value); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IMinMaxValue + where TSelf : System.IMinMaxValue + { + static abstract TSelf MinValue { get; } + static abstract TSelf MaxValue { get; } + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IModulusOperators + where TSelf : System.IModulusOperators + { + static abstract TResult operator %(TSelf left, TOther right); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IMultiplicativeIdentity + where TSelf : System.IMultiplicativeIdentity + { + static abstract TResult MultiplicativeIdentity { get; } + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IMultiplyOperators + where TSelf : System.IMultiplyOperators + { + static abstract TResult operator *(TSelf left, TOther right); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface INumber : System.IAdditionOperators, System.IAdditiveIdentity, System.IComparable, System.IComparable, System.IComparisonOperators, System.IDecrementOperators, System.IDivisionOperators, System.IEquatable, System.IEqualityOperators, System.IFormattable, System.IIncrementOperators, System.IModulusOperators, System.IMultiplicativeIdentity, System.IMultiplyOperators, System.IParseable, System.ISpanFormattable, System.ISpanParseable, System.ISubtractionOperators, System.IUnaryNegationOperators, System.IUnaryPlusOperators + where TSelf : System.INumber + { + static abstract TSelf One { get; } + static abstract TSelf Zero { get; } + static abstract TSelf Abs(TSelf value); + static abstract TSelf Clamp(TSelf value, TSelf min, TSelf max); + static abstract TSelf Create(TOther value) where TOther : INumber; + static abstract TSelf CreateSaturating(TOther value) where TOther : INumber; + static abstract TSelf CreateTruncating(TOther value) where TOther : INumber; + static abstract (TSelf Quotient, TSelf Remainder) DivRem(TSelf left, TSelf right); + static abstract TSelf Max(TSelf x, TSelf y); + static abstract TSelf Min(TSelf x, TSelf y); + static abstract TSelf Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider); + static abstract TSelf Parse(ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider); + static abstract TSelf Sign(TSelf value); + static abstract bool TryCreate(TOther value, out TSelf result) where TOther : INumber; + static abstract bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out TSelf result); + static abstract bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, IFormatProvider? provider, out TSelf result); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IParseable + where TSelf : System.IParseable + { + static abstract TSelf Parse(string s, System.IFormatProvider? provider); + static abstract bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out TSelf result); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IShiftOperators + where TSelf : System.IShiftOperators + { + static abstract TResult operator <<(TSelf value, int shiftAmount); + static abstract TResult operator >>(TSelf value, int shiftAmount); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface ISignedNumber : System.INumber, System.IUnaryNegationOperators + where TSelf : System.ISignedNumber + { + static abstract TSelf NegativeOne { get; } + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface ISpanParseable : System.IParseable + where TSelf : System.ISpanParseable + { + static abstract TSelf Parse(System.ReadOnlySpan s, System.IFormatProvider? provider); + static abstract bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out TSelf result); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface ISubtractionOperators + where TSelf : System.ISubtractionOperators + { + static abstract TResult operator -(TSelf left, TOther right); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IUnaryNegationOperators + where TSelf : System.IUnaryNegationOperators + { + static abstract TResult operator -(TSelf value); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IUnaryPlusOperators + where TSelf : System.IUnaryPlusOperators + { + static abstract TResult operator +(TSelf value); + } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + public partial interface IUnsignedNumber : System.INumber + where TSelf : IUnsignedNumber + { + } +#endif // FEATURE_GENERIC_MATH public partial interface IAsyncDisposable { System.Threading.Tasks.ValueTask DisposeAsync(); @@ -2477,6 +3688,13 @@ public InsufficientMemoryException(string? message) { } public InsufficientMemoryException(string? message, System.Exception? innerException) { } } public readonly partial struct Int16 : System.IComparable, System.IComparable, System.IConvertible, System.IEquatable, System.ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IBinaryInteger, + System.IMinMaxValue, + System.ISignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly short _dummyPrimitive; public const short MaxValue = (short)32767; @@ -2516,12 +3734,150 @@ public InsufficientMemoryException(string? message, System.Exception? innerExcep public static bool TryParse(System.ReadOnlySpan s, out System.Int16 result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Int16 result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.Int16 result) { throw null; } - } - public readonly partial struct Int32 : System.IComparable, System.IComparable, System.IConvertible, System.IEquatable, System.ISpanFormattable - { - private readonly int _dummyPrimitive; - public const int MaxValue = 2147483647; - public const int MinValue = -2147483648; + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short INumber.One { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short INumber.Zero { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IAdditionOperators.operator +(short left, short right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IBinaryInteger.LeadingZeroCount(short value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IBinaryInteger.PopCount(short value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IBinaryInteger.RotateLeft(short value, short rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IBinaryInteger.RotateRight(short value, short rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IBinaryInteger.TrailingZeroCount(short value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IBinaryNumber.IsPow2(short value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IBinaryNumber.Log2(short value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IBitwiseOperators.operator &(short left, short right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IBitwiseOperators.operator |(short left, short right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IBitwiseOperators.operator ^(short left, short right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IBitwiseOperators.operator ~(short value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(short left, short right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(short left, short right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(short left, short right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(short left, short right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IDecrementOperators.operator --(short value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IDivisionOperators.operator /(short left, short right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(short left, short right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(short left, short right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IIncrementOperators.operator ++(short value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IModulusOperators.operator %(short left, short right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IMultiplyOperators.operator *(short left, short right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short INumber.Abs(short value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short INumber.Clamp(short value, short min, short max) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short INumber.Create(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short INumber.CreateSaturating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short INumber.CreateTruncating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static (short Quotient, short Remainder) INumber.DivRem(short left, short right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short INumber.Max(short x, short y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short INumber.Min(short x, short y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short INumber.Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short INumber.Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short INumber.Sign(short value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryCreate(TOther value, out short result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out short result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out short result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out short result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static short IShiftOperators.operator <<(short value, int shiftAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeatures] + static short IShiftOperators.operator >>(short value, int shiftAmount) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short ISignedNumber.NegativeOne { get; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short ISpanParseable.Parse(System.ReadOnlySpan s, IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out short result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short ISubtractionOperators.operator -(short left, short right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IUnaryNegationOperators.operator -(short value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static short IUnaryPlusOperators.operator +(short value) { throw null; } +#endif // FEATURE_GENERIC_MATH + } + public readonly partial struct Int32 : System.IComparable, System.IComparable, System.IConvertible, System.IEquatable, System.ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IBinaryInteger, + System.IMinMaxValue, + System.ISignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH + { + private readonly int _dummyPrimitive; + public const int MaxValue = 2147483647; + public const int MinValue = -2147483648; public System.Int32 CompareTo(System.Int32 value) { throw null; } public System.Int32 CompareTo(object? value) { throw null; } public bool Equals(System.Int32 obj) { throw null; } @@ -2557,8 +3913,146 @@ public InsufficientMemoryException(string? message, System.Exception? innerExcep public static bool TryParse(System.ReadOnlySpan s, out System.Int32 result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Int32 result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.Int32 result) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int INumber.One { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int INumber.Zero { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IAdditionOperators.operator +(int left, int right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IBinaryInteger.LeadingZeroCount(int value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IBinaryInteger.PopCount(int value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IBinaryInteger.RotateLeft(int value, int rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IBinaryInteger.RotateRight(int value, int rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IBinaryInteger.TrailingZeroCount(int value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IBinaryNumber.IsPow2(int value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IBinaryNumber.Log2(int value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IBitwiseOperators.operator &(int left, int right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IBitwiseOperators.operator |(int left, int right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IBitwiseOperators.operator ^(int left, int right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IBitwiseOperators.operator ~(int value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(int left, int right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(int left, int right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(int left, int right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(int left, int right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IDecrementOperators.operator --(int value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IDivisionOperators.operator /(int left, int right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(int left, int right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(int left, int right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IIncrementOperators.operator ++(int value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IModulusOperators.operator %(int left, int right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IMultiplyOperators.operator *(int left, int right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int INumber.Abs(int value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int INumber.Clamp(int value, int min, int max) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int INumber.Create(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int INumber.CreateSaturating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int INumber.CreateTruncating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static (int Quotient, int Remainder) INumber.DivRem(int left, int right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int INumber.Max(int x, int y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int INumber.Min(int x, int y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int INumber.Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int INumber.Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int INumber.Sign(int value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryCreate(TOther value, out int result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out int result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out int result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out int result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static int IShiftOperators.operator <<(int value, int shiftAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeatures] + static int IShiftOperators.operator >>(int value, int shiftAmount) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int ISignedNumber.NegativeOne { get; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int ISpanParseable.Parse(System.ReadOnlySpan s, IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out int result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int ISubtractionOperators.operator -(int left, int right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IUnaryNegationOperators.operator -(int value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static int IUnaryPlusOperators.operator +(int value) { throw null; } +#endif // FEATURE_GENERIC_MATH } public readonly partial struct Int64 : System.IComparable, System.IComparable, System.IConvertible, System.IEquatable, System.ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IBinaryInteger, + System.IMinMaxValue, + System.ISignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly long _dummyPrimitive; public const long MaxValue = (long)9223372036854775807; @@ -2598,8 +4092,146 @@ public InsufficientMemoryException(string? message, System.Exception? innerExcep public static bool TryParse(System.ReadOnlySpan s, out System.Int64 result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Int64 result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.Int64 result) { throw null; } - } - public readonly partial struct IntPtr : System.IComparable, System.IComparable, System.IEquatable, System.ISpanFormattable, System.Runtime.Serialization.ISerializable + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long INumber.One { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long INumber.Zero { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IAdditionOperators.operator +(long left, long right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IBinaryInteger.LeadingZeroCount(long value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IBinaryInteger.PopCount(long value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IBinaryInteger.RotateLeft(long value, long rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IBinaryInteger.RotateRight(long value, long rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IBinaryInteger.TrailingZeroCount(long value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IBinaryNumber.IsPow2(long value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IBinaryNumber.Log2(long value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IBitwiseOperators.operator &(long left, long right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IBitwiseOperators.operator |(long left, long right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IBitwiseOperators.operator ^(long left, long right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IBitwiseOperators.operator ~(long value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(long left, long right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(long left, long right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(long left, long right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(long left, long right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IDecrementOperators.operator --(long value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IDivisionOperators.operator /(long left, long right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(long left, long right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(long left, long right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IIncrementOperators.operator ++(long value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IModulusOperators.operator %(long left, long right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IMultiplyOperators.operator *(long left, long right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long INumber.Abs(long value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long INumber.Clamp(long value, long min, long max) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long INumber.Create(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long INumber.CreateSaturating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long INumber.CreateTruncating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static (long Quotient, long Remainder) INumber.DivRem(long left, long right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long INumber.Max(long x, long y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long INumber.Min(long x, long y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long INumber.Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long INumber.Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long INumber.Sign(long value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryCreate(TOther value, out long result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out long result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out long result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out long result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static long IShiftOperators.operator <<(long value, int shiftAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeatures] + static long IShiftOperators.operator >>(long value, int shiftAmount) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long ISignedNumber.NegativeOne { get; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long ISpanParseable.Parse(System.ReadOnlySpan s, IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out long result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long ISubtractionOperators.operator -(long left, long right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IUnaryNegationOperators.operator -(long value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static long IUnaryPlusOperators.operator +(long value) { throw null; } +#endif // FEATURE_GENERIC_MATH + } + public readonly partial struct IntPtr : System.IComparable, System.IComparable, System.IEquatable, System.ISpanFormattable, System.Runtime.Serialization.ISerializable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IBinaryInteger, + System.IMinMaxValue, + System.ISignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly int _dummyPrimitive; public static readonly System.IntPtr Zero; @@ -2648,6 +4280,137 @@ void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Ser public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.IntPtr result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out System.IntPtr result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.IntPtr result) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint INumber.One { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint INumber.Zero { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IAdditionOperators.operator +(nint left, nint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IBinaryInteger.LeadingZeroCount(nint value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IBinaryInteger.PopCount(nint value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IBinaryInteger.RotateLeft(nint value, nint rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IBinaryInteger.RotateRight(nint value, nint rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IBinaryInteger.TrailingZeroCount(nint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IBinaryNumber.IsPow2(nint value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IBinaryNumber.Log2(nint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IBitwiseOperators.operator &(nint left, nint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IBitwiseOperators.operator |(nint left, nint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IBitwiseOperators.operator ^(nint left, nint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IBitwiseOperators.operator ~(nint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(nint left, nint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(nint left, nint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(nint left, nint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(nint left, nint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IDecrementOperators.operator --(nint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IDivisionOperators.operator /(nint left, nint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(nint left, nint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(nint left, nint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IIncrementOperators.operator ++(nint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IModulusOperators.operator %(nint left, nint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IMultiplyOperators.operator *(nint left, nint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint INumber.Abs(nint value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint INumber.Clamp(nint value, nint min, nint max) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint INumber.Create(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint INumber.CreateSaturating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint INumber.CreateTruncating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static (nint Quotient, nint Remainder) INumber.DivRem(nint left, nint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint INumber.Max(nint x, nint y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint INumber.Min(nint x, nint y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint INumber.Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint INumber.Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint INumber.Sign(nint value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryCreate(TOther value, out nint result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out nint result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out nint result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out nint result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static nint IShiftOperators.operator <<(nint value, int shiftAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeatures] + static nint IShiftOperators.operator >>(nint value, int shiftAmount) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint ISignedNumber.NegativeOne { get; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint ISpanParseable.Parse(System.ReadOnlySpan s, IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out nint result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint ISubtractionOperators.operator -(nint left, nint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IUnaryNegationOperators.operator -(nint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nint IUnaryPlusOperators.operator +(nint value) { throw null; } +#endif // FEATURE_GENERIC_MATH } public partial class InvalidCastException : System.SystemException { @@ -3434,6 +5197,13 @@ public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, S } [System.CLSCompliantAttribute(false)] public readonly partial struct SByte : System.IComparable, System.IComparable, System.IConvertible, System.IEquatable, System.ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IBinaryInteger, + System.IMinMaxValue, + System.ISignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly sbyte _dummyPrimitive; public const sbyte MaxValue = (sbyte)127; @@ -3473,6 +5243,137 @@ public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, S public static bool TryParse(System.ReadOnlySpan s, out System.SByte result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.SByte result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.SByte result) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte INumber.One { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte INumber.Zero { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IAdditionOperators.operator +(sbyte left, sbyte right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IBinaryInteger.LeadingZeroCount(sbyte value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IBinaryInteger.PopCount(sbyte value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IBinaryInteger.RotateLeft(sbyte value, sbyte rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IBinaryInteger.RotateRight(sbyte value, sbyte rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IBinaryInteger.TrailingZeroCount(sbyte value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IBinaryNumber.IsPow2(sbyte value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IBinaryNumber.Log2(sbyte value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IBitwiseOperators.operator &(sbyte left, sbyte right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IBitwiseOperators.operator |(sbyte left, sbyte right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IBitwiseOperators.operator ^(sbyte left, sbyte right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IBitwiseOperators.operator ~(sbyte value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(sbyte left, sbyte right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(sbyte left, sbyte right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(sbyte left, sbyte right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(sbyte left, sbyte right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IDecrementOperators.operator --(sbyte value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IDivisionOperators.operator /(sbyte left, sbyte right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(sbyte left, sbyte right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(sbyte left, sbyte right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IIncrementOperators.operator ++(sbyte value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IModulusOperators.operator %(sbyte left, sbyte right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IMultiplyOperators.operator *(sbyte left, sbyte right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte INumber.Abs(sbyte value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte INumber.Clamp(sbyte value, sbyte min, sbyte max) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte INumber.Create(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte INumber.CreateSaturating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte INumber.CreateTruncating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static (sbyte Quotient, sbyte Remainder) INumber.DivRem(sbyte left, sbyte right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte INumber.Max(sbyte x, sbyte y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte INumber.Min(sbyte x, sbyte y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte INumber.Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte INumber.Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte INumber.Sign(sbyte value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryCreate(TOther value, out sbyte result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out sbyte result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out sbyte result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out sbyte result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static sbyte IShiftOperators.operator <<(sbyte value, int shiftAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeatures] + static sbyte IShiftOperators.operator >>(sbyte value, int shiftAmount) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte ISignedNumber.NegativeOne { get; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte ISpanParseable.Parse(System.ReadOnlySpan s, IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out sbyte result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte ISubtractionOperators.operator -(sbyte left, sbyte right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IUnaryNegationOperators.operator -(sbyte value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static sbyte IUnaryPlusOperators.operator +(sbyte value) { throw null; } +#endif // FEATURE_GENERIC_MATH } [System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Struct, Inherited=false)] public sealed partial class SerializableAttribute : System.Attribute @@ -3480,6 +5381,12 @@ public sealed partial class SerializableAttribute : System.Attribute public SerializableAttribute() { } } public readonly partial struct Single : System.IComparable, System.IComparable, System.IConvertible, System.IEquatable, System.ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IBinaryFloatingPoint, + System.IMinMaxValue +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly float _dummyPrimitive; public const float Epsilon = 1E-45f; @@ -3537,6 +5444,213 @@ public SerializableAttribute() { } public static bool TryParse(System.ReadOnlySpan s, out System.Single result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Single result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.Single result) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.E { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Epsilon { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.NaN { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.NegativeInfinity { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.NegativeZero { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Pi { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.PositiveInfinity { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Tau { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float INumber.One { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float INumber.Zero { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IAdditionOperators.operator +(float left, float right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IBinaryNumber.IsPow2(float value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IBinaryNumber.Log2(float value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IBitwiseOperators.operator &(float left, float right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IBitwiseOperators.operator |(float left, float right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IBitwiseOperators.operator ^(float left, float right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IBitwiseOperators.operator ~(float value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(float left, float right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(float left, float right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(float left, float right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(float left, float right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IDecrementOperators.operator --(float value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IDivisionOperators.operator /(float left, float right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(float left, float right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(float left, float right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Acos(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Acosh(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Asin(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Asinh(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Atan(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Atan2(float y, float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Atanh(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.BitIncrement(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.BitDecrement(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Cbrt(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Ceiling(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.CopySign(float x, float y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Cos(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Cosh(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Exp(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Floor(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.FusedMultiplyAdd(float left, float right, float addend) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.IEEERemainder(float left, float right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static TInteger IFloatingPoint.ILogB(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Log(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Log(float x, float newBase) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Log2(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Log10(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.MaxMagnitude(float x, float y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.MinMagnitude(float x, float y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Pow(float x, float y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Round(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Round(float x, TInteger digits) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Round(float x, System.MidpointRounding mode) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Round(float x, TInteger digits, System.MidpointRounding mode) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.ScaleB(float x, TInteger n) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Sin(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Sinh(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Sqrt(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Tan(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Tanh(float x) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IFloatingPoint.Truncate(float x) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IIncrementOperators.operator ++(float value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IModulusOperators.operator %(float left, float right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IMultiplyOperators.operator *(float left, float right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float INumber.Abs(float value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float INumber.Clamp(float value, float min, float max) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float INumber.Create(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float INumber.CreateSaturating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float INumber.CreateTruncating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static (float Quotient, float Remainder) INumber.DivRem(float left, float right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float INumber.Max(float x, float y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float INumber.Min(float x, float y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float INumber.Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float INumber.Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float INumber.Sign(float value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryCreate(TOther value, out float result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out float result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out float result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out float result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float ISignedNumber.NegativeOne { get; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float ISpanParseable.Parse(System.ReadOnlySpan s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out float result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float ISubtractionOperators.operator -(float left, float right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IUnaryNegationOperators.operator -(float value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static float IUnaryPlusOperators.operator +(float value) { throw null; } +#endif // FEATURE_GENERIC_MATH } public readonly ref partial struct Span { @@ -3843,7 +5957,15 @@ public partial class ThreadStaticAttribute : System.Attribute { public ThreadStaticAttribute() { } } - public readonly struct TimeOnly : System.IComparable, System.IComparable, System.IEquatable, System.ISpanFormattable + public readonly partial struct TimeOnly : System.IComparable, System.IComparable, System.IEquatable, System.ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IComparisonOperators, + System.IMinMaxValue, + System.ISpanParseable, + System.ISubtractionOperators +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { public static System.TimeOnly MinValue { get { throw null; } } public static System.TimeOnly MaxValue { get { throw null; } } @@ -3907,6 +6029,35 @@ public ThreadStaticAttribute() { } public string ToString(System.IFormatProvider? provider) { throw null; } public string ToString(string? format, System.IFormatProvider? provider) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(System.TimeOnly left, System.TimeOnly right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(System.TimeOnly left, System.TimeOnly right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(System.TimeOnly left, System.TimeOnly right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(System.TimeOnly left, System.TimeOnly right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(System.TimeOnly left, System.TimeOnly right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(System.TimeOnly left, System.TimeOnly right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.TimeOnly IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out System.TimeOnly result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.TimeOnly ISpanParseable.Parse(System.ReadOnlySpan s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out System.TimeOnly result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static System.TimeSpan ISubtractionOperators.operator -(System.TimeOnly left, System.TimeOnly right) { throw null; } +#endif // FEATURE_GENERIC_MATH } public partial class TimeoutException : System.SystemException { @@ -3916,6 +6067,22 @@ public TimeoutException(string? message) { } public TimeoutException(string? message, System.Exception? innerException) { } } public readonly partial struct TimeSpan : System.IComparable, System.IComparable, System.IEquatable, System.ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IAdditionOperators, + System.IAdditiveIdentity, + System.IComparisonOperators, + System.IDivisionOperators, + System.IDivisionOperators, + System.IMinMaxValue, + System.IMultiplyOperators, + System.IMultiplicativeIdentity, + System.ISpanParseable, + System.ISubtractionOperators, + System.IUnaryNegationOperators, + System.IUnaryPlusOperators +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly int _dummyPrimitive; public static readonly System.TimeSpan MaxValue; @@ -4000,6 +6167,63 @@ public TimeoutException(string? message, System.Exception? innerException) { } public static bool TryParseExact([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? format, System.IFormatProvider? formatProvider, out System.TimeSpan result) { throw null; } public static bool TryParseExact([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string?[]? formats, System.IFormatProvider? formatProvider, System.Globalization.TimeSpanStyles styles, out System.TimeSpan result) { throw null; } public static bool TryParseExact([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string?[]? formats, System.IFormatProvider? formatProvider, out System.TimeSpan result) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.TimeSpan IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.TimeSpan IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static System.TimeSpan IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static double IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static System.TimeSpan IAdditionOperators.operator +(System.TimeSpan left, System.TimeSpan right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(System.TimeSpan left, System.TimeSpan right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(System.TimeSpan left, System.TimeSpan right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(System.TimeSpan left, System.TimeSpan right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(System.TimeSpan left, System.TimeSpan right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static System.TimeSpan IDivisionOperators.operator /(System.TimeSpan left, double right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeatures] + static double IDivisionOperators.operator /(System.TimeSpan left, System.TimeSpan right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(System.TimeSpan left, System.TimeSpan right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(System.TimeSpan left, System.TimeSpan right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static System.TimeSpan IMultiplyOperators.operator *(System.TimeSpan left, double right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static System.TimeSpan IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeatures] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out System.TimeSpan result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static System.TimeSpan ISpanParseable.Parse(System.ReadOnlySpan s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeatures] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out System.TimeSpan result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static System.TimeSpan ISubtractionOperators.operator -(System.TimeSpan left, System.TimeSpan right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static System.TimeSpan IUnaryNegationOperators.operator -(System.TimeSpan value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static System.TimeSpan IUnaryPlusOperators.operator +(System.TimeSpan value) { throw null; } +#endif // FEATURE_GENERIC_MATH } [System.ObsoleteAttribute("System.TimeZone has been deprecated. Please investigate the use of System.TimeZoneInfo instead.")] public abstract partial class TimeZone @@ -4683,6 +6907,13 @@ public TypeUnloadedException(string? message, System.Exception? innerException) } [System.CLSCompliantAttribute(false)] public readonly partial struct UInt16 : System.IComparable, System.IComparable, System.IConvertible, System.IEquatable, System.ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IBinaryInteger, + System.IMinMaxValue, + System.IUnsignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly ushort _dummyPrimitive; public const ushort MaxValue = (ushort)65535; @@ -4722,9 +6953,144 @@ public TypeUnloadedException(string? message, System.Exception? innerException) public static bool TryParse(System.ReadOnlySpan s, out System.UInt16 result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.UInt16 result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.UInt16 result) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort INumber.One { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort INumber.Zero { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IAdditionOperators.operator +(ushort left, ushort right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IBinaryInteger.LeadingZeroCount(ushort value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IBinaryInteger.PopCount(ushort value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IBinaryInteger.RotateLeft(ushort value, ushort rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IBinaryInteger.RotateRight(ushort value, ushort rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IBinaryInteger.TrailingZeroCount(ushort value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IBinaryNumber.IsPow2(ushort value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IBinaryNumber.Log2(ushort value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IBitwiseOperators.operator &(ushort left, ushort right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IBitwiseOperators.operator |(ushort left, ushort right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IBitwiseOperators.operator ^(ushort left, ushort right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IBitwiseOperators.operator ~(ushort value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(ushort left, ushort right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(ushort left, ushort right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(ushort left, ushort right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(ushort left, ushort right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IDecrementOperators.operator --(ushort value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IDivisionOperators.operator /(ushort left, ushort right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(ushort left, ushort right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(ushort left, ushort right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IIncrementOperators.operator ++(ushort value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IModulusOperators.operator %(ushort left, ushort right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IMultiplyOperators.operator *(ushort left, ushort right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort INumber.Abs(ushort value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort INumber.Clamp(ushort value, ushort min, ushort max) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort INumber.Create(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort INumber.CreateSaturating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort INumber.CreateTruncating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static (ushort Quotient, ushort Remainder) INumber.DivRem(ushort left, ushort right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort INumber.Max(ushort x, ushort y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort INumber.Min(ushort x, ushort y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort INumber.Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort INumber.Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort INumber.Sign(ushort value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryCreate(TOther value, out ushort result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out ushort result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out ushort result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out ushort result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static ushort IShiftOperators.operator <<(ushort value, int shiftAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeatures] + static ushort IShiftOperators.operator >>(ushort value, int shiftAmount) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort ISpanParseable.Parse(System.ReadOnlySpan s, IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out ushort result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort ISubtractionOperators.operator -(ushort left, ushort right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IUnaryNegationOperators.operator -(ushort value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ushort IUnaryPlusOperators.operator +(ushort value) { throw null; } +#endif // FEATURE_GENERIC_MATH } [System.CLSCompliantAttribute(false)] public readonly partial struct UInt32 : System.IComparable, System.IComparable, System.IConvertible, System.IEquatable, System.ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IBinaryInteger, + System.IMinMaxValue, + System.IUnsignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly uint _dummyPrimitive; public const uint MaxValue = (uint)4294967295; @@ -4764,9 +7130,144 @@ public TypeUnloadedException(string? message, System.Exception? innerException) public static bool TryParse(System.ReadOnlySpan s, out System.UInt32 result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.UInt32 result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.UInt32 result) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint INumber.One { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint INumber.Zero { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IAdditionOperators.operator +(uint left, uint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IBinaryInteger.LeadingZeroCount(uint value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IBinaryInteger.PopCount(uint value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IBinaryInteger.RotateLeft(uint value, uint rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IBinaryInteger.RotateRight(uint value, uint rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IBinaryInteger.TrailingZeroCount(uint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IBinaryNumber.IsPow2(uint value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IBinaryNumber.Log2(uint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IBitwiseOperators.operator &(uint left, uint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IBitwiseOperators.operator |(uint left, uint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IBitwiseOperators.operator ^(uint left, uint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IBitwiseOperators.operator ~(uint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(uint left, uint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(uint left, uint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(uint left, uint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(uint left, uint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IDecrementOperators.operator --(uint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IDivisionOperators.operator /(uint left, uint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(uint left, uint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(uint left, uint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IIncrementOperators.operator ++(uint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IModulusOperators.operator %(uint left, uint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IMultiplyOperators.operator *(uint left, uint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint INumber.Abs(uint value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint INumber.Clamp(uint value, uint min, uint max) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint INumber.Create(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint INumber.CreateSaturating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint INumber.CreateTruncating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static (uint Quotient, uint Remainder) INumber.DivRem(uint left, uint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint INumber.Max(uint x, uint y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint INumber.Min(uint x, uint y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint INumber.Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint INumber.Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint INumber.Sign(uint value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryCreate(TOther value, out uint result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out uint result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out uint result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out uint result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static uint IShiftOperators.operator <<(uint value, int shiftAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeatures] + static uint IShiftOperators.operator >>(uint value, int shiftAmount) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint ISpanParseable.Parse(System.ReadOnlySpan s, IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out uint result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint ISubtractionOperators.operator -(uint left, uint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IUnaryNegationOperators.operator -(uint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static uint IUnaryPlusOperators.operator +(uint value) { throw null; } +#endif // FEATURE_GENERIC_MATH } [System.CLSCompliantAttribute(false)] public readonly partial struct UInt64 : System.IComparable, System.IComparable, System.IConvertible, System.IEquatable, System.ISpanFormattable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IBinaryInteger, + System.IMinMaxValue, + System.IUnsignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly ulong _dummyPrimitive; public const ulong MaxValue = (ulong)18446744073709551615; @@ -4806,9 +7307,144 @@ public TypeUnloadedException(string? message, System.Exception? innerException) public static bool TryParse(System.ReadOnlySpan s, out System.UInt64 result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.UInt64 result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.UInt64 result) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong INumber.One { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong INumber.Zero { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IAdditionOperators.operator +(ulong left, ulong right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IBinaryInteger.LeadingZeroCount(ulong value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IBinaryInteger.PopCount(ulong value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IBinaryInteger.RotateLeft(ulong value, ulong rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IBinaryInteger.RotateRight(ulong value, ulong rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IBinaryInteger.TrailingZeroCount(ulong value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IBinaryNumber.IsPow2(ulong value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IBinaryNumber.Log2(ulong value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IBitwiseOperators.operator &(ulong left, ulong right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IBitwiseOperators.operator |(ulong left, ulong right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IBitwiseOperators.operator ^(ulong left, ulong right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IBitwiseOperators.operator ~(ulong value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(ulong left, ulong right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(ulong left, ulong right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(ulong left, ulong right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(ulong left, ulong right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IDecrementOperators.operator --(ulong value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IDivisionOperators.operator /(ulong left, ulong right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(ulong left, ulong right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(ulong left, ulong right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IIncrementOperators.operator ++(ulong value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IModulusOperators.operator %(ulong left, ulong right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IMultiplyOperators.operator *(ulong left, ulong right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong INumber.Abs(ulong value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong INumber.Clamp(ulong value, ulong min, ulong max) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong INumber.Create(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong INumber.CreateSaturating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong INumber.CreateTruncating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static (ulong Quotient, ulong Remainder) INumber.DivRem(ulong left, ulong right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong INumber.Max(ulong x, ulong y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong INumber.Min(ulong x, ulong y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong INumber.Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong INumber.Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong INumber.Sign(ulong value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryCreate(TOther value, out ulong result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out ulong result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out ulong result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out ulong result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static ulong IShiftOperators.operator <<(ulong value, int shiftAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeatures] + static ulong IShiftOperators.operator >>(ulong value, int shiftAmount) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong ISpanParseable.Parse(System.ReadOnlySpan s, IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out ulong result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong ISubtractionOperators.operator -(ulong left, ulong right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IUnaryNegationOperators.operator -(ulong value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static ulong IUnaryPlusOperators.operator +(ulong value) { throw null; } +#endif // FEATURE_GENERIC_MATH } [System.CLSCompliantAttribute(false)] - public readonly partial struct UIntPtr : System.IComparable, System.IComparable, System.IEquatable, System.ISpanFormattable, System.Runtime.Serialization.ISerializable + public readonly partial struct UIntPtr : System.IComparable, System.IComparable, System.IEquatable, System.ISpanFormattable, System.Runtime.Serialization.ISerializable +#if FEATURE_GENERIC_MATH +#pragma warning disable SA1001 + , System.IBinaryInteger, + System.IMinMaxValue, + System.IUnsignedNumber +#pragma warning restore SA1001 +#endif // FEATURE_GENERIC_MATH { private readonly int _dummyPrimitive; public static readonly System.UIntPtr Zero; @@ -4853,6 +7489,133 @@ void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Ser public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.UIntPtr result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out System.UIntPtr result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.UIntPtr result) { throw null; } + +#if FEATURE_GENERIC_MATH + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IMinMaxValue.MinValue { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IMinMaxValue.MaxValue { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint INumber.One { get { throw null; } } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint INumber.Zero { get { throw null; } } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IAdditionOperators.operator +(nuint left, nuint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IBinaryInteger.LeadingZeroCount(nuint value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IBinaryInteger.PopCount(nuint value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IBinaryInteger.RotateLeft(nuint value, nuint rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IBinaryInteger.RotateRight(nuint value, nuint rotateAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IBinaryInteger.TrailingZeroCount(nuint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IBinaryNumber.IsPow2(nuint value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IBinaryNumber.Log2(nuint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IBitwiseOperators.operator &(nuint left, nuint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IBitwiseOperators.operator |(nuint left, nuint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IBitwiseOperators.operator ^(nuint left, nuint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IBitwiseOperators.operator ~(nuint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <(nuint left, nuint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator <=(nuint left, nuint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >(nuint left, nuint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IComparisonOperators.operator >=(nuint left, nuint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IDecrementOperators.operator --(nuint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IDivisionOperators.operator /(nuint left, nuint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator ==(nuint left, nuint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IEqualityOperators.operator !=(nuint left, nuint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IIncrementOperators.operator ++(nuint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IModulusOperators.operator %(nuint left, nuint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IMultiplyOperators.operator *(nuint left, nuint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint INumber.Abs(nuint value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint INumber.Clamp(nuint value, nuint min, nuint max) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint INumber.Create(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint INumber.CreateSaturating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint INumber.CreateTruncating(TOther value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static (nuint Quotient, nuint Remainder) INumber.DivRem(nuint left, nuint right) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint INumber.Max(nuint x, nuint y) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint INumber.Min(nuint x, nuint y) { throw null; }[System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint INumber.Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint INumber.Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint INumber.Sign(nuint value) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryCreate(TOther value, out nuint result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out nuint result) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool INumber.TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out nuint result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IParseable.Parse(string s, System.IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool IParseable.TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out nuint result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeatures] + static nuint IShiftOperators.operator <<(nuint value, int shiftAmount) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeatures] + static nuint IShiftOperators.operator >>(nuint value, int shiftAmount) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint ISpanParseable.Parse(System.ReadOnlySpan s, IFormatProvider? provider) { throw null; } + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static bool ISpanParseable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out nuint result) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint ISubtractionOperators.operator -(nuint left, nuint right) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IUnaryNegationOperators.operator -(nuint value) { throw null; } + + [System.Runtime.Versioning.RequiresPreviewFeaturesAttribute] + static nuint IUnaryPlusOperators.operator +(nuint value) { throw null; } +#endif // FEATURE_GENERIC_MATH } public partial class UnauthorizedAccessException : System.SystemException { diff --git a/src/libraries/System.Runtime/ref/System.Runtime.csproj b/src/libraries/System.Runtime/ref/System.Runtime.csproj index 9a05ef6d40318..c978be13789ea 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.csproj +++ b/src/libraries/System.Runtime/ref/System.Runtime.csproj @@ -1,6 +1,7 @@ true + true v4.0.30319