From 4aff8c8915b0bd65d13cf86411b63761a55628ed Mon Sep 17 00:00:00 2001 From: Blokyk <32983140+Blokyk@users.noreply.github.com> Date: Sat, 3 Sep 2022 22:00:54 +0200 Subject: [PATCH 1/5] Don't ignore mode in IFloatingPoint.Round(TSelf, MipointRounding) DIM --- .../src/System/Numerics/IFloatingPoint.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/IFloatingPoint.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/IFloatingPoint.cs index 0abcc40ebbbd3c..c8e58d8f8fb826 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/IFloatingPoint.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/IFloatingPoint.cs @@ -36,7 +36,7 @@ public interface IFloatingPoint /// The value to round. /// The mode under which should be rounded. /// The result of rounding to the nearest integer using . - static virtual TSelf Round(TSelf x, MidpointRounding mode) => TSelf.Round(x, digits: 0, MidpointRounding.ToEven); + static virtual TSelf Round(TSelf x, MidpointRounding mode) => TSelf.Round(x, digits: 0, mode); /// Rounds a value to a specified number of fractional-digits using the default rounding mode (). /// The value to round. From 06fe9271f2eb48527eb2a21f4b2468066f07803c Mon Sep 17 00:00:00 2001 From: Blokyk <32983140+Blokyk@users.noreply.github.com> Date: Sat, 3 Sep 2022 22:05:09 +0200 Subject: [PATCH 2/5] Fix recursion in IExponentialFunctions.Exp10M1's DIM --- .../src/System/Numerics/IExponentialFunctions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/IExponentialFunctions.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/IExponentialFunctions.cs index f7370ff4708fbf..b060924c8ceadb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/IExponentialFunctions.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/IExponentialFunctions.cs @@ -37,6 +37,6 @@ public interface IExponentialFunctions /// Computes 10 raised to a given power and subtracts one. /// The power to which 10 is raised. /// 10 - 1 - static virtual TSelf Exp10M1(TSelf x) => TSelf.Exp10M1(x) - TSelf.One; + static virtual TSelf Exp10M1(TSelf x) => TSelf.Exp10(x) - TSelf.One; } } From aa475f50a310cb7c22c8be693a442d04e885615c Mon Sep 17 00:00:00 2001 From: Blokyk Date: Sun, 4 Sep 2022 15:58:25 +0200 Subject: [PATCH 3/5] Add tests for IExponentialFunctions.Exp10M1's DIM --- .../tests/System.Runtime.Tests.csproj | 1 + .../System/Numerics/GenericMathDimHelpers.cs | 79 +++++++++++++++++++ .../Numerics/IExponentialFunctionsTests.cs | 19 +++++ 3 files changed, 99 insertions(+) create mode 100644 src/libraries/System.Runtime/tests/System/Numerics/IExponentialFunctionsTests.cs diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj b/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj index accc11d4277ca8..a5177e128072d8 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj @@ -111,6 +111,7 @@ + diff --git a/src/libraries/System.Runtime/tests/System/Numerics/GenericMathDimHelpers.cs b/src/libraries/System.Runtime/tests/System/Numerics/GenericMathDimHelpers.cs index c072ce36ad29f7..1440a224b5a8f3 100644 --- a/src/libraries/System.Runtime/tests/System/Numerics/GenericMathDimHelpers.cs +++ b/src/libraries/System.Runtime/tests/System/Numerics/GenericMathDimHelpers.cs @@ -96,4 +96,83 @@ private BinaryNumberDimHelper(int value) static bool IComparisonOperators.operator >=(BinaryNumberDimHelper left, BinaryNumberDimHelper right) => throw new NotImplementedException(); } + public struct ExponentialFunctionsDimHelper : IExponentialFunctions + { + public float Value; + + public ExponentialFunctionsDimHelper(float value) + { + Value = value; + } + + + static ExponentialFunctionsDimHelper IExponentialFunctions.Exp10(ExponentialFunctionsDimHelper x) => new ExponentialFunctionsDimHelper(Single.Exp10(x.Value)); + static ExponentialFunctionsDimHelper INumberBase.One => new ExponentialFunctionsDimHelper(1f); + static ExponentialFunctionsDimHelper ISubtractionOperators.operator -(ExponentialFunctionsDimHelper left, ExponentialFunctionsDimHelper right) + => new ExponentialFunctionsDimHelper(left.Value - right.Value); + + // + // The below are all not used for existing Dim tests, so they stay unimplemented + // + + static ExponentialFunctionsDimHelper IFloatingPointConstants.E => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper IFloatingPointConstants.Pi => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper IFloatingPointConstants.Tau => throw new NotImplementedException(); + static int INumberBase.Radix => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper INumberBase.Zero => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper IAdditiveIdentity.AdditiveIdentity => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper IMultiplicativeIdentity.MultiplicativeIdentity => throw new NotImplementedException(); + + static ExponentialFunctionsDimHelper INumberBase.Abs(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper IExponentialFunctions.Exp(ExponentialFunctionsDimHelper x) => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper IExponentialFunctions.Exp2(ExponentialFunctionsDimHelper x) => throw new NotImplementedException(); + static bool INumberBase.IsCanonical(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsComplexNumber(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsEvenInteger(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsFinite(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsImaginaryNumber(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsInfinity(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsInteger(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsNaN(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsNegative(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsNegativeInfinity(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsNormal(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsOddInteger(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsPositive(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsPositiveInfinity(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsRealNumber(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsSubnormal(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsZero(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper INumberBase.MaxMagnitude(ExponentialFunctionsDimHelper x, ExponentialFunctionsDimHelper y) => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper INumberBase.MaxMagnitudeNumber(ExponentialFunctionsDimHelper x, ExponentialFunctionsDimHelper y) => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper INumberBase.MinMagnitude(ExponentialFunctionsDimHelper x, ExponentialFunctionsDimHelper y) => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper INumberBase.MinMagnitudeNumber(ExponentialFunctionsDimHelper x, ExponentialFunctionsDimHelper y) => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper INumberBase.Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper INumberBase.Parse(string s, NumberStyles style, IFormatProvider? provider) => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper ISpanParsable.Parse(ReadOnlySpan s, IFormatProvider? provider) => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper IParsable.Parse(string s, IFormatProvider? provider) => throw new NotImplementedException(); + static bool INumberBase.TryConvertFromChecked(TOther value, out ExponentialFunctionsDimHelper result) => throw new NotImplementedException(); + static bool INumberBase.TryConvertFromSaturating(TOther value, out ExponentialFunctionsDimHelper result) => throw new NotImplementedException(); + static bool INumberBase.TryConvertFromTruncating(TOther value, out ExponentialFunctionsDimHelper result) => throw new NotImplementedException(); + static bool INumberBase.TryConvertToChecked(ExponentialFunctionsDimHelper value, out TOther result) => throw new NotImplementedException(); + static bool INumberBase.TryConvertToSaturating(ExponentialFunctionsDimHelper value, out TOther result) => throw new NotImplementedException(); + static bool INumberBase.TryConvertToTruncating(ExponentialFunctionsDimHelper value, out TOther result) => throw new NotImplementedException(); + static bool INumberBase.TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ExponentialFunctionsDimHelper result) => throw new NotImplementedException(); + static bool INumberBase.TryParse(string? s, NumberStyles style, IFormatProvider? provider, out ExponentialFunctionsDimHelper result) => throw new NotImplementedException(); + static bool ISpanParsable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out ExponentialFunctionsDimHelper result) => throw new NotImplementedException(); + static bool IParsable.TryParse(string? s, IFormatProvider? provider, out ExponentialFunctionsDimHelper result) => throw new NotImplementedException(); + bool IEquatable.Equals(ExponentialFunctionsDimHelper other) => throw new NotImplementedException(); + string IFormattable.ToString(string? format, IFormatProvider? formatProvider) => throw new NotImplementedException(); + bool ISpanFormattable.TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) => throw new NotImplementedException(); + + static ExponentialFunctionsDimHelper IUnaryPlusOperators.operator +(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper IAdditionOperators.operator +(ExponentialFunctionsDimHelper left, ExponentialFunctionsDimHelper right) => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper IUnaryNegationOperators.operator -(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper IIncrementOperators.operator ++(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper IDecrementOperators.operator --(ExponentialFunctionsDimHelper value) => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper IMultiplyOperators.operator *(ExponentialFunctionsDimHelper left, ExponentialFunctionsDimHelper right) => throw new NotImplementedException(); + static ExponentialFunctionsDimHelper IDivisionOperators.operator /(ExponentialFunctionsDimHelper left, ExponentialFunctionsDimHelper right) => throw new NotImplementedException(); + static bool IEqualityOperators.operator ==(ExponentialFunctionsDimHelper left, ExponentialFunctionsDimHelper right) => throw new NotImplementedException(); + static bool IEqualityOperators.operator !=(ExponentialFunctionsDimHelper left, ExponentialFunctionsDimHelper right) => throw new NotImplementedException(); + } } diff --git a/src/libraries/System.Runtime/tests/System/Numerics/IExponentialFunctionsTests.cs b/src/libraries/System.Runtime/tests/System/Numerics/IExponentialFunctionsTests.cs new file mode 100644 index 00000000000000..1312c3cbc77832 --- /dev/null +++ b/src/libraries/System.Runtime/tests/System/Numerics/IExponentialFunctionsTests.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Xunit; + +namespace System.Numerics.Tests +{ + public sealed class IExponentialFunctionsTests + { + const float baseValue = 2.1f; + static readonly ExponentialFunctionsDimHelper helperValue = new ExponentialFunctionsDimHelper(baseValue); + + [Fact] + public static void Exp10M1Test() + { + Assert.Equal(Single.Exp10M1(baseValue), ExponentialFunctionsHelper.Exp10M1(helperValue).Value); + } + } +} From 38b2d2e2113fddeb79497bbe26e6d5f24228b6bd Mon Sep 17 00:00:00 2001 From: Blokyk Date: Sun, 4 Sep 2022 16:00:51 +0200 Subject: [PATCH 4/5] Add tests for IFloatingPoint.Round's DIM --- .../tests/System.Runtime.Tests.csproj | 1 + .../System/Numerics/GenericMathDimHelpers.cs | 94 +++++++++++++++++++ .../System/Numerics/IFloatingPointTests.cs | 43 +++++++++ 3 files changed, 138 insertions(+) create mode 100644 src/libraries/System.Runtime/tests/System/Numerics/IFloatingPointTests.cs diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj b/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj index a5177e128072d8..fc6859854dc2e6 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj @@ -112,6 +112,7 @@ + diff --git a/src/libraries/System.Runtime/tests/System/Numerics/GenericMathDimHelpers.cs b/src/libraries/System.Runtime/tests/System/Numerics/GenericMathDimHelpers.cs index 1440a224b5a8f3..c8481e73e1672a 100644 --- a/src/libraries/System.Runtime/tests/System/Numerics/GenericMathDimHelpers.cs +++ b/src/libraries/System.Runtime/tests/System/Numerics/GenericMathDimHelpers.cs @@ -96,6 +96,100 @@ private BinaryNumberDimHelper(int value) static bool IComparisonOperators.operator >=(BinaryNumberDimHelper left, BinaryNumberDimHelper right) => throw new NotImplementedException(); } + public struct FloatingPointDimHelper : IFloatingPoint + { + public float Value; + + public FloatingPointDimHelper(float value) + { + Value = value; + } + + static FloatingPointDimHelper IFloatingPoint.Round(FloatingPointDimHelper x, int digits, MidpointRounding mode) + => new FloatingPointDimHelper(Single.Round(x.Value, digits, mode)); + + // + // The below are all not used for existing Dim tests, so they stay unimplemented + // + + static FloatingPointDimHelper IFloatingPointConstants.E => throw new NotImplementedException(); + static FloatingPointDimHelper IFloatingPointConstants.Pi => throw new NotImplementedException(); + static FloatingPointDimHelper IFloatingPointConstants.Tau => throw new NotImplementedException(); + static FloatingPointDimHelper ISignedNumber.NegativeOne => throw new NotImplementedException(); + static FloatingPointDimHelper INumberBase.One => throw new NotImplementedException(); + static int INumberBase.Radix => throw new NotImplementedException(); + static FloatingPointDimHelper INumberBase.Zero => throw new NotImplementedException(); + static FloatingPointDimHelper IAdditiveIdentity.AdditiveIdentity => throw new NotImplementedException(); + static FloatingPointDimHelper IMultiplicativeIdentity.MultiplicativeIdentity => throw new NotImplementedException(); + + static FloatingPointDimHelper INumberBase.Abs(FloatingPointDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsCanonical(FloatingPointDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsComplexNumber(FloatingPointDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsEvenInteger(FloatingPointDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsFinite(FloatingPointDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsImaginaryNumber(FloatingPointDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsInfinity(FloatingPointDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsInteger(FloatingPointDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsNaN(FloatingPointDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsNegative(FloatingPointDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsNegativeInfinity(FloatingPointDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsNormal(FloatingPointDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsOddInteger(FloatingPointDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsPositive(FloatingPointDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsPositiveInfinity(FloatingPointDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsRealNumber(FloatingPointDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsSubnormal(FloatingPointDimHelper value) => throw new NotImplementedException(); + static bool INumberBase.IsZero(FloatingPointDimHelper value) => throw new NotImplementedException(); + static FloatingPointDimHelper INumberBase.MaxMagnitude(FloatingPointDimHelper x, FloatingPointDimHelper y) => throw new NotImplementedException(); + static FloatingPointDimHelper INumberBase.MaxMagnitudeNumber(FloatingPointDimHelper x, FloatingPointDimHelper y) => throw new NotImplementedException(); + static FloatingPointDimHelper INumberBase.MinMagnitude(FloatingPointDimHelper x, FloatingPointDimHelper y) => throw new NotImplementedException(); + static FloatingPointDimHelper INumberBase.MinMagnitudeNumber(FloatingPointDimHelper x, FloatingPointDimHelper y) => throw new NotImplementedException(); + static FloatingPointDimHelper INumberBase.Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) => throw new NotImplementedException(); + static FloatingPointDimHelper INumberBase.Parse(string s, NumberStyles style, IFormatProvider? provider) => throw new NotImplementedException(); + static FloatingPointDimHelper ISpanParsable.Parse(ReadOnlySpan s, IFormatProvider? provider) => throw new NotImplementedException(); + static FloatingPointDimHelper IParsable.Parse(string s, IFormatProvider? provider) => throw new NotImplementedException(); + + static bool INumberBase.TryConvertFromChecked(TOther value, out FloatingPointDimHelper result) => throw new NotImplementedException(); + static bool INumberBase.TryConvertFromSaturating(TOther value, out FloatingPointDimHelper result) => throw new NotImplementedException(); + static bool INumberBase.TryConvertFromTruncating(TOther value, out FloatingPointDimHelper result) => throw new NotImplementedException(); + static bool INumberBase.TryConvertToChecked(FloatingPointDimHelper value, out TOther result) => throw new NotImplementedException(); + static bool INumberBase.TryConvertToSaturating(FloatingPointDimHelper value, out TOther result) => throw new NotImplementedException(); + static bool INumberBase.TryConvertToTruncating(FloatingPointDimHelper value, out TOther result) => throw new NotImplementedException(); + static bool INumberBase.TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out FloatingPointDimHelper result) => throw new NotImplementedException(); + static bool INumberBase.TryParse(string? s, NumberStyles style, IFormatProvider? provider, out FloatingPointDimHelper result) => throw new NotImplementedException(); + static bool ISpanParsable.TryParse(ReadOnlySpan s, IFormatProvider? provider, out FloatingPointDimHelper result) => throw new NotImplementedException(); + static bool IParsable.TryParse(string? s, IFormatProvider? provider, out FloatingPointDimHelper result) => throw new NotImplementedException(); + int IComparable.CompareTo(object? obj) => throw new NotImplementedException(); + int IComparable.CompareTo(FloatingPointDimHelper other) => throw new NotImplementedException(); + bool IEquatable.Equals(FloatingPointDimHelper other) => throw new NotImplementedException(); + int IFloatingPoint.GetExponentByteCount() => throw new NotImplementedException(); + int IFloatingPoint.GetExponentShortestBitLength() => throw new NotImplementedException(); + int IFloatingPoint.GetSignificandBitLength() => throw new NotImplementedException(); + int IFloatingPoint.GetSignificandByteCount() => throw new NotImplementedException(); + string IFormattable.ToString(string? format, IFormatProvider? formatProvider) => throw new NotImplementedException(); + bool ISpanFormattable.TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) => throw new NotImplementedException(); + bool IFloatingPoint.TryWriteExponentBigEndian(Span destination, out int bytesWritten) => throw new NotImplementedException(); + bool IFloatingPoint.TryWriteExponentLittleEndian(Span destination, out int bytesWritten) => throw new NotImplementedException(); + bool IFloatingPoint.TryWriteSignificandBigEndian(Span destination, out int bytesWritten) => throw new NotImplementedException(); + bool IFloatingPoint.TryWriteSignificandLittleEndian(Span destination, out int bytesWritten) => throw new NotImplementedException(); + + static FloatingPointDimHelper IUnaryPlusOperators.operator +(FloatingPointDimHelper value) => throw new NotImplementedException(); + static FloatingPointDimHelper IAdditionOperators.operator +(FloatingPointDimHelper left, FloatingPointDimHelper right) => throw new NotImplementedException(); + static FloatingPointDimHelper IUnaryNegationOperators.operator -(FloatingPointDimHelper value) => throw new NotImplementedException(); + static FloatingPointDimHelper ISubtractionOperators.operator -(FloatingPointDimHelper left, FloatingPointDimHelper right) => throw new NotImplementedException(); + static FloatingPointDimHelper IIncrementOperators.operator ++(FloatingPointDimHelper value) => throw new NotImplementedException(); + static FloatingPointDimHelper IDecrementOperators.operator --(FloatingPointDimHelper value) => throw new NotImplementedException(); + static FloatingPointDimHelper IMultiplyOperators.operator *(FloatingPointDimHelper left, FloatingPointDimHelper right) => throw new NotImplementedException(); + static FloatingPointDimHelper IDivisionOperators.operator /(FloatingPointDimHelper left, FloatingPointDimHelper right) => throw new NotImplementedException(); + static FloatingPointDimHelper IModulusOperators.operator %(FloatingPointDimHelper left, FloatingPointDimHelper right) => throw new NotImplementedException(); + static bool IEqualityOperators.operator ==(FloatingPointDimHelper left, FloatingPointDimHelper right) => throw new NotImplementedException(); + static bool IEqualityOperators.operator !=(FloatingPointDimHelper left, FloatingPointDimHelper right) => throw new NotImplementedException(); + static bool IComparisonOperators.operator <(FloatingPointDimHelper left, FloatingPointDimHelper right) => throw new NotImplementedException(); + static bool IComparisonOperators.operator >(FloatingPointDimHelper left, FloatingPointDimHelper right) => throw new NotImplementedException(); + static bool IComparisonOperators.operator <=(FloatingPointDimHelper left, FloatingPointDimHelper right) => throw new NotImplementedException(); + static bool IComparisonOperators.operator >=(FloatingPointDimHelper left, FloatingPointDimHelper right) => throw new NotImplementedException(); + } + public struct ExponentialFunctionsDimHelper : IExponentialFunctions { public float Value; diff --git a/src/libraries/System.Runtime/tests/System/Numerics/IFloatingPointTests.cs b/src/libraries/System.Runtime/tests/System/Numerics/IFloatingPointTests.cs new file mode 100644 index 00000000000000..2e0669f86646cb --- /dev/null +++ b/src/libraries/System.Runtime/tests/System/Numerics/IFloatingPointTests.cs @@ -0,0 +1,43 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Xunit; + +namespace System.Numerics.Tests +{ + public sealed class IFloatingPointTests + { + const float baseValue = 5.5f; + static readonly FloatingPointDimHelper helperValue = new FloatingPointDimHelper(baseValue); + + [Fact] + public static void AwayFromZeroRoundingTest() + { + Assert.Equal(Single.Round(baseValue, MidpointRounding.AwayFromZero), FloatingPointHelper.Round(helperValue, MidpointRounding.AwayFromZero).Value); + } + + [Fact] + public static void ToEvenRoundingTest() + { + Assert.Equal(Single.Round(baseValue, MidpointRounding.ToEven), FloatingPointHelper.Round(helperValue, MidpointRounding.ToEven).Value); + } + + [Fact] + public static void ToNegativeInfinityRoundingTest() + { + Assert.Equal(Single.Round(baseValue, MidpointRounding.ToNegativeInfinity), FloatingPointHelper.Round(helperValue, MidpointRounding.ToNegativeInfinity).Value); + } + + [Fact] + public static void ToPositiveRoundingTest() + { + Assert.Equal(Single.Round(baseValue, MidpointRounding.ToPositiveInfinity), FloatingPointHelper.Round(helperValue, MidpointRounding.ToPositiveInfinity).Value); + } + + [Fact] + public static void ToZeroRoundingTest() + { + Assert.Equal(Single.Round(baseValue, MidpointRounding.ToZero), FloatingPointHelper.Round(helperValue, MidpointRounding.ToZero).Value); + } + } +} From 764dd65fbe3710c8e40cdd60c3163c26c316a257 Mon Sep 17 00:00:00 2001 From: blokyk Date: Tue, 6 Sep 2022 22:38:25 +0200 Subject: [PATCH 5/5] fix nits from tannergooding --- .../tests/System/Numerics/GenericMathDimHelpers.cs | 5 ++--- .../System/Numerics/IExponentialFunctionsTests.cs | 2 +- .../tests/System/Numerics/IFloatingPointTests.cs | 10 +++++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System/Numerics/GenericMathDimHelpers.cs b/src/libraries/System.Runtime/tests/System/Numerics/GenericMathDimHelpers.cs index c8481e73e1672a..058bba1d255b5c 100644 --- a/src/libraries/System.Runtime/tests/System/Numerics/GenericMathDimHelpers.cs +++ b/src/libraries/System.Runtime/tests/System/Numerics/GenericMathDimHelpers.cs @@ -106,7 +106,7 @@ public FloatingPointDimHelper(float value) } static FloatingPointDimHelper IFloatingPoint.Round(FloatingPointDimHelper x, int digits, MidpointRounding mode) - => new FloatingPointDimHelper(Single.Round(x.Value, digits, mode)); + => new FloatingPointDimHelper(float.Round(x.Value, digits, mode)); // // The below are all not used for existing Dim tests, so they stay unimplemented @@ -199,8 +199,7 @@ public ExponentialFunctionsDimHelper(float value) Value = value; } - - static ExponentialFunctionsDimHelper IExponentialFunctions.Exp10(ExponentialFunctionsDimHelper x) => new ExponentialFunctionsDimHelper(Single.Exp10(x.Value)); + static ExponentialFunctionsDimHelper IExponentialFunctions.Exp10(ExponentialFunctionsDimHelper x) => new ExponentialFunctionsDimHelper(float.Exp10(x.Value)); static ExponentialFunctionsDimHelper INumberBase.One => new ExponentialFunctionsDimHelper(1f); static ExponentialFunctionsDimHelper ISubtractionOperators.operator -(ExponentialFunctionsDimHelper left, ExponentialFunctionsDimHelper right) => new ExponentialFunctionsDimHelper(left.Value - right.Value); diff --git a/src/libraries/System.Runtime/tests/System/Numerics/IExponentialFunctionsTests.cs b/src/libraries/System.Runtime/tests/System/Numerics/IExponentialFunctionsTests.cs index 1312c3cbc77832..6c2096cf88d77c 100644 --- a/src/libraries/System.Runtime/tests/System/Numerics/IExponentialFunctionsTests.cs +++ b/src/libraries/System.Runtime/tests/System/Numerics/IExponentialFunctionsTests.cs @@ -13,7 +13,7 @@ public sealed class IExponentialFunctionsTests [Fact] public static void Exp10M1Test() { - Assert.Equal(Single.Exp10M1(baseValue), ExponentialFunctionsHelper.Exp10M1(helperValue).Value); + Assert.Equal(float.Exp10M1(baseValue), ExponentialFunctionsHelper.Exp10M1(helperValue).Value); } } } diff --git a/src/libraries/System.Runtime/tests/System/Numerics/IFloatingPointTests.cs b/src/libraries/System.Runtime/tests/System/Numerics/IFloatingPointTests.cs index 2e0669f86646cb..6085d5b29d0e5a 100644 --- a/src/libraries/System.Runtime/tests/System/Numerics/IFloatingPointTests.cs +++ b/src/libraries/System.Runtime/tests/System/Numerics/IFloatingPointTests.cs @@ -13,31 +13,31 @@ public sealed class IFloatingPointTests [Fact] public static void AwayFromZeroRoundingTest() { - Assert.Equal(Single.Round(baseValue, MidpointRounding.AwayFromZero), FloatingPointHelper.Round(helperValue, MidpointRounding.AwayFromZero).Value); + Assert.Equal(float.Round(baseValue, MidpointRounding.AwayFromZero), FloatingPointHelper.Round(helperValue, MidpointRounding.AwayFromZero).Value); } [Fact] public static void ToEvenRoundingTest() { - Assert.Equal(Single.Round(baseValue, MidpointRounding.ToEven), FloatingPointHelper.Round(helperValue, MidpointRounding.ToEven).Value); + Assert.Equal(float.Round(baseValue, MidpointRounding.ToEven), FloatingPointHelper.Round(helperValue, MidpointRounding.ToEven).Value); } [Fact] public static void ToNegativeInfinityRoundingTest() { - Assert.Equal(Single.Round(baseValue, MidpointRounding.ToNegativeInfinity), FloatingPointHelper.Round(helperValue, MidpointRounding.ToNegativeInfinity).Value); + Assert.Equal(float.Round(baseValue, MidpointRounding.ToNegativeInfinity), FloatingPointHelper.Round(helperValue, MidpointRounding.ToNegativeInfinity).Value); } [Fact] public static void ToPositiveRoundingTest() { - Assert.Equal(Single.Round(baseValue, MidpointRounding.ToPositiveInfinity), FloatingPointHelper.Round(helperValue, MidpointRounding.ToPositiveInfinity).Value); + Assert.Equal(float.Round(baseValue, MidpointRounding.ToPositiveInfinity), FloatingPointHelper.Round(helperValue, MidpointRounding.ToPositiveInfinity).Value); } [Fact] public static void ToZeroRoundingTest() { - Assert.Equal(Single.Round(baseValue, MidpointRounding.ToZero), FloatingPointHelper.Round(helperValue, MidpointRounding.ToZero).Value); + Assert.Equal(float.Round(baseValue, MidpointRounding.ToZero), FloatingPointHelper.Round(helperValue, MidpointRounding.ToZero).Value); } } }