Skip to content

Commit 825bd7e

Browse files
authored
Work extracting System.Math (#51)
1 parent 74a8b2d commit 825bd7e

File tree

5 files changed

+22
-127
lines changed

5 files changed

+22
-127
lines changed

source/nanoFramework.CoreLibrary/CoreLibrary.nfproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
</PropertyGroup>
4646
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
4747
<ItemGroup>
48+
<Compile Include="Friends.cs" />
4849
<Compile Include="System\AppDomain.cs" />
4950
<Compile Include="System\AppDomainUnloadedException.cs" />
5051
<Compile Include="System\ApplicationException.cs" />
@@ -379,4 +380,4 @@
379380
<ProjectConfigurationsDeclaredAsItems />
380381
</ProjectCapabilities>
381382
</ProjectExtensions>
382-
</Project>
383+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// Copyright (c) 2017 The nanoFramework project contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
using System.Runtime.CompilerServices;
7+
8+
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("System.Math, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")]

source/nanoFramework.CoreLibrary/System/Math.cs

Lines changed: 4 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -8,129 +8,15 @@ namespace System
88
{
99
using Runtime.CompilerServices;
1010

11-
/// <summary>
12-
/// Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions.
13-
/// </summary>
14-
/// <remarks>
15-
/// Specific for nanoFramework: this class library is split between mscorlib and it's own assembly.
16-
/// If you require any of the other methods that are not available here add the NuGet package nanoFramework.System.Math.
17-
/// </remarks>
18-
public static partial class Math
11+
internal static class MathInternal
1912
{
20-
/// <summary>
21-
/// Represents the ratio of the circumference of a circle to its diameter, specified by the constant, π.
22-
/// </summary>
23-
/// <remarks>The value of this field is 3.14159265358979323846.</remarks>
24-
public const double PI = 3.14159265358979323846;
25-
/// <summary>
26-
/// Represents the natural logarithmic base, specified by the constant, e.
27-
/// </summary>
28-
/// <remarks>The value of this field is 2.7182818284590452354.</remarks>
29-
public const double E = 2.7182818284590452354;
30-
31-
/// <summary>
32-
/// Returns the absolute value of a 32-bit signed integer.
33-
/// </summary>
34-
/// <param name="val">A number that is greater than Int32..::..MinValue, but less than or equal to Int32..::..MaxValue.</param>
35-
/// <returns>A 32-bit signed integer, x, such that 0 ≤ x ≤ Int32..::..MaxValue.</returns>
36-
[MethodImpl(MethodImplOptions.InternalCall)]
37-
public static extern int Abs(int val);
38-
39-
/// <summary>
40-
/// Returns the absolute value of a double-precision floating-point number.
41-
/// </summary>
42-
/// <param name="val">A number that is greater than or equal to Double..::..MinValue, but less than or equal to Double..::..MaxValue.</param>
43-
/// <returns>A double-precision floating-point number, x, such that 0 ≤ x ≤ Double..::..MaxValue.</returns>
44-
/// <remarks>
45-
/// This method with double-precision floating-point parameter might not be available in all platforms or with firmware images that where build with single point FPU option.
46-
/// </remarks>
47-
/// <exception cref="NotImplementedException"/>
48-
[MethodImpl(MethodImplOptions.InternalCall)]
49-
public static extern double Abs(double val);
50-
51-
/// <summary>
52-
/// Returns the absolute value of a single-precision floating-point number.
53-
/// </summary>
54-
/// <param name="val">A number that is greater than or equal to Double..::..MinValue, but less than or equal to Double..::..MaxValue.</param>
55-
/// <returns>A single-precision floating-point number, x, such that 0 ≤ x ≤ Double..::..MaxValue.</returns>
56-
/// <remarks>
57-
/// This method with single-precision floating-point parameter is exclusive of nanoFramework. It doesn't exist in the .NET API, only the double-precision floating-point version.
58-
/// It might not be available in all platforms or with firmware images that where build with double point FPU option.
59-
/// </remarks>
60-
/// <exception cref="NotImplementedException"/>
61-
[MethodImpl(MethodImplOptions.InternalCall)]
62-
public static extern float Abs(float val);
63-
64-
/// <summary>
65-
/// Returns the larger of two 32-bit signed integers.
66-
/// </summary>
67-
/// <param name="val1">The first of two 32-bit signed integers to compare. </param>
68-
/// <param name="val2">The second of two 32-bit signed integers to compare. </param>
69-
/// <returns>Parameter val1 or val2, whichever is larger.</returns>
70-
[MethodImpl(MethodImplOptions.InternalCall)]
71-
public static extern int Max(int val1, int val2);
72-
73-
/// <summary>
74-
/// Returns the larger of two double-precision floating-point numbers.
75-
/// </summary>
76-
/// <param name="x">The first of two double-precision floating-point numbers to compare. </param>
77-
/// <param name="y">The second of two double-precision floating-point numbers to compare. </param>
78-
/// <returns>Parameter x or y, whichever is larger. If x, y, or both x and y are equal to NaN, NaN is returned.</returns>
79-
/// <remarks>
80-
/// This method with double-precision floating-point parameter might not be available in all platforms or with firmware images that where build with single point FPU option.
81-
/// </remarks>
82-
/// <exception cref="NotImplementedException"/>
8313
[MethodImpl(MethodImplOptions.InternalCall)]
84-
public static extern double Max(double x, double y);
85-
86-
/// <summary>
87-
/// Returns the larger of two single-precision floating-point numbers.
88-
/// </summary>
89-
/// <param name="x">The first of two single-precision floating-point numbers to compare. </param>
90-
/// <param name="y">The second of two single-precision floating-point numbers to compare. </param>
91-
/// <returns>Parameter x or y, whichever is larger. If x, y, or both x and y are equal to NaN, NaN is returned.</returns>
92-
/// <remarks>
93-
/// This method with single-precision floating-point parameter is exclusive of nanoFramework. It doesn't exist in the .NET API, only the double-precision floating-point version.
94-
/// It might not be available in all platforms or with firmware images that where build with double point FPU option.
95-
/// </remarks>
96-
/// <exception cref="NotImplementedException"/>
97-
[MethodImpl(MethodImplOptions.InternalCall)]
98-
public static extern float Max(float x, float y);
14+
internal static extern int Abs(int val);
9915

100-
/// <summary>
101-
/// Returns the smaller of two 32-bit signed integers.
102-
/// </summary>
103-
/// <param name="val1">The first of two 32-bit signed integers to compare. </param>
104-
/// <param name="val2">The second of two 32-bit signed integers to compare. </param>
105-
/// <returns>Parameter val1 or val2, whichever is smaller.</returns>
10616
[MethodImpl(MethodImplOptions.InternalCall)]
107-
public static extern int Min(int val1, int val2);
17+
internal static extern int Min(int val1, int val2);
10818

109-
/// <summary>
110-
/// Returns the smaller of two double-precision floating-point numbers.
111-
/// </summary>
112-
/// <param name="x">The first of two double-precision floating-point numbers to compare. </param>
113-
/// <param name="y">The second of two double-precision floating-point numbers to compare. </param>
114-
/// <returns>Parameter x or y, whichever is smaller. If x, y, or both x and y are equal to NaN, NaN is returned.</returns>
115-
/// <remarks>
116-
/// This method with double-precision floating-point parameter might not be available in all platforms or with firmware images that where build with single point FPU option.
117-
/// </remarks>
118-
/// <exception cref="NotImplementedException"/>
119-
[MethodImpl(MethodImplOptions.InternalCall)]
120-
public static extern double Min(double x, double y);
121-
/// <summary>
122-
/// Returns the smaller of two single-precision floating-point numbers.
123-
/// </summary>
124-
/// <param name="x">The first of two single-precision floating-point numbers to compare. </param>
125-
/// <param name="y">The second of two single-precision floating-point numbers to compare. </param>
126-
/// <returns>Parameter x or y, whichever is smaller. If x, y, or both x and y are equal to NaN, NaN is returned.</returns>
127-
/// <remarks>
128-
/// This method with single-precision floating-point parameter is exclusive of nanoFramework. It doesn't exist in the .NET API, only the double-precision floating-point version.
129-
/// It might not be available in all platforms or with firmware images that where build with double point FPU option.
130-
/// </remarks>
131-
/// <exception cref="NotImplementedException"/>
13219
[MethodImpl(MethodImplOptions.InternalCall)]
133-
public static extern float Min(float x, float y);
134-
20+
internal static extern int Max(int val1, int val2);
13521
}
13622
}

