Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit ec87e62

Browse files
authored
Merge pull request #12183 from tannergooding/math
Updating the 'System.Runtime.Extensions' contracts to include the new single-precision Math APIs.
2 parents f5b67a2 + f7d1819 commit ec87e62

10 files changed

+474
-1
lines changed

pkg/descriptions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,7 @@
12511251
"Description": "Provides commonly-used classes for performing mathematical functions, conversions, string comparisons and querying environment information.",
12521252
"CommonTypes": [
12531253
"System.Math",
1254+
"System.MathF",
12541255
"System.Environment",
12551256
"System.Random",
12561257
"System.Progress<T>",

src/System.Runtime.Extensions/ref/System.Runtime.Extensions.Manual.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@ public static partial class Math
1414
public const double PI = 3.14159265358979323846;
1515
public const double E = 2.7182818284590452354;
1616
}
17+
#if netcoreapp11
18+
public static partial class MathF
19+
{
20+
public const float PI = 3.14159265f;
21+
public const float E = 2.71828183f;
22+
}
23+
#endif
1724
}

src/System.Runtime.Extensions/ref/System.Runtime.Extensions.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,13 @@ public static partial class BitConverter
134134
public static byte[] GetBytes(uint value) { throw null; }
135135
[System.CLSCompliantAttribute(false)]
136136
public static byte[] GetBytes(ulong value) { throw null; }
137+
#if netcoreapp11
138+
public static float Int32BitsToSingle(int value) { throw null; }
139+
#endif
137140
public static double Int64BitsToDouble(long value) { throw null; }
141+
#if netcoreapp11
142+
public static int SingleToInt32Bits(float value) { throw null; }
143+
#endif
138144
public static bool ToBoolean(byte[] value, int startIndex) { throw null; }
139145
public static char ToChar(byte[] value, int startIndex) { throw null; }
140146
public static double ToDouble(byte[] value, int startIndex) { throw null; }
@@ -790,6 +796,39 @@ public static partial class Math
790796
public static decimal Truncate(decimal d) { throw null; }
791797
public static double Truncate(double d) { throw null; }
792798
}
799+
#if netcoreapp11
800+
public static partial class MathF
801+
{
802+
public static float Abs(float x) { throw null; }
803+
public static float Acos(float x) { throw null; }
804+
public static float Asin(float x) { throw null; }
805+
public static float Atan(float x) { throw null; }
806+
public static float Atan2(float y, float x) { throw null; }
807+
public static float Ceiling(float x) { throw null; }
808+
public static float Cos(float x) { throw null; }
809+
public static float Cosh(float x) { throw null; }
810+
public static float Exp(float x) { throw null; }
811+
public static float Floor(float x) { throw null; }
812+
public static float IEEERemainder(float x, float y) { throw null; }
813+
public static float Log(float x) { throw null; }
814+
public static float Log(float x, float y) { throw null; }
815+
public static float Log10(float x) { throw null; }
816+
public static float Max(float x, float y) { throw null; }
817+
public static float Min(float x, float y) { throw null; }
818+
public static float Pow(float x, float y) { throw null; }
819+
public static float Round(float x) { throw null; }
820+
public static float Round(float x, int digits) { throw null; }
821+
public static float Round(float x, int digits, System.MidpointRounding mode) { throw null; }
822+
public static float Round(float x, System.MidpointRounding mode) { throw null; }
823+
public static int Sign(float x) { return default(int); }
824+
public static float Sin(float x) { throw null; }
825+
public static float Sinh(float x) { throw null; }
826+
public static float Sqrt(float x) { throw null; }
827+
public static float Tan(float x) { throw null; }
828+
public static float Tanh(float x) { throw null; }
829+
public static float Truncate(float x) { throw null; }
830+
}
831+
#endif
793832
public sealed class OperatingSystem : System.ICloneable, System.Runtime.Serialization.ISerializable
794833
{
795834
private OperatingSystem() { }

src/System.Runtime.Extensions/src/System.Runtime.Extensions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<Compile Include="System\Environment.SpecialFolder.cs" />
4646
<Compile Include="System\Environment.SpecialFolderOption.cs" />
4747
<Compile Include="System\EnvironmentVariableTarget.cs" />
48+
<Compile Include="System\MathF.cs" /> <!-- https://github.com/dotnet/buildtools/issues/1041 -->
4849
<Compile Include="System\OperatingSystem.cs" />
4950
<Compile Include="System\PlatformID.cs" />
5051
<Compile Include="System\IO\Path.cs" />

src/System.Runtime.Extensions/src/System/BitConverter.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,18 @@ public static unsafe double Int64BitsToDouble(long value)
453453
return *((double*)&value);
454454
}
455455

456+
[SecuritySafeCritical]
457+
public static unsafe int SingleToInt32Bits(float value)
458+
{
459+
return *((int*)&value);
460+
}
461+
462+
[SecuritySafeCritical]
463+
public static unsafe float Int32BitsToSingle(int value)
464+
{
465+
return *((float*)&value);
466+
}
467+
456468
private static void ThrowValueArgumentNull()
457469
{
458470
throw new ArgumentNullException("value");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Runtime.CompilerServices;
7+
8+
// We normally shouldn't have to manually specify the
9+
// TypeForwardedToAttribute. The following bug is tracking
10+
// this: https://github.com/dotnet/buildtools/issues/1041
11+
[assembly: TypeForwardedTo(typeof(MathF))]

src/System.Runtime.Extensions/tests/System.Runtime.Extensions.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@
4848
</Compile>
4949
</ItemGroup>
5050
<ItemGroup Condition="'$(TargetGroup)'=='netcoreapp1.1'">
51+
<Compile Include="System\BitConverter.netcoreapp1.1.cs" />
5152
<Compile Include="System\IO\Path.GetRelativePath.cs" />
5253
<Compile Include="System\MathTests.netcoreapp1.1.cs" />
54+
<Compile Include="System\MathF.netcoreapp1.1.cs" />
5355
</ItemGroup>
5456
<ItemGroup>
5557
<Compile Include="System\Diagnostics\Stopwatch.cs" />

src/System.Runtime.Extensions/tests/System/BitConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace System.Tests
1010
{
11-
public static class BitConverterTests
11+
public static partial class BitConverterTests
1212
{
1313
[Fact]
1414
public static unsafe void IsLittleEndian()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Xunit;
6+
7+
namespace System.Tests
8+
{
9+
public static partial class BitConverterTests
10+
{
11+
[Fact]
12+
public static void SingleToInt32Bits()
13+
{
14+
Single input = 12345.63f;
15+
Int32 result = BitConverter.SingleToInt32Bits(input);
16+
Assert.Equal(1178658437, result);
17+
Single roundtripped = BitConverter.Int32BitsToSingle(result);
18+
Assert.Equal(input, roundtripped);
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)