diff --git a/eng/packaging.targets b/eng/packaging.targets index ee8e95167d9f8..32b96187eed74 100644 --- a/eng/packaging.targets +++ b/eng/packaging.targets @@ -12,13 +12,13 @@ true 6.0.0 + BeforePack must be used. Setting both to ensure that we are always running before other targets. --> AddNETStandardCompatErrorFileForPackaging;IncludeAnalyzersInPackage;$(PackDependsOn) AddNETStandardCompatErrorFileForPackaging;IncludeAnalyzersInPackage;$(BeforePack) $(PackageOutputPath) $(TargetsForTfmSpecificContentInPackage);AddRuntimeSpecificFilesToPackage;IncludePrivateProjectReferencesWithPackAttributeInPackage $(TargetsForTfmSpecificDebugSymbolsInPackage);AddRuntimeSpecificSymbolToPackage - false + false true $(MSBuildThisFileDirectory)useSharedDesignerContext.txt @@ -54,7 +54,7 @@ $(Version)-$(VersionSuffix) <_IsWindowsDesktopApp Condition="$(WindowsDesktopCoreAppLibrary.Contains('$(AssemblyName);'))">true <_IsAspNetCoreApp Condition="$(AspNetCoreAppLibrary.Contains('$(AssemblyName);'))">true - <_AssemblyInTargetingPack Condition="('$(IsNETCoreAppSrc)' == 'true' or '$(_IsAspNetCoreApp)' == 'true' or '$(_IsWindowsDesktopApp)' == 'true') and '$(TargetFrameworkIdentifier)' != '.NETFramework'">true + <_AssemblyInTargetingPack Condition="('$(IsNETCoreAppSrc)' == 'true' or '$(IsNetCoreAppRef)' == 'true' or '$(_IsAspNetCoreApp)' == 'true' or '$(_IsWindowsDesktopApp)' == 'true') and '$(TargetFrameworkIdentifier)' != '.NETFramework'">true $(MajorVersion).$(MinorVersion).0.$(ServicingVersion) @@ -276,7 +276,7 @@ - diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index c651da612d53c..cb95472d7f96d 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -528,6 +528,9 @@ Type passed must be an interface. + + Object must be of type NFloat. + Type must be a Pointer. diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs index e3cb842f2a529..62d9a8d30e1a3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs @@ -2,7 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Versioning; +using Internal.Runtime.CompilerServices; #pragma warning disable SA1121 // We use our own aliases since they differ per platform #if TARGET_32BIT @@ -13,65 +17,691 @@ namespace System.Runtime.InteropServices { - /// - /// is an immutable value type that represents a floating type that has the same size - /// as the native integer size. - /// It is meant to be used as an exchange type at the managed/unmanaged boundary to accurately represent - /// in managed code unmanaged APIs that use a type alias for C or C++'s float on 32-bit platforms - /// or double on 64-bit platforms, such as the CGFloat type in libraries provided by Apple. - /// + /// Defines an immutable value type that represents a floating type that has the same size as the native integer size. + /// It is meant to be used as an exchange type at the managed/unmanaged boundary to accurately represent in managed code unmanaged APIs that use a type alias for C or C++'s float on 32-bit platforms or double on 64-bit platforms, such as the CGFloat type in libraries provided by Apple. [Intrinsic] - public readonly struct NFloat : IEquatable + public readonly struct NFloat + : IComparable, + IComparable, + IEquatable, + ISpanFormattable { + private const NumberStyles DefaultNumberStyles = NumberStyles.Float | NumberStyles.AllowThousands; + private readonly NativeType _value; - /// - /// Constructs an instance from a 32-bit floating point value. - /// - /// The floating-point vaule. + /// Constructs an instance from a 32-bit floating point value. + /// The floating-point value. + [NonVersionable] public NFloat(float value) { _value = value; } - /// - /// Constructs an instance from a 64-bit floating point value. - /// - /// The floating-point vaule. + /// Constructs an instance from a 64-bit floating point value. + /// The floating-point value. + [NonVersionable] public NFloat(double value) { _value = (NativeType)value; } - /// - /// The underlying floating-point value of this instance. - /// - public double Value => _value; + /// Represents the smallest positive NFloat value that is greater than zero. + public static NFloat Epsilon + { + [NonVersionable] + get => new NFloat(NativeType.Epsilon); + } + + /// Represents the largest finite value of a NFloat. + public static NFloat MaxValue + { + [NonVersionable] + get => new NFloat(NativeType.MaxValue); + } + + /// Represents the smallest finite value of a NFloat. + public static NFloat MinValue + { + [NonVersionable] + get => new NFloat(NativeType.MinValue); + } + + /// Represents a value that is not a number (NaN). + public static NFloat NaN + { + [NonVersionable] + get => new NFloat(NativeType.NaN); + } + + /// Represents negative infinity. + public static NFloat NegativeInfinity + { + [NonVersionable] + get => new NFloat(NativeType.NegativeInfinity); + } + + /// Represents positive infinity. + public static NFloat PositiveInfinity + { + [NonVersionable] + get => new NFloat(NativeType.PositiveInfinity); + } + + /// Gets the size, in bytes, of an NFloat. + public static int Size + { + [NonVersionable] + get => sizeof(NativeType); + } + + /// The underlying floating-point value of this instance. + public double Value + { + [NonVersionable] + get => _value; + } + + // + // Unary Arithmetic + // + + /// Computes the unary plus of a value. + /// The value for which to compute its unary plus. + /// The unary plus of . + [NonVersionable] + public static NFloat operator +(NFloat value) => value; + + /// Computes the unary negation of a value. + /// The value for which to compute its unary negation. + /// The unary negation of . + [NonVersionable] + public static NFloat operator -(NFloat value) => new NFloat(-value._value); + + /// Increments a value. + /// The value to increment. + /// The result of incrementing . + [NonVersionable] + public static NFloat operator ++(NFloat value) => new NFloat(value._value + 1); + + /// Decrements a value. + /// The value to decrement. + /// The result of decrementing . + [NonVersionable] + public static NFloat operator --(NFloat value) => new NFloat(value._value - 1); + + // + // Binary Arithmetic + // + + /// Adds two values together to compute their sum. + /// The value to which is added. + /// The value which is added to . + /// The sum of and . + [NonVersionable] + public static NFloat operator +(NFloat left, NFloat right) => new NFloat(left._value + right._value); + + /// Subtracts two values to compute their difference. + /// The value from which is subtracted. + /// The value which is subtracted from . + /// The difference of subtracted from . + [NonVersionable] + public static NFloat operator -(NFloat left, NFloat right) => new NFloat(left._value - right._value); + + /// Multiplies two values together to compute their product. + /// The value which multiplies. + /// The value which multiplies . + /// The product of divided-by . + [NonVersionable] + public static NFloat operator *(NFloat left, NFloat right) => new NFloat(left._value * right._value); + + /// Divides two values together to compute their quotient. + /// The value which divides. + /// The value which divides . + /// The quotient of divided-by . + [NonVersionable] + public static NFloat operator /(NFloat left, NFloat right) => new NFloat(left._value / right._value); + + /// Divides two values together to compute their remainder. + /// The value which divides. + /// The value which divides . + /// The remainder of divided-by . + [NonVersionable] + public static NFloat operator %(NFloat left, NFloat right) => new NFloat(left._value % right._value); + + // + // Comparisons + // + + /// Compares two values to determine equality. + /// The value to compare with . + /// The value to compare with . + /// true if is equal to ; otherwise, false. + [NonVersionable] + public static bool operator ==(NFloat left, NFloat right) => left._value == right._value; + + /// Compares two values to determine inequality. + /// The value to compare with . + /// The value to compare with . + /// true if is not equal to ; otherwise, false. + [NonVersionable] + public static bool operator !=(NFloat left, NFloat right) => left._value != right._value; + + /// 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. + [NonVersionable] + public static bool operator <(NFloat left, NFloat right) => left._value < right._value; + + /// 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. + [NonVersionable] + public static bool operator <=(NFloat left, NFloat right) => left._value <= right._value; + + /// 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. + [NonVersionable] + public static bool operator >(NFloat left, NFloat right) => left._value > right._value; + + /// 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. + [NonVersionable] + public static bool operator >=(NFloat left, NFloat right) => left._value >= right._value; + + // + // Explicit Convert To NFloat + // + + /// Explicitly converts a value to its nearest representable native-sized floating-point value. + /// The value to convert. + /// converted to its nearest representable native-sized floating-point value. + [NonVersionable] + public static explicit operator NFloat(decimal value) => new NFloat((NativeType)value); + + /// Explicitly converts a value to its nearest representable native-sized floating-point value. + /// The value to convert. + /// converted to its nearest representable native-sized floating-point value. + [NonVersionable] + public static explicit operator NFloat(double value) => new NFloat((NativeType)value); + + // + // Explicit Convert From NFloat + // + + /// Explicitly converts a native-sized floating-point value to its nearest representable value. + /// The value to convert. + /// converted to its nearest representable value. + [NonVersionable] + public static explicit operator byte(NFloat value) => (byte)(value._value); + + /// Explicitly converts a native-sized floating-point value to its nearest representable value. + /// The value to convert. + /// converted to its nearest representable value. + [NonVersionable] + public static explicit operator char(NFloat value) => (char)(value._value); + + /// Explicitly converts a native-sized floating-point value to its nearest representable value. + /// The value to convert. + /// converted to its nearest representable value. + [NonVersionable] + public static explicit operator decimal(NFloat value) => (decimal)(value._value); + + /// Explicitly converts a native-sized floating-point value to its nearest representable value. + /// The value to convert. + /// converted to its nearest representable value. + [NonVersionable] + public static explicit operator short(NFloat value) => (short)(value._value); + + /// Explicitly converts a native-sized floating-point value to its nearest representable value. + /// The value to convert. + /// converted to its nearest representable value. + [NonVersionable] + public static explicit operator int(NFloat value) => (int)(value._value); + + /// Explicitly converts a native-sized floating-point value to its nearest representable value. + /// The value to convert. + /// converted to its nearest representable value. + [NonVersionable] + public static explicit operator long(NFloat value) => (long)(value._value); + + /// Explicitly converts a native-sized floating-point value to its nearest representable value. + /// The value to convert. + /// converted to its nearest representable value. + [NonVersionable] + public static explicit operator nint(NFloat value) => (nint)(value._value); + + /// Explicitly converts a native-sized floating-point value to its nearest representable value. + /// The value to convert. + /// converted to its nearest representable value. + [NonVersionable] + [CLSCompliant(false)] + public static explicit operator sbyte(NFloat value) => (sbyte)(value._value); + + /// Explicitly converts a native-sized floating-point value to its nearest representable value. + /// The value to convert. + /// converted to its nearest representable value. + [NonVersionable] + public static explicit operator float(NFloat value) => (float)(value._value); + + /// Explicitly converts a native-sized floating-point value to its nearest representable value. + /// The value to convert. + /// converted to its nearest representable value. + [NonVersionable] + [CLSCompliant(false)] + public static explicit operator ushort(NFloat value) => (ushort)(value._value); + + /// Explicitly converts a native-sized floating-point value to its nearest representable value. + /// The value to convert. + /// converted to its nearest representable value. + [NonVersionable] + [CLSCompliant(false)] + public static explicit operator uint(NFloat value) => (uint)(value._value); + + /// Explicitly converts a native-sized floating-point value to its nearest representable value. + /// The value to convert. + /// converted to its nearest representable value. + [NonVersionable] + [CLSCompliant(false)] + public static explicit operator ulong(NFloat value) => (ulong)(value._value); + + /// Explicitly converts a native-sized floating-point value to its nearest representable value. + /// The value to convert. + /// converted to its nearest representable value. + [NonVersionable] + [CLSCompliant(false)] + public static explicit operator nuint(NFloat value) => (nuint)(value._value); + + // + // Implicit Convert To NFloat + // - /// - /// Returns a value indicating whether this instance is equal to a specified object. - /// - /// An object to compare with this instance. - /// true if is an instance of and equals the value of this instance; otherwise, false. - public override bool Equals([NotNullWhen(true)] object? o) => o is NFloat other && Equals(other); + /// Implicitly converts a value to its nearest representable native-sized floating-point value. + /// The value to convert. + /// converted to its nearest representable native-sized floating-point value. + [NonVersionable] + public static implicit operator NFloat(byte value) => new NFloat((NativeType)value); - /// - /// Returns a value indicating whether this instance is equal to a specified value. - /// + /// Implicitly converts a value to its nearest representable native-sized floating-point value. + /// The value to convert. + /// converted to its nearest representable native-sized floating-point value. + [NonVersionable] + public static implicit operator NFloat(char value) => new NFloat((NativeType)value); + + /// Implicitly converts a value to its nearest representable native-sized floating-point value. + /// The value to convert. + /// converted to its nearest representable native-sized floating-point value. + [NonVersionable] + public static implicit operator NFloat(short value) => new NFloat((NativeType)value); + + /// Implicitly converts a value to its nearest representable native-sized floating-point value. + /// The value to convert. + /// converted to its nearest representable native-sized floating-point value. + [NonVersionable] + public static implicit operator NFloat(int value) => new NFloat((NativeType)value); + + /// Implicitly converts a value to its nearest representable native-sized floating-point value. + /// The value to convert. + /// converted to its nearest representable native-sized floating-point value. + [NonVersionable] + public static implicit operator NFloat(long value) => new NFloat((NativeType)value); + + /// Implicitly converts a value to its nearest representable native-sized floating-point value. + /// The value to convert. + /// converted to its nearest representable native-sized floating-point value. + [NonVersionable] + public static implicit operator NFloat(nint value) => new NFloat((NativeType)value); + + /// Implicitly converts a value to its nearest representable native-sized floating-point value. + /// The value to convert. + /// converted to its nearest representable native-sized floating-point value. + [NonVersionable] + [CLSCompliant(false)] + public static implicit operator NFloat(sbyte value) => new NFloat((NativeType)value); + + /// Implicitly converts a value to its nearest representable native-sized floating-point value. + /// The value to convert. + /// converted to its nearest representable native-sized floating-point value. + [NonVersionable] + public static implicit operator NFloat(float value) => new NFloat((NativeType)value); + + /// Implicitly converts a value to its nearest representable native-sized floating-point value. + /// The value to convert. + /// converted to its nearest representable native-sized floating-point value. + [NonVersionable] + [CLSCompliant(false)] + public static implicit operator NFloat(ushort value) => new NFloat((NativeType)value); + + /// Implicitly converts a value to its nearest representable native-sized floating-point value. + /// The value to convert. + /// converted to its nearest representable native-sized floating-point value. + [NonVersionable] + [CLSCompliant(false)] + public static implicit operator NFloat(uint value) => new NFloat((NativeType)value); + + /// Implicitly converts a value to its nearest representable native-sized floating-point value. + /// The value to convert. + /// converted to its nearest representable native-sized floating-point value. + [NonVersionable] + [CLSCompliant(false)] + public static implicit operator NFloat(ulong value) => new NFloat((NativeType)value); + + /// Implicitly converts a value to its nearest representable native-sized floating-point value. + /// The value to convert. + /// converted to its nearest representable native-sized floating-point value. + [NonVersionable] + [CLSCompliant(false)] + public static implicit operator NFloat(nuint value) => new NFloat((NativeType)value); + + // + // Implicit Convert From NFloat + // + + /// Implicitly converts a native-sized floating-point value to its nearest representable value. + /// The value to convert. + /// converted to its nearest representable value. + public static implicit operator double(NFloat value) => (double)(value._value); + + /// Determines whether the specified value is finite (zero, subnormal, or normal). + /// The floating-point value. + /// true if the value is finite (zero, subnormal or normal); false otherwise. + [NonVersionable] + public static bool IsFinite(NFloat value) => NativeType.IsFinite(value._value); + + /// Determines whether the specified value is infinite (positive or negative infinity). + /// The floating-point value. + /// true if the value is infinite (positive or negative infinity); false otherwise. + [NonVersionable] + public static bool IsInfinity(NFloat value) => NativeType.IsInfinity(value._value); + + /// Determines whether the specified value is NaN (not a number). + /// The floating-point value. + /// true if the value is NaN (not a number); false otherwise. + [NonVersionable] + public static bool IsNaN(NFloat value) => NativeType.IsNaN(value._value); + + /// Determines whether the specified value is negative. + /// The floating-point value. + /// true if the value is negative; false otherwise. + [NonVersionable] + public static bool IsNegative(NFloat value) => NativeType.IsNegative(value._value); + + /// Determines whether the specified value is negative infinity. + /// The floating-point value. + /// true if the value is negative infinity; false otherwise. + [NonVersionable] + public static bool IsNegativeInfinity(NFloat value) => NativeType.IsNegativeInfinity(value._value); + + /// Determines whether the specified value is normal. + /// The floating-point value. + /// true if the value is normal; false otherwise. + [NonVersionable] + public static bool IsNormal(NFloat value) => NativeType.IsNormal(value._value); + + /// Determines whether the specified value is positive infinity. + /// The floating-point value. + /// true if the value is positive infinity; false otherwise. + [NonVersionable] + public static bool IsPositiveInfinity(NFloat value) => NativeType.IsPositiveInfinity(value._value); + + /// Determines whether the specified value is subnormal. + /// The floating-point value. + /// true if the value is subnormal; false otherwise. + [NonVersionable] + public static bool IsSubnormal(NFloat value) => NativeType.IsSubnormal(value._value); + + /// Converts the string representation of a number to its floating-point number equivalent. + /// A string that contains the number to convert. + /// A floating-point number that is equivalent to the numeric value or symbol specified in . + /// is null. + /// does not represent a number in a valid format. + public static NFloat Parse(string s) + { + var result = NativeType.Parse(s); + return new NFloat(result); + } + + /// Converts the string representation of a number in a specified style to its floating-point number equivalent. + /// A string that contains the number to convert. + /// A bitwise combination of enumeration values that indicate the style elements that can be present in . + /// A floating-point number that is equivalent to the numeric value or symbol specified in . + /// + /// is not a value. + /// -or- + /// includes the value. + /// + /// is null. + /// does not represent a number in a valid format. + public static NFloat Parse(string s, NumberStyles style) + { + var result = NativeType.Parse(s, style); + return new NFloat(result); + } + + /// Converts the string representation of a number in a specified culture-specific format to its floating-point number equivalent. + /// A string that contains the number to convert. + /// An object that supplies culture-specific formatting information about . + /// A floating-point number that is equivalent to the numeric value or symbol specified in . + /// is null. + /// does not represent a number in a valid format. + public static NFloat Parse(string s, IFormatProvider? provider) + { + var result = NativeType.Parse(s, provider); + return new NFloat(result); + } + + /// Converts the string representation of a number in a specified style and culture-specific format to its floating-point number equivalent. + /// A string that contains the number to convert. + /// A bitwise combination of enumeration values that indicate the style elements that can be present in . + /// An object that supplies culture-specific formatting information about . + /// A floating-point number that is equivalent to the numeric value or symbol specified in . + /// + /// is not a value. + /// -or- + /// includes the value. + /// + /// is null. + /// does not represent a number in a valid format. + public static NFloat Parse(string s, NumberStyles style, IFormatProvider? provider) + { + var result = NativeType.Parse(s, style, provider); + return new NFloat(result); + } + + /// Converts a character span that contains the string representation of a number in a specified style and culture-specific format to its floating-point number equivalent. + /// A character span that contains the number to convert. + /// A bitwise combination of enumeration values that indicate the style elements that can be present in . + /// An object that supplies culture-specific formatting information about . + /// A floating-point number that is equivalent to the numeric value or symbol specified in . + /// + /// is not a value. + /// -or- + /// includes the value. + /// + /// does not represent a number in a valid format. + public static NFloat Parse(ReadOnlySpan s, NumberStyles style = DefaultNumberStyles, IFormatProvider? provider = null) + { + var result = NativeType.Parse(s, style, provider); + return new NFloat(result); + } + + /// Tries to convert the string representation of a number to its floating-point number equivalent. + /// A read-only character span that contains the number to convert. + /// When this method returns, contains a floating-point number equivalent of the numeric value or symbol contained in if the conversion succeeded or zero if the conversion failed. The conversion fails if the is null, , or is not in a valid format. This parameter is passed uninitialized; any value originally supplied in result will be overwritten. + /// true if was converted successfully; otherwise, false. + public static bool TryParse([NotNullWhen(true)] string? s, out NFloat result) + { + Unsafe.SkipInit(out result); + return NativeType.TryParse(s, out Unsafe.As(ref result)); + } + + /// Tries to convert a character span containing the string representation of a number to its floating-point number equivalent. + /// A read-only character span that contains the number to convert. + /// When this method returns, contains a floating-point number equivalent of the numeric value or symbol contained in if the conversion succeeded or zero if the conversion failed. The conversion fails if the is or is not in a valid format. This parameter is passed uninitialized; any value originally supplied in result will be overwritten. + /// true if was converted successfully; otherwise, false. + public static bool TryParse(ReadOnlySpan s, out NFloat result) + { + Unsafe.SkipInit(out result); + return NativeType.TryParse(s, out Unsafe.As(ref result)); + } + + /// Tries to convert the string representation of a number in a specified style and culture-specific format to its floating-point number equivalent. + /// A read-only character span that contains the number to convert. + /// A bitwise combination of enumeration values that indicate the style elements that can be present in . + /// An object that supplies culture-specific formatting information about . + /// When this method returns, contains a floating-point number equivalent of the numeric value or symbol contained in if the conversion succeeded or zero if the conversion failed. The conversion fails if the is null, , or is not in a format compliant with , or if is not a valid combination of enumeration constants. This parameter is passed uninitialized; any value originally supplied in result will be overwritten. + /// true if was converted successfully; otherwise, false. + /// + /// is not a value. + /// -or- + /// includes the value. + /// + public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out NFloat result) + { + Unsafe.SkipInit(out result); + return NativeType.TryParse(s, style, provider, out Unsafe.As(ref result)); + } + + /// Tries to convert a character span containing the string representation of a number in a specified style and culture-specific format to its floating-point number equivalent. + /// A read-only character span that contains the number to convert. + /// A bitwise combination of enumeration values that indicate the style elements that can be present in . + /// An object that supplies culture-specific formatting information about . + /// When this method returns, contains a floating-point number equivalent of the numeric value or symbol contained in if the conversion succeeded or zero if the conversion failed. The conversion fails if the is or is not in a format compliant with , or if is not a valid combination of enumeration constants. This parameter is passed uninitialized; any value originally supplied in result will be overwritten. + /// true if was converted successfully; otherwise, false. + /// + /// is not a value. + /// -or- + /// includes the value. + /// + public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out NFloat result) + { + Unsafe.SkipInit(out result); + return NativeType.TryParse(s, style, provider, out Unsafe.As(ref result)); + } + + /// Compares this instance to a specified object and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified object. + /// An object to compare, or null. + /// + /// A signed number indicating the relative values of this instance and . + /// + /// + /// Return Value + /// Description + /// + /// + /// Less than zero + /// This instance is less than , or this instance is not a number and is a number. + /// + /// + /// Zero + /// This instance is equal to , or both this instance and are not a number. + /// + /// + /// Greater than zero + /// This instance is greater than , or this instance is a number and is not a number or is null. + /// + /// + /// + /// is not a . + public int CompareTo(object? obj) + { + if (obj is NFloat other) + { + if (_value < other._value) return -1; + if (_value > other._value) return 1; + if (_value == other._value) return 0; + + // At least one of the values is NaN. + if (NativeType.IsNaN(_value)) + { + return NativeType.IsNaN(other._value) ? 0 : -1; + } + else + { + return 1; + } + } + else if (obj is null) + { + return 1; + } + + throw new ArgumentException(SR.Arg_MustBeNFloat); + } + + /// Compares this instance to a specified floating-point number and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified floating-point number. + /// A floating-point number to compare. + /// + /// A signed number indicating the relative values of this instance and . + /// + /// + /// Return Value + /// Description + /// + /// + /// Less than zero + /// This instance is less than , or this instance is not a number and is a number. + /// + /// + /// Zero + /// This instance is equal to , or both this instance and are not a number. + /// + /// + /// Greater than zero + /// This instance is greater than , or this instance is a number and is not a number. + /// + /// + /// + public int CompareTo(NFloat other) => _value.CompareTo(other._value); + + /// Returns a value indicating whether this instance is equal to a specified object. + /// An object to compare with this instance. + /// true if is an instance of and equals the value of this instance; otherwise, false. + public override bool Equals([NotNullWhen(true)] object? obj) => (obj is NFloat other) && Equals(other); + + /// Returns a value indicating whether this instance is equal to a specified value. /// An value to compare to this instance. /// true if has the same value as this instance; otherwise, false. public bool Equals(NFloat other) => _value.Equals(other._value); - /// - /// Returns the hash code for this instance. - /// + /// Returns the hash code for this instance. /// A 32-bit signed integer hash code. public override int GetHashCode() => _value.GetHashCode(); - /// - /// Converts the numeric value of this instance to its equivalent string representation. - /// + /// Converts the numeric value of this instance to its equivalent string representation. /// The string representation of the value of this instance. public override string ToString() => _value.ToString(); + + /// Converts the numeric value of this instance to its equivalent string representation using the specified format. + /// A numeric format string. + /// The string representation of the value of this instance as specified by . + /// is invalid. + public string ToString(string? format) => _value.ToString(format); + + /// Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information. + /// An object that supplies culture-specific formatting information. + /// The string representation of the value of this instance as specified by . + public string ToString(IFormatProvider? provider)=> _value.ToString(provider); + + /// Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information. + /// A numeric format string. + /// An object that supplies culture-specific formatting information. + /// The string representation of the value of this instance as specified by and . + /// is invalid. + public string ToString(string? format, IFormatProvider? provider) => _value.ToString(format, provider); + + /// Tries to format the value of the current instance into the provided span of characters. + /// The span in which to write this instance's value formatted as a span of characters. + /// When this method returns, contains the number of characters that were written in . + /// A span containing the characters that represent a standard or custom format string that defines the acceptable format for . + /// An optional object that supplies culture-specific formatting information for . + /// true if the formatting was successful; otherwise, false. + public bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format = default, IFormatProvider? provider = null) => _value.TryFormat(destination, out charsWritten, format, provider); } } diff --git a/src/libraries/System.Runtime.InteropServices.NFloat.Internal/Directory.Build.props b/src/libraries/System.Runtime.InteropServices.NFloat.Internal/Directory.Build.props new file mode 100644 index 0000000000000..a2b7f43d8786f --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices.NFloat.Internal/Directory.Build.props @@ -0,0 +1,9 @@ + + + + + false + Microsoft + true + + diff --git a/src/libraries/System.Runtime.InteropServices.NFloat.Internal/System.Runtime.InteropServices.NFloat.Internal.sln b/src/libraries/System.Runtime.InteropServices.NFloat.Internal/System.Runtime.InteropServices.NFloat.Internal.sln new file mode 100644 index 0000000000000..a74a031810bfd --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices.NFloat.Internal/System.Runtime.InteropServices.NFloat.Internal.sln @@ -0,0 +1,198 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Private.CoreLib", "..\..\coreclr\System.Private.CoreLib\System.Private.CoreLib.csproj", "{94B59BA0-491F-4B59-ADFF-A057EC3EC835}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtilities", "..\Common\tests\TestUtilities\TestUtilities.csproj", "{1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.CompilerServices.Unsafe", "..\System.Runtime.CompilerServices.Unsafe\ref\System.Runtime.CompilerServices.Unsafe.csproj", "{5BB5F99F-1052-4EB4-B12E-7863805661F3}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.CompilerServices.Unsafe", "..\System.Runtime.CompilerServices.Unsafe\src\System.Runtime.CompilerServices.Unsafe.ilproj", "{04BA3E3C-6979-4792-B19E-C797AD607F42}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.InteropServices.NFloat.Internal", "ref\System.Runtime.InteropServices.NFloat.Internal.csproj", "{8671F164-F78C-44FA-93B7-A310F67890FE}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.InteropServices.NFloat.Internal", "src\System.Runtime.InteropServices.NFloat.Internal.csproj", "{4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.InteropServices.ComDisabled.Tests", "tests\ComDisabled\System.Runtime.InteropServices.ComDisabled.Tests.csproj", "{6D2197E6-D3DF-43AE-9BEE-3573018639F9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.InteropServices.NFloat.Internal.Tests", "tests\System.Runtime.InteropServices.NFloat.Internal.Tests.csproj", "{E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{FB99AC59-1744-4F12-A4B0-0D54FCA048BF}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B1678CCD-95C8-4419-B9F9-14A03061BE4B}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{D893B9AA-57C5-49E3-97B1-12CC62D84307}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + Checked|Any CPU = Checked|Any CPU + Checked|x64 = Checked|x64 + Checked|x86 = Checked|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Debug|x64.ActiveCfg = Debug|Any CPU + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Debug|x64.Build.0 = Debug|Any CPU + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Debug|x86.ActiveCfg = Debug|Any CPU + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Debug|x86.Build.0 = Debug|Any CPU + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Release|Any CPU.Build.0 = Release|Any CPU + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Release|x64.ActiveCfg = Release|Any CPU + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Release|x64.Build.0 = Release|Any CPU + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Release|x86.ActiveCfg = Release|Any CPU + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Release|x86.Build.0 = Release|Any CPU + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Checked|Any CPU.Build.0 = Debug|Any CPU + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Checked|x64.ActiveCfg = Debug|Any CPU + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Checked|x64.Build.0 = Debug|Any CPU + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Checked|x86.ActiveCfg = Debug|Any CPU + {6D2197E6-D3DF-43AE-9BEE-3573018639F9}.Checked|x86.Build.0 = Debug|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Debug|x64.ActiveCfg = Debug|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Debug|x64.Build.0 = Debug|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Debug|x86.ActiveCfg = Debug|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Debug|x86.Build.0 = Debug|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Release|Any CPU.Build.0 = Release|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Release|x64.ActiveCfg = Release|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Release|x64.Build.0 = Release|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Release|x86.ActiveCfg = Release|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Release|x86.Build.0 = Release|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Checked|Any CPU.Build.0 = Debug|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Checked|x64.ActiveCfg = Debug|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Checked|x64.Build.0 = Debug|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Checked|x86.ActiveCfg = Debug|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Checked|x86.Build.0 = Debug|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Debug|x64.ActiveCfg = Debug|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Debug|x64.Build.0 = Debug|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Debug|x86.ActiveCfg = Debug|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Debug|x86.Build.0 = Debug|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Release|Any CPU.Build.0 = Release|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Release|x64.ActiveCfg = Release|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Release|x64.Build.0 = Release|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Release|x86.ActiveCfg = Release|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Release|x86.Build.0 = Release|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Checked|Any CPU.Build.0 = Debug|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Checked|x64.ActiveCfg = Debug|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Checked|x64.Build.0 = Debug|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Checked|x86.ActiveCfg = Debug|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Checked|x86.Build.0 = Debug|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Debug|x64.ActiveCfg = Debug|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Debug|x64.Build.0 = Debug|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Debug|x86.ActiveCfg = Debug|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Debug|x86.Build.0 = Debug|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Release|Any CPU.Build.0 = Release|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Release|x64.ActiveCfg = Release|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Release|x64.Build.0 = Release|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Release|x86.ActiveCfg = Release|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Release|x86.Build.0 = Release|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Checked|Any CPU.Build.0 = Debug|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Checked|x64.ActiveCfg = Debug|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Checked|x64.Build.0 = Debug|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Checked|x86.ActiveCfg = Debug|Any CPU + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664}.Checked|x86.Build.0 = Debug|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Debug|x64.ActiveCfg = Debug|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Debug|x64.Build.0 = Debug|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Debug|x86.ActiveCfg = Debug|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Debug|x86.Build.0 = Debug|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Release|Any CPU.Build.0 = Release|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Release|x64.ActiveCfg = Release|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Release|x64.Build.0 = Release|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Release|x86.ActiveCfg = Release|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Release|x86.Build.0 = Release|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Checked|Any CPU.Build.0 = Debug|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Checked|x64.ActiveCfg = Debug|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Checked|x64.Build.0 = Debug|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Checked|x86.ActiveCfg = Debug|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Checked|x86.Build.0 = Debug|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Debug|Any CPU.Build.0 = Debug|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Debug|x64.ActiveCfg = Debug|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Debug|x64.Build.0 = Debug|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Debug|x86.ActiveCfg = Debug|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Debug|x86.Build.0 = Debug|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Release|Any CPU.ActiveCfg = Release|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Release|Any CPU.Build.0 = Release|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Release|x64.ActiveCfg = Release|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Release|x64.Build.0 = Release|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Release|x86.ActiveCfg = Release|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Release|x86.Build.0 = Release|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Checked|Any CPU.Build.0 = Debug|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Checked|x64.ActiveCfg = Debug|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Checked|x64.Build.0 = Debug|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Checked|x86.ActiveCfg = Debug|Any CPU + {04BA3E3C-6979-4792-B19E-C797AD607F42}.Checked|x86.Build.0 = Debug|Any CPU + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Debug|Any CPU.ActiveCfg = Debug|x64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Debug|Any CPU.Build.0 = Debug|x64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Debug|x64.ActiveCfg = Debug|x64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Debug|x64.Build.0 = Debug|x64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Debug|x86.ActiveCfg = Debug|x86 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Debug|x86.Build.0 = Debug|x86 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Release|Any CPU.ActiveCfg = Release|x64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Release|Any CPU.Build.0 = Release|x64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Release|x64.ActiveCfg = Release|x64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Release|x64.Build.0 = Release|x64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Release|x86.ActiveCfg = Release|x86 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Release|x86.Build.0 = Release|x86 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|Any CPU.ActiveCfg = Checked|x64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|Any CPU.Build.0 = Checked|x64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|x64.ActiveCfg = Checked|x64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|x64.Build.0 = Checked|x64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|x86.ActiveCfg = Checked|x86 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|x86.Build.0 = Checked|x86 + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Debug|x64.ActiveCfg = Debug|Any CPU + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Debug|x64.Build.0 = Debug|Any CPU + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Debug|x86.ActiveCfg = Debug|Any CPU + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Debug|x86.Build.0 = Debug|Any CPU + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Release|Any CPU.Build.0 = Release|Any CPU + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Release|x64.ActiveCfg = Release|Any CPU + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Release|x64.Build.0 = Release|Any CPU + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Release|x86.ActiveCfg = Release|Any CPU + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Release|x86.Build.0 = Release|Any CPU + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Checked|Any CPU.Build.0 = Debug|Any CPU + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Checked|x64.ActiveCfg = Debug|Any CPU + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Checked|x64.Build.0 = Debug|Any CPU + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Checked|x86.ActiveCfg = Debug|Any CPU + {5BB5F99F-1052-4EB4-B12E-7863805661F3}.Checked|x86.Build.0 = Debug|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {6D2197E6-D3DF-43AE-9BEE-3573018639F9} = {FB99AC59-1744-4F12-A4B0-0D54FCA048BF} + {E249BD6A-85DB-4CE4-BD82-8D67EBAC5664} = {FB99AC59-1744-4F12-A4B0-0D54FCA048BF} + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA} = {FB99AC59-1744-4F12-A4B0-0D54FCA048BF} + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1} = {B1678CCD-95C8-4419-B9F9-14A03061BE4B} + {04BA3E3C-6979-4792-B19E-C797AD607F42} = {B1678CCD-95C8-4419-B9F9-14A03061BE4B} + {94B59BA0-491F-4B59-ADFF-A057EC3EC835} = {B1678CCD-95C8-4419-B9F9-14A03061BE4B} + {8671F164-F78C-44FA-93B7-A310F67890FE} = {D893B9AA-57C5-49E3-97B1-12CC62D84307} + {5BB5F99F-1052-4EB4-B12E-7863805661F3} = {D893B9AA-57C5-49E3-97B1-12CC62D84307} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D4031401-FEB5-4CCF-91C1-38F5646B2BFD} + EndGlobalSection +EndGlobal diff --git a/src/libraries/System.Runtime.InteropServices.NFloat.Internal/ref/System.Runtime.InteropServices.NFloat.Internal.csproj b/src/libraries/System.Runtime.InteropServices.NFloat.Internal/ref/System.Runtime.InteropServices.NFloat.Internal.csproj new file mode 100644 index 0000000000000..144688b2bf26d --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices.NFloat.Internal/ref/System.Runtime.InteropServices.NFloat.Internal.csproj @@ -0,0 +1,44 @@ + + + System.Runtime.InteropServices + true + + + $(NoWarn);0809;0618;CS8614;CS8765;CS3015;NU5131 + true + $(NetCoreAppCurrent) + enable + + + + ref + $(DefineConstants);FEATURE_NFLOAT + true + 1 + true + Exposes additional NFloat APIs for Xamarin/Maui APIs from System.Runtime.InteropServices + $(MSBuildProjectName) + + true + + + + + + + + + + + + <_FileVersionMaj>$(FileVersion.Split('.')[0]) + <_FileVersionMin>$(FileVersion.Split('.')[1]) + <_FileVersionBld>$(FileVersion.Split('.')[2]) + <_FileVersionRev>$(FileVersion.Split('.')[3]) + $(_FileVersionMaj).$([MSBuild]::Add($(_FileVersionMin), 100)).$(_FileVersionBld).$(_FileVersionRev) + + + diff --git a/src/libraries/System.Runtime.InteropServices.NFloat.Internal/src/System.Runtime.InteropServices.NFloat.Internal.proj b/src/libraries/System.Runtime.InteropServices.NFloat.Internal/src/System.Runtime.InteropServices.NFloat.Internal.proj new file mode 100644 index 0000000000000..304633a1911a7 --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices.NFloat.Internal/src/System.Runtime.InteropServices.NFloat.Internal.proj @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/libraries/System.Runtime.InteropServices.NFloat.Internal/tests/System.Runtime.InteropServices.NFloat.Internal.Tests.csproj b/src/libraries/System.Runtime.InteropServices.NFloat.Internal/tests/System.Runtime.InteropServices.NFloat.Internal.Tests.csproj new file mode 100644 index 0000000000000..a8499d3dde85d --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices.NFloat.Internal/tests/System.Runtime.InteropServices.NFloat.Internal.Tests.csproj @@ -0,0 +1,19 @@ + + + true + true + $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser + true + true + + + $(DefineConstants);FEATURE_NFLOAT + + + + + + + + + diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs index 6fa5eb10ea0d4..e7eb8164ddbdc 100644 --- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs +++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs @@ -157,13 +157,14 @@ public enum ClassInterfaceType AutoDual = 2, } [System.CLSCompliantAttribute(false)] - public readonly struct CLong : IEquatable + public readonly partial struct CLong : System.IEquatable { - public CLong(int value) { } - public CLong(nint value) { } + private readonly int _dummyPrimitive; + public CLong(int value) { throw null; } + public CLong(nint value) { throw null; } public nint Value { get { throw null; } } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? o) { throw null; } - public bool Equals(CLong other) { throw null; } + public bool Equals(System.Runtime.InteropServices.CLong other) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } } @@ -294,13 +295,14 @@ public sealed partial class ComUnregisterFunctionAttribute : System.Attribute public ComUnregisterFunctionAttribute() { } } [System.CLSCompliantAttribute(false)] - public readonly struct CULong : IEquatable + public readonly partial struct CULong : System.IEquatable { - public CULong(uint value) { } - public CULong(nuint value) { } + private readonly int _dummyPrimitive; + public CULong(uint value) { throw null; } + public CULong(nuint value) { throw null; } public nuint Value { get { throw null; } } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? o) { throw null; } - public bool Equals(CULong other) { throw null; } + public bool Equals(System.Runtime.InteropServices.CULong other) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } } @@ -782,15 +784,109 @@ public static void Free(void* ptr) { } [System.CLSCompliantAttribute(false)] public static void* Realloc(void* ptr, nuint byteCount) { throw null; } } - public readonly struct NFloat : IEquatable + public readonly partial struct NFloat : System.IEquatable +#if FEATURE_NFLOAT +#pragma warning disable SA1001 + , System.IComparable, + System.IComparable, + System.IFormattable, + System.ISpanFormattable +#pragma warning restore SA1001 +#endif // FEATURE_NFLOAT { - public NFloat(float value) { } - public NFloat(double value) { } + private readonly int _dummyPrimitive; + public NFloat(double value) { throw null; } + public NFloat(float value) { throw null; } public double Value { get { throw null; } } - public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? o) { throw null; } - public bool Equals(NFloat other) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } + public bool Equals(System.Runtime.InteropServices.NFloat other) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } +#if FEATURE_NFLOAT + public static System.Runtime.InteropServices.NFloat Epsilon { get { throw null; } } + public static System.Runtime.InteropServices.NFloat MaxValue { get { throw null; } } + public static System.Runtime.InteropServices.NFloat MinValue { get { throw null; } } + public static System.Runtime.InteropServices.NFloat NaN { get { throw null; } } + public static System.Runtime.InteropServices.NFloat NegativeInfinity { get { throw null; } } + public static System.Runtime.InteropServices.NFloat PositiveInfinity { get { throw null; } } + public static int Size { get { throw null; } } + public int CompareTo(object? obj) { throw null; } + public int CompareTo(System.Runtime.InteropServices.NFloat other) { throw null; } + public static bool IsFinite(System.Runtime.InteropServices.NFloat value) { throw null; } + public static bool IsInfinity(System.Runtime.InteropServices.NFloat value) { throw null; } + public static bool IsNaN(System.Runtime.InteropServices.NFloat value) { throw null; } + public static bool IsNegative(System.Runtime.InteropServices.NFloat value) { throw null; } + public static bool IsNegativeInfinity(System.Runtime.InteropServices.NFloat value) { throw null; } + public static bool IsNormal(System.Runtime.InteropServices.NFloat value) { throw null; } + public static bool IsPositiveInfinity(System.Runtime.InteropServices.NFloat value) { throw null; } + public static bool IsSubnormal(System.Runtime.InteropServices.NFloat value) { throw null; } + public static System.Runtime.InteropServices.NFloat operator +(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } + public static System.Runtime.InteropServices.NFloat operator --(System.Runtime.InteropServices.NFloat value) { throw null; } + public static System.Runtime.InteropServices.NFloat operator /(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } + public static bool operator ==(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } + public static explicit operator System.Runtime.InteropServices.NFloat (decimal value) { throw null; } + public static explicit operator System.Runtime.InteropServices.NFloat (double value) { throw null; } + public static explicit operator byte (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator char (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator decimal (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator short (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator int (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator long (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator nint (System.Runtime.InteropServices.NFloat value) { throw null; } + [System.CLSCompliantAttribute(false)] + public static explicit operator sbyte (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator float (System.Runtime.InteropServices.NFloat value) { throw null; } + [System.CLSCompliantAttribute(false)] + public static explicit operator ushort (System.Runtime.InteropServices.NFloat value) { throw null; } + [System.CLSCompliantAttribute(false)] + public static explicit operator uint (System.Runtime.InteropServices.NFloat value) { throw null; } + [System.CLSCompliantAttribute(false)] + public static explicit operator ulong (System.Runtime.InteropServices.NFloat value) { throw null; } + [System.CLSCompliantAttribute(false)] + public static explicit operator nuint (System.Runtime.InteropServices.NFloat value) { throw null; } + public static bool operator >(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } + public static bool operator >=(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (byte value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (char value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (short value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (int value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (long value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (nint value) { throw null; } + public static implicit operator double (System.Runtime.InteropServices.NFloat value) { throw null; } + [System.CLSCompliantAttribute(false)] + public static implicit operator System.Runtime.InteropServices.NFloat (sbyte value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (float value) { throw null; } + [System.CLSCompliantAttribute(false)] + public static implicit operator System.Runtime.InteropServices.NFloat (ushort value) { throw null; } + [System.CLSCompliantAttribute(false)] + public static implicit operator System.Runtime.InteropServices.NFloat (uint value) { throw null; } + [System.CLSCompliantAttribute(false)] + public static implicit operator System.Runtime.InteropServices.NFloat (ulong value) { throw null; } + [System.CLSCompliantAttribute(false)] + public static implicit operator System.Runtime.InteropServices.NFloat (nuint value) { throw null; } + public static System.Runtime.InteropServices.NFloat operator ++(System.Runtime.InteropServices.NFloat value) { throw null; } + public static bool operator !=(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } + public static bool operator <(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } + public static bool operator <=(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } + public static System.Runtime.InteropServices.NFloat operator %(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } + public static System.Runtime.InteropServices.NFloat operator *(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } + public static System.Runtime.InteropServices.NFloat operator -(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } + public static System.Runtime.InteropServices.NFloat operator -(System.Runtime.InteropServices.NFloat value) { throw null; } + public static System.Runtime.InteropServices.NFloat operator +(System.Runtime.InteropServices.NFloat value) { throw null; } + public static System.Runtime.InteropServices.NFloat Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.AllowDecimalPoint | System.Globalization.NumberStyles.AllowExponent | System.Globalization.NumberStyles.AllowLeadingSign | System.Globalization.NumberStyles.AllowLeadingWhite | System.Globalization.NumberStyles.AllowThousands | System.Globalization.NumberStyles.AllowTrailingWhite, System.IFormatProvider? provider = null) { throw null; } + public static System.Runtime.InteropServices.NFloat Parse(string s) { throw null; } + public static System.Runtime.InteropServices.NFloat Parse(string s, System.Globalization.NumberStyles style) { throw null; } + public static System.Runtime.InteropServices.NFloat Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; } + public static System.Runtime.InteropServices.NFloat Parse(string s, System.IFormatProvider? provider) { throw null; } + public string ToString(System.IFormatProvider? provider) { throw null; } + public string ToString(string? format) { 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; } + public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Runtime.InteropServices.NFloat result) { throw null; } + public static bool TryParse(System.ReadOnlySpan s, out System.Runtime.InteropServices.NFloat result) { throw null; } + public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Runtime.InteropServices.NFloat result) { throw null; } + public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.Runtime.InteropServices.NFloat result) { throw null; } +#endif // FEATURE_NFLOAT } [System.AttributeUsageAttribute(System.AttributeTargets.Parameter, Inherited=false)] public sealed partial class OptionalAttribute : System.Attribute diff --git a/src/libraries/System.Runtime.InteropServices/src/MatchingRefApiCompatBaseline.txt b/src/libraries/System.Runtime.InteropServices/src/MatchingRefApiCompatBaseline.txt index dd2e06b69c3c2..7f9c02ebeff29 100644 --- a/src/libraries/System.Runtime.InteropServices/src/MatchingRefApiCompatBaseline.txt +++ b/src/libraries/System.Runtime.InteropServices/src/MatchingRefApiCompatBaseline.txt @@ -8,4 +8,80 @@ TypesMustExist : Type 'System.Runtime.InteropServices.RegistrationClassContext' TypesMustExist : Type 'System.Runtime.InteropServices.RegistrationConnectionType' does not exist in the reference but it does exist in the implementation. TypesMustExist : Type 'System.Runtime.InteropServices.SetWin32ContextInIDispatchAttribute' does not exist in the reference but it does exist in the implementation. MembersMustExist : Member 'public void System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute..ctor()' does not exist in the reference but it does exist in the implementation. -Total Issues: 9 +CannotRemoveBaseTypeOrInterface : Type 'System.Runtime.InteropServices.NFloat' does not implement interface 'System.IComparable' in the reference but it does in the implementation. +MembersMustExist : Member 'public System.Int32 System.Runtime.InteropServices.NFloat.CompareTo(System.Object)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Int32 System.Runtime.InteropServices.NFloat.CompareTo(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.Epsilon.get()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.IsFinite(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.IsInfinity(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.IsNaN(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.IsNegative(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.IsNegativeInfinity(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.IsNormal(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.IsPositiveInfinity(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.IsSubnormal(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.MaxValue.get()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.MinValue.get()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.NaN.get()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.NegativeInfinity.get()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Addition(System.Runtime.InteropServices.NFloat, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Decrement(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Division(System.Runtime.InteropServices.NFloat, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.op_Equality(System.Runtime.InteropServices.NFloat, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation.C:\Users\tagoo\.nuget\packages\microsoft.dotnet.apicompat\6.0.0-beta.21614.2\build\Microsoft.DotNet.ApiCompat.targets(145,5): error : MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Explicit(System.Decimal)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Explicit(System.Double)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Byte System.Runtime.InteropServices.NFloat.op_Explicit(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Char System.Runtime.InteropServices.NFloat.op_Explicit(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Decimal System.Runtime.InteropServices.NFloat.op_Explicit(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Int16 System.Runtime.InteropServices.NFloat.op_Explicit(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Int32 System.Runtime.InteropServices.NFloat.op_Explicit(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Int64 System.Runtime.InteropServices.NFloat.op_Explicit(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.IntPtr System.Runtime.InteropServices.NFloat.op_Explicit(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.SByte System.Runtime.InteropServices.NFloat.op_Explicit(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Single System.Runtime.InteropServices.NFloat.op_Explicit(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.UInt16 System.Runtime.InteropServices.NFloat.op_Explicit(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.UInt32 System.Runtime.InteropServices.NFloat.op_Explicit(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.UInt64 System.Runtime.InteropServices.NFloat.op_Explicit(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.UIntPtr System.Runtime.InteropServices.NFloat.op_Explicit(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.op_GreaterThan(System.Runtime.InteropServices.NFloat, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.op_GreaterThanOrEqual(System.Runtime.InteropServices.NFloat, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Implicit(System.Byte)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Implicit(System.Char)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Implicit(System.Int16)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Implicit(System.Int32)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Implicit(System.Int64)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Implicit(System.IntPtr)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Double System.Runtime.InteropServices.NFloat.op_Implicit(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Implicit(System.SByte)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Implicit(System.Single)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Implicit(System.UInt16)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Implicit(System.UInt32)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Implicit(System.UInt64)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Implicit(System.UIntPtr)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Increment(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.op_Inequality(System.Runtime.InteropServices.NFloat, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.op_LessThan(System.Runtime.InteropServices.NFloat, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation.C:\Users\tagoo\.nuget\packages\microsoft.dotnet.apicompat\6.0.0-beta.21614.2\build\Microsoft.DotNet.ApiCompat.targets(145,5): error : MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.op_LessThanOrEqual(System.Runtime.InteropServices.NFloat, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Modulus(System.Runtime.InteropServices.NFloat, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Multiply(System.Runtime.InteropServices.NFloat, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Subtraction(System.Runtime.InteropServices.NFloat, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_UnaryNegation(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_UnaryPlus(System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.Parse(System.ReadOnlySpan, System.Globalization.NumberStyles, System.IFormatProvider)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.Parse(System.String)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.Parse(System.String, System.Globalization.NumberStyles)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.Parse(System.String, System.Globalization.NumberStyles, System.IFormatProvider)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.Parse(System.String, System.IFormatProvider)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.PositiveInfinity.get()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Int32 System.Runtime.InteropServices.NFloat.Size.get()' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.String System.Runtime.InteropServices.NFloat.ToString(System.IFormatProvider)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.String System.Runtime.InteropServices.NFloat.ToString(System.String)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.String System.Runtime.InteropServices.NFloat.ToString(System.String, System.IFormatProvider)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.TryFormat(System.Span, System.Int32, System.ReadOnlySpan, System.IFormatProvider)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.TryParse(System.ReadOnlySpan, System.Globalization.NumberStyles, System.IFormatProvider, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.TryParse(System.ReadOnlySpan, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.TryParse(System.String, System.Globalization.NumberStyles, System.IFormatProvider, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.TryParse(System.String, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.op_Equality(System.Runtime.InteropServices.NFloat, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Runtime.InteropServices.NFloat System.Runtime.InteropServices.NFloat.op_Explicit(System.Decimal)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.op_LessThan(System.Runtime.InteropServices.NFloat, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Boolean System.Runtime.InteropServices.NFloat.op_LessThanOrEqual(System.Runtime.InteropServices.NFloat, System.Runtime.InteropServices.NFloat)' does not exist in the reference but it does exist in the implementation. +Total Issues: 85 diff --git a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/NFloatTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/NFloatTests.cs index c2311afae708d..b56ee77c89003 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/NFloatTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/NFloatTests.cs @@ -15,36 +15,36 @@ public class NFloatTests [Fact] public void Ctor_Empty() { - NFloat value = new NFloat(); - Assert.Equal(0, value.Value); + NFloat result = new NFloat(); + Assert.Equal(0, result.Value); } [Fact] public void Ctor_Float() { - NFloat value = new NFloat(42.0f); - Assert.Equal(42.0, value.Value); + NFloat result = new NFloat(42.0f); + Assert.Equal(42.0, result.Value); } [Fact] public void Ctor_Double() { - NFloat value = new NFloat(42.0); - Assert.Equal(42.0, value.Value); + NFloat result = new NFloat(42.0); + Assert.Equal(42.0, result.Value); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.Is32BitProcess))] public void Ctor_Double_OutOfRange() { - NFloat value = new NFloat(double.MaxValue); - Assert.Equal((double)(float)double.MaxValue, value.Value); + NFloat result = new NFloat(double.MaxValue); + Assert.Equal(float.PositiveInfinity, result.Value); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.Is64BitProcess))] public void Ctor_Double_LargeValue() { - NFloat value = new NFloat(double.MaxValue); - Assert.Equal(double.MaxValue, value.Value); + NFloat result = new NFloat(double.MaxValue); + Assert.Equal(double.MaxValue, result.Value); } public static IEnumerable EqualsData() @@ -83,7 +83,6 @@ public void NaNEqualsTest() [InlineData(0.0f)] [InlineData(4567.0f)] [InlineData(4567.89101f)] - [InlineData(float.NaN)] public static void ToStringTest64(float value) { @@ -116,5 +115,805 @@ public unsafe void Size() #pragma warning restore xUnit2000 Assert.Equal(size, Marshal.SizeOf()); } + +#if FEATURE_NFLOAT + [Fact] + public void Epsilon() + { + NFloat result = NFloat.Epsilon; + + if (Environment.Is64BitProcess) + { + Assert.Equal(double.Epsilon, result.Value); + } + else + { + Assert.Equal(float.Epsilon, result.Value); + } + } + + [Fact] + public void MaxValue() + { + NFloat result = NFloat.MaxValue; + + if (Environment.Is64BitProcess) + { + Assert.Equal(double.MaxValue, result.Value); + } + else + { + Assert.Equal(float.MaxValue, result.Value); + } + } + + [Fact] + public void MinValue() + { + NFloat result = NFloat.MinValue; + + if (Environment.Is64BitProcess) + { + Assert.Equal(double.MinValue, result.Value); + } + else + { + Assert.Equal(float.MinValue, result.Value); + } + } + + [Fact] + public void NaN() + { + NFloat result = NFloat.NaN; + Assert.True(double.IsNaN(result.Value)); + } + + [Fact] + public void NegativeInfinity() + { + NFloat result = NFloat.NegativeInfinity; + + if (Environment.Is64BitProcess) + { + Assert.Equal(double.NegativeInfinity, result.Value); + } + else + { + Assert.Equal(float.NegativeInfinity, result.Value); + } + } + + [Fact] + public void PositiveInfinity() + { + NFloat result = NFloat.PositiveInfinity; + + if (Environment.Is64BitProcess) + { + Assert.Equal(double.PositiveInfinity, result.Value); + } + else + { + Assert.Equal(float.PositiveInfinity, result.Value); + } + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public static void op_UnaryPlus(float value) + { + NFloat result = +(new NFloat(value)); + Assert.Equal(+value, result.Value); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public static void op_UnaryNegation(float value) + { + NFloat result = -(new NFloat(value)); + Assert.Equal(-value, result.Value); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public static void op_Decrement(float value) + { + NFloat result = new NFloat(value); + --result; + + if (Environment.Is64BitProcess) + { + Assert.Equal((double)value - 1, result.Value); + } + else + { + Assert.Equal(value - 1, result.Value); + } + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public static void op_Increment(float value) + { + NFloat result = new NFloat(value); + ++result; + + if (Environment.Is64BitProcess) + { + Assert.Equal((double)value + 1, result.Value); + } + else + { + Assert.Equal(value + 1, result.Value); + } + } + + [Theory] + [InlineData(-4567.0f, 3.14f)] + [InlineData(-4567.89101f, 3.14569f)] + [InlineData(0.0f, 3.14f)] + [InlineData(4567.0f, -3.14f)] + [InlineData(4567.89101f, -3.14569f)] + public static void op_Addition(float left, float right) + { + NFloat result = new NFloat(left) + new NFloat(right); + + if (Environment.Is64BitProcess) + { + Assert.Equal((double)left + right, result.Value); + } + else + { + Assert.Equal(left + right, result.Value); + } + } + + [Theory] + [InlineData(-4567.0f, 3.14f)] + [InlineData(-4567.89101f, 3.14569f)] + [InlineData(0.0f, 3.14f)] + [InlineData(4567.0f, -3.14f)] + [InlineData(4567.89101f, -3.14569f)] + public static void op_Subtraction(float left, float right) + { + NFloat result = new NFloat(left) - new NFloat(right); + + if (Environment.Is64BitProcess) + { + Assert.Equal((double)left - right, result.Value); + } + else + { + Assert.Equal(left - right, result.Value); + } + } + + [Theory] + [InlineData(-4567.0f, 3.14f)] + [InlineData(-4567.89101f, 3.14569f)] + [InlineData(0.0f, 3.14f)] + [InlineData(4567.0f, -3.14f)] + [InlineData(4567.89101f, -3.14569f)] + public static void op_Multiply(float left, float right) + { + NFloat result = new NFloat(left) * new NFloat(right); + + if (Environment.Is64BitProcess) + { + Assert.Equal((double)left * right, result.Value); + } + else + { + Assert.Equal(left * right, result.Value); + } + } + + [Theory] + [InlineData(-4567.0f, 3.14f)] + [InlineData(-4567.89101f, 3.14569f)] + [InlineData(0.0f, 3.14f)] + [InlineData(4567.0f, -3.14f)] + [InlineData(4567.89101f, -3.14569f)] + public static void op_Division(float left, float right) + { + NFloat result = new NFloat(left) / new NFloat(right); + + if (Environment.Is64BitProcess) + { + Assert.Equal((double)left / right, result.Value); + } + else + { + Assert.Equal(left / right, result.Value); + } + } + + [Theory] + [InlineData(-4567.0f, 3.14f)] + [InlineData(-4567.89101f, 3.14569f)] + [InlineData(0.0f, 3.14f)] + [InlineData(4567.0f, -3.14f)] + [InlineData(4567.89101f, -3.14569f)] + public static void op_Modulus(float left, float right) + { + NFloat result = new NFloat(left) % new NFloat(right); + + if (Environment.Is64BitProcess) + { + Assert.Equal((double)left % right, result.Value); + } + else + { + Assert.Equal(left % right, result.Value); + } + } + + [Theory] + [InlineData(789.0f, 789.0f)] + [InlineData(789.0f, -789.0f)] + [InlineData(789.0f, 0.0f)] + [InlineData(789.0f, 1000.0f)] + public void op_Equality(float left, float right) + { + bool result = new NFloat(left) == new NFloat(right); + Assert.Equal(left == right, result); + } + + [Theory] + [InlineData(789.0f, 789.0f)] + [InlineData(789.0f, -789.0f)] + [InlineData(789.0f, 0.0f)] + [InlineData(789.0f, 1000.0f)] + public void op_Inequality(float left, float right) + { + bool result = new NFloat(left) != new NFloat(right); + Assert.Equal(left != right, result); + } + + [Theory] + [InlineData(789.0f, 789.0f)] + [InlineData(789.0f, -789.0f)] + [InlineData(789.0f, 0.0f)] + [InlineData(789.0f, 1000.0f)] + public void op_GreaterThan(float left, float right) + { + bool result = new NFloat(left) > new NFloat(right); + Assert.Equal(left > right, result); + } + + [Theory] + [InlineData(789.0f, 789.0f)] + [InlineData(789.0f, -789.0f)] + [InlineData(789.0f, 0.0f)] + [InlineData(789.0f, 1000.0f)] + public void op_GreaterThanOrEqual(float left, float right) + { + bool result = new NFloat(left) >= new NFloat(right); + Assert.Equal(left >= right, result); + } + + [Theory] + [InlineData(789.0f, 789.0f)] + [InlineData(789.0f, -789.0f)] + [InlineData(789.0f, 0.0f)] + [InlineData(789.0f, 1000.0f)] + public void op_LessThan(float left, float right) + { + bool result = new NFloat(left) < new NFloat(right); + Assert.Equal(left < right, result); + } + + [Theory] + [InlineData(789.0f, 789.0f)] + [InlineData(789.0f, -789.0f)] + [InlineData(789.0f, 0.0f)] + [InlineData(789.0f, 1000.0f)] + public void op_LessThanOrEqual(float left, float right) + { + bool result = new NFloat(left) <= new NFloat(right); + Assert.Equal(left <= right, result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public void DoubleToNFloat(float value) + { + NFloat result = (NFloat)(double)value; + + if (Environment.Is64BitProcess) + { + Assert.Equal(value, result.Value); + } + else + { + Assert.Equal((float)value, result.Value); + } + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public void NFloatToByte(float value) + { + byte result = (byte)new NFloat(value); + Assert.Equal((byte)value, result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public void NFloatToChar(float value) + { + char result = (char)new NFloat(value); + Assert.Equal((char)value, result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public void NFloatToDecimal(float value) + { + decimal result = (decimal)new NFloat(value); + + if (Environment.Is64BitProcess) + { + Assert.Equal((decimal)(double)value, result); + } + else + { + Assert.Equal((decimal)value, result); + } + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public void NFloatToInt16(float value) + { + short result = (short)new NFloat(value); + Assert.Equal((short)value, result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public void NFloatToInt32(float value) + { + int result = (int)new NFloat(value); + Assert.Equal((int)value, result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public void NFloatToInt64(float value) + { + long result = (long)new NFloat(value); + Assert.Equal((long)value, result); + } + + [Theory] + [InlineData(-4567.0f, Skip = "https://github.com/dotnet/runtime/issues/64386")] + [InlineData(-4567.89101f, Skip = "https://github.com/dotnet/runtime/issues/64386")] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public void NFloatToIntPtr(float value) + { + nint result = (nint)new NFloat(value); + Assert.Equal((nint)value, result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public void NFloatToSByte(float value) + { + sbyte result = (sbyte)new NFloat(value); + Assert.Equal((sbyte)value, result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public void NFloatToSingle(float value) + { + float result = (float)new NFloat(value); + Assert.Equal(value, result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public void NFloatToUInt16(float value) + { + ushort result = (ushort)new NFloat(value); + Assert.Equal((ushort)value, result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public void NFloatToUInt32(float value) + { + uint result = (uint)new NFloat(value); + Assert.Equal((uint)value, result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public void NFloatToUInt64(float value) + { + ulong result = (ulong)new NFloat(value); + Assert.Equal((ulong)value, result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public void NFloatToUIntPtr(float value) + { + nuint result = (nuint)new NFloat(value); + Assert.Equal((nuint)value, result); + } + + [Theory] + [InlineData((byte)0)] + [InlineData((byte)5)] + [InlineData((byte)42)] + [InlineData((byte)127)] + [InlineData((byte)255)] + public void ByteToNFloat(byte value) + { + NFloat result = value; + Assert.Equal(value, result.Value); + } + + [Theory] + [InlineData('A')] + [InlineData('B')] + [InlineData('C')] + [InlineData('D')] + [InlineData('E')] + public void CharToNFloat(char value) + { + NFloat result = value; + Assert.Equal(value, result.Value); + } + + [Theory] + [InlineData((short)-255)] + [InlineData((short)-127)] + [InlineData((short)0)] + [InlineData((short)127)] + [InlineData((short)255)] + public void Int16ToNFloat(short value) + { + NFloat result = value; + Assert.Equal(value, result.Value); + } + + [Theory] + [InlineData(-255)] + [InlineData(-127)] + [InlineData(0)] + [InlineData(127)] + [InlineData(255)] + public void Int32ToNFloat(int value) + { + NFloat result = value; + Assert.Equal(value, result.Value); + } + + [Theory] + [InlineData((long)-255)] + [InlineData((long)-127)] + [InlineData((long)0)] + [InlineData((long)127)] + [InlineData((long)255)] + public void Int64ToNFloat(long value) + { + NFloat result = value; + Assert.Equal(value, result.Value); + } + + [Theory] + [InlineData((int)-255)] + [InlineData((int)-127)] + [InlineData((int)0)] + [InlineData((int)127)] + [InlineData((int)255)] + public void IntPtrToNFloat(int value) + { + NFloat result = (nint)value; + Assert.Equal(value, result.Value); + } + + [Theory] + [InlineData((sbyte)-127)] + [InlineData((sbyte)-63)] + [InlineData((sbyte)0)] + [InlineData((sbyte)63)] + [InlineData((sbyte)127)] + public void SByteToNFloat(sbyte value) + { + NFloat result = value; + Assert.Equal(value, result.Value); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public void SingleToNFloat(float value) + { + NFloat result = value; + Assert.Equal(value, result.Value); + } + + [Theory] + [InlineData((ushort)0)] + [InlineData((ushort)5)] + [InlineData((ushort)42)] + [InlineData((ushort)127)] + [InlineData((ushort)255)] + public void UInt16ToNFloat(ushort value) + { + NFloat result = value; + Assert.Equal(value, result.Value); + } + + [Theory] + [InlineData((uint)0)] + [InlineData((uint)5)] + [InlineData((uint)42)] + [InlineData((uint)127)] + [InlineData((uint)255)] + public void UInt32ToNFloat(uint value) + { + NFloat result = value; + Assert.Equal(value, result.Value); + } + + [Theory] + [InlineData((ulong)0)] + [InlineData((ulong)5)] + [InlineData((ulong)42)] + [InlineData((ulong)127)] + [InlineData((ulong)255)] + public void UInt64ToNFloat(ulong value) + { + NFloat result = value; + Assert.Equal(value, result.Value); + } + + [Theory] + [InlineData((uint)0)] + [InlineData((uint)5)] + [InlineData((uint)42)] + [InlineData((uint)127)] + [InlineData((uint)255)] + public void UIntPtrToNFloat(uint value) + { + NFloat result = (nuint)value; + Assert.Equal(value, result.Value); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + public void NFloatToDouble(float value) + { + double result = new NFloat(value); + Assert.Equal(value, result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + [InlineData(float.Epsilon)] + [InlineData(float.NegativeInfinity)] + [InlineData(float.PositiveInfinity)] + [InlineData(float.NaN)] + public void IsFinite(float value) + { + bool result = NFloat.IsFinite(value); + Assert.Equal(float.IsFinite(value), result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + [InlineData(float.Epsilon)] + [InlineData(float.NegativeInfinity)] + [InlineData(float.PositiveInfinity)] + [InlineData(float.NaN)] + public void IsInfinity(float value) + { + bool result = NFloat.IsInfinity(value); + Assert.Equal(float.IsInfinity(value), result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + [InlineData(float.Epsilon)] + [InlineData(float.NegativeInfinity)] + [InlineData(float.PositiveInfinity)] + [InlineData(float.NaN)] + public void IsNaN(float value) + { + bool result = NFloat.IsNaN(value); + Assert.Equal(float.IsNaN(value), result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + [InlineData(float.Epsilon)] + [InlineData(float.NegativeInfinity)] + [InlineData(float.PositiveInfinity)] + [InlineData(float.NaN)] + public void IsNegative(float value) + { + bool result = NFloat.IsNegative(value); + Assert.Equal(float.IsNegative(value), result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + [InlineData(float.Epsilon)] + [InlineData(float.NegativeInfinity)] + [InlineData(float.PositiveInfinity)] + [InlineData(float.NaN)] + public void IsNegativeInfinity(float value) + { + bool result = NFloat.IsNegativeInfinity(value); + Assert.Equal(float.IsNegativeInfinity(value), result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + [InlineData(float.Epsilon)] + [InlineData(float.NegativeInfinity)] + [InlineData(float.PositiveInfinity)] + [InlineData(float.NaN)] + public void IsNormal(float value) + { + bool result = NFloat.IsNormal(value); + + if (Environment.Is64BitProcess) + { + Assert.Equal(double.IsNormal(value), result); + } + else + { + Assert.Equal(float.IsNormal(value), result); + } + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + [InlineData(float.Epsilon)] + [InlineData(float.NegativeInfinity)] + [InlineData(float.PositiveInfinity)] + [InlineData(float.NaN)] + public void IsPositiveInfinity(float value) + { + bool result = NFloat.IsPositiveInfinity(value); + Assert.Equal(float.IsPositiveInfinity(value), result); + } + + [Theory] + [InlineData(-4567.0f)] + [InlineData(-4567.89101f)] + [InlineData(0.0f)] + [InlineData(4567.0f)] + [InlineData(4567.89101f)] + [InlineData(float.Epsilon)] + [InlineData(float.NegativeInfinity)] + [InlineData(float.PositiveInfinity)] + [InlineData(float.NaN)] + public void IsSubnormal(float value) + { + bool result = NFloat.IsSubnormal(value); + + if (Environment.Is64BitProcess) + { + Assert.Equal(double.IsSubnormal(value), result); + } + else + { + Assert.Equal(float.IsSubnormal(value), result); + } + } +#endif // FEATURE_NFLOAT } } diff --git a/src/libraries/testPackages/packageSettings/System.Runtime.InteropServices.NFloat.Internal/settings.targets b/src/libraries/testPackages/packageSettings/System.Runtime.InteropServices.NFloat.Internal/settings.targets new file mode 100644 index 0000000000000..eaa4cdfb1bb52 --- /dev/null +++ b/src/libraries/testPackages/packageSettings/System.Runtime.InteropServices.NFloat.Internal/settings.targets @@ -0,0 +1,5 @@ + + + true + + \ No newline at end of file