source/nanoFramework.CoreLibrary/System/String.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ public static string Format(string format, params object[] args)
701701
}
702702
else if (alignment < 0)
703703
{
704-
output += token.PadRight(Math.Abs(alignment));
704+
output += token.PadRight(MathInternal.Abs(alignment));
705705
}
706706
else
707707
{

source/nanoFramework.CoreLibrary/System/Text/StringBuilder.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public StringBuilder(int capacity, int maxCapacity)
222222
if (capacity > maxCapacity) throw new ArgumentOutOfRangeException("capacity");
223223
if (maxCapacity < 1) throw new ArgumentOutOfRangeException("maxCapacity");
224224
if (capacity < 0) throw new ArgumentOutOfRangeException("capacity");
225-
if (capacity == 0) capacity = Math.Min(0x10, maxCapacity);
225+
if (capacity == 0) capacity = MathInternal.Min(0x10, maxCapacity);
226226
_maxCapacity = maxCapacity;
227227
_chunkChars = new char[capacity];
228228
}
@@ -711,8 +711,8 @@ public StringBuilder Replace(char oldChar, char newChar, int startIndex, int cou
711711
var num4 = startIndex - chunkPrevious._chunkOffset;
712712
if (num3 >= 0)
713713
{
714-
var index = Math.Max(num4, 0);
715-
var num6 = Math.Min(chunkPrevious._chunkLength, num3);
714+
var index = MathInternal.Max(num4, 0);
715+
var num6 = MathInternal.Min(chunkPrevious._chunkLength, num3);
716716
while (index < num6)
717717
{
718718
if (chunkPrevious._chunkChars[index] == oldChar)
@@ -940,7 +940,7 @@ private void ReplaceInPlaceAtChunk(ref StringBuilder chunk, ref int indexInChunk
940940
while (true)
941941
{
942942
//int num = chunk.m_ChunkLength - indexInChunk;
943-
var length = Math.Min(chunk._chunkLength - indexInChunk, count);
943+
var length = MathInternal.Min(chunk._chunkLength - indexInChunk, count);
944944
//ThreadSafeCopy(value, ref valueIndex, chunk.m_ChunkChars, ref indexInChunk, num2);
945945
Array.Copy(value, valueIndex, chunk._chunkChars, indexInChunk, length);
946946
indexInChunk += length;
@@ -977,9 +977,9 @@ internal void MakeRoom(int index, int count, out StringBuilder chunk, out int in
977977
}
978978
else
979979
{
980-
var builder = new StringBuilder(Math.Max(count, 0x10), chunk._maxCapacity, chunk._chunkPrevious);
980+
var builder = new StringBuilder(MathInternal.Max(count, 0x10), chunk._maxCapacity, chunk._chunkPrevious);
981981
builder._chunkLength = count;
982-
var length = Math.Min(count, indexInChunk);
982+
var length = MathInternal.Min(count, indexInChunk);
983983
if (length > 0)
984984
{
985985
Array.Copy(chunk._chunkChars, 0, builder._chunkChars, 0, length);
@@ -1016,7 +1016,7 @@ internal void AppendHelper(ref string value)
10161016
internal void ExpandByABlock(int minBlockCharCount)
10171017
{
10181018
if (minBlockCharCount + Length > _maxCapacity) throw new ArgumentOutOfRangeException("requiredLength");
1019-
var num = Math.Max(minBlockCharCount, Math.Min(Length, 0x1f40));
1019+
var num = MathInternal.Max(minBlockCharCount, MathInternal.Min(Length, 0x1f40));
10201020
_chunkPrevious = new StringBuilder(this);
10211021
_chunkOffset += _chunkLength;
10221022
_chunkLength = 0;

0 commit comments

Comments
 (0)