diff --git a/src/libraries/System.Private.CoreLib/src/System/Math.cs b/src/libraries/System.Private.CoreLib/src/System/Math.cs index 2b0ca9e0f279b..34b62546c0034 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Math.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Math.cs @@ -29,6 +29,8 @@ public static partial class Math public const double PI = 3.14159265358979323846; + public const double Tau = 6.283185307179586476925; + private const int maxRoundingDigits = 15; private const double doubleRoundLimit = 1e16d; diff --git a/src/libraries/System.Private.CoreLib/src/System/MathF.cs b/src/libraries/System.Private.CoreLib/src/System/MathF.cs index 5d7de83959039..5c1a61468b089 100644 --- a/src/libraries/System.Private.CoreLib/src/System/MathF.cs +++ b/src/libraries/System.Private.CoreLib/src/System/MathF.cs @@ -23,6 +23,8 @@ public static partial class MathF public const float PI = 3.14159265f; + public const float Tau = 6.283185307f; + private const int maxRoundingDigits = 6; // This table is required for the Round function which can specify the number of digits to round to diff --git a/src/libraries/System.Runtime.Extensions/tests/System/Math.cs b/src/libraries/System.Runtime.Extensions/tests/System/Math.cs index c2b43c8d8ec4d..c94799fc8b7ba 100644 --- a/src/libraries/System.Runtime.Extensions/tests/System/Math.cs +++ b/src/libraries/System.Runtime.Extensions/tests/System/Math.cs @@ -153,6 +153,24 @@ private static void AssertEqual(double expected, double actual, double variance) } } + [Fact] + public static void E() + { + Assert.Equal(unchecked((long)0x4005BF0A8B145769), BitConverter.DoubleToInt64Bits(Math.E)); + } + + [Fact] + public static void Pi() + { + Assert.Equal(unchecked((long)0x400921FB54442D18), BitConverter.DoubleToInt64Bits(Math.PI)); + } + + [Fact] + public static void Tau() + { + Assert.Equal(unchecked((long)0x401921FB54442D18), BitConverter.DoubleToInt64Bits(Math.Tau)); + } + /// Verifies that two values are equal, within the . /// The expected value /// The value to be compared against diff --git a/src/libraries/System.Runtime.Extensions/tests/System/MathF.cs b/src/libraries/System.Runtime.Extensions/tests/System/MathF.cs index 76b72cad8cf7d..4588569fcea7e 100644 --- a/src/libraries/System.Runtime.Extensions/tests/System/MathF.cs +++ b/src/libraries/System.Runtime.Extensions/tests/System/MathF.cs @@ -179,6 +179,24 @@ private static string ToStringPadded(float value) } } + [Fact] + public static void E() + { + Assert.Equal(0x402DF854, BitConverter.SingleToInt32Bits(MathF.E)); + } + + [Fact] + public static void Pi() + { + Assert.Equal(0x40490FDB, BitConverter.SingleToInt32Bits(MathF.PI)); + } + + [Fact] + public static void Tau() + { + Assert.Equal(0x40C90FDB, BitConverter.SingleToInt32Bits(MathF.Tau)); + } + [Theory] [InlineData( float.NegativeInfinity, float.PositiveInfinity, 0.0f)] [InlineData(-3.14159265f, 3.14159265f, CrossPlatformMachineEpsilon * 10)] // value: -(pi) expected: (pi) diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index 4c39802764aae..90be5589d8bc4 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -2532,6 +2532,7 @@ public static partial class Math { public const double E = 2.718281828459045; public const double PI = 3.141592653589793; + public const double Tau = 6.283185307179586; public static decimal Abs(decimal value) { throw null; } public static double Abs(double value) { throw null; } public static short Abs(short value) { throw null; } @@ -2648,6 +2649,7 @@ public static partial class MathF { public const float E = 2.7182817f; public const float PI = 3.1415927f; + public const float Tau = 6.2831855f; public static float Abs(float x) { throw null; } public static float Acos(float x) { throw null; } public static float Acosh(float x) { throw null; }