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; } } 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. diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj b/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj index accc11d4277ca8..fc6859854dc2e6 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj @@ -111,6 +111,8 @@ + + diff --git a/src/libraries/System.Runtime/tests/System/Numerics/GenericMathDimHelpers.cs b/src/libraries/System.Runtime/tests/System/Numerics/GenericMathDimHelpers.cs index c072ce36ad29f7..058bba1d255b5c 100644 --- a/src/libraries/System.Runtime/tests/System/Numerics/GenericMathDimHelpers.cs +++ b/src/libraries/System.Runtime/tests/System/Numerics/GenericMathDimHelpers.cs @@ -96,4 +96,176 @@ 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(float.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; + + public ExponentialFunctionsDimHelper(float value) + { + Value = 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); + + // + // 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..6c2096cf88d77c --- /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(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 new file mode 100644 index 00000000000000..6085d5b29d0e5a --- /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(float.Round(baseValue, MidpointRounding.AwayFromZero), FloatingPointHelper.Round(helperValue, MidpointRounding.AwayFromZero).Value); + } + + [Fact] + public static void ToEvenRoundingTest() + { + Assert.Equal(float.Round(baseValue, MidpointRounding.ToEven), FloatingPointHelper.Round(helperValue, MidpointRounding.ToEven).Value); + } + + [Fact] + public static void ToNegativeInfinityRoundingTest() + { + Assert.Equal(float.Round(baseValue, MidpointRounding.ToNegativeInfinity), FloatingPointHelper.Round(helperValue, MidpointRounding.ToNegativeInfinity).Value); + } + + [Fact] + public static void ToPositiveRoundingTest() + { + Assert.Equal(float.Round(baseValue, MidpointRounding.ToPositiveInfinity), FloatingPointHelper.Round(helperValue, MidpointRounding.ToPositiveInfinity).Value); + } + + [Fact] + public static void ToZeroRoundingTest() + { + Assert.Equal(float.Round(baseValue, MidpointRounding.ToZero), FloatingPointHelper.Round(helperValue, MidpointRounding.ToZero).Value); + } + } +}