Skip to content

Commit

Permalink
Add Math.Tau, MathF.Tau (#37517)
Browse files Browse the repository at this point in the history
* Add Math.Tau, MathF.Tau

* Remove unncessary 'checked' and wrong val
  • Loading branch information
john-h-k authored Jun 7, 2020
1 parent e8964cc commit 16e7c69
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/Math.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/MathF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/libraries/System.Runtime.Extensions/tests/System/Math.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/// <summary>Verifies that two <see cref="float"/> values are equal, within the <paramref name="variance"/>.</summary>
/// <param name="expected">The expected value</param>
/// <param name="actual">The value to be compared against</param>
Expand Down
18 changes: 18 additions & 0 deletions src/libraries/System.Runtime.Extensions/tests/System/MathF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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; }
Expand Down

0 comments on commit 16e7c69

Please sign in to comment.