Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion source/nanoFramework.CoreLibrary/CoreLibrary.nfproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
</PropertyGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
<ItemGroup>
<Compile Include="Friends.cs" />
<Compile Include="System\AppDomain.cs" />
<Compile Include="System\AppDomainUnloadedException.cs" />
<Compile Include="System\ApplicationException.cs" />
Expand Down Expand Up @@ -379,4 +380,4 @@
<ProjectConfigurationsDeclaredAsItems />
</ProjectCapabilities>
</ProjectExtensions>
</Project>
</Project>
8 changes: 8 additions & 0 deletions source/nanoFramework.CoreLibrary/Friends.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// Copyright (c) 2017 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

using System.Runtime.CompilerServices;

[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("System.Math, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")]
122 changes: 4 additions & 118 deletions source/nanoFramework.CoreLibrary/System/Math.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,129 +8,15 @@ namespace System
{
using Runtime.CompilerServices;

/// <summary>
/// Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions.
/// </summary>
/// <remarks>
/// Specific for nanoFramework: this class library is split between mscorlib and it's own assembly.
/// If you require any of the other methods that are not available here add the NuGet package nanoFramework.System.Math.
/// </remarks>
public static partial class Math
internal static class MathInternal
{
/// <summary>
/// Represents the ratio of the circumference of a circle to its diameter, specified by the constant, π.
/// </summary>
/// <remarks>The value of this field is 3.14159265358979323846.</remarks>
public const double PI = 3.14159265358979323846;
/// <summary>
/// Represents the natural logarithmic base, specified by the constant, e.
/// </summary>
/// <remarks>The value of this field is 2.7182818284590452354.</remarks>
public const double E = 2.7182818284590452354;

/// <summary>
/// Returns the absolute value of a 32-bit signed integer.
/// </summary>
/// <param name="val">A number that is greater than Int32..::..MinValue, but less than or equal to Int32..::..MaxValue.</param>
/// <returns>A 32-bit signed integer, x, such that 0 ≤ x ≤ Int32..::..MaxValue.</returns>
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern int Abs(int val);

/// <summary>
/// Returns the absolute value of a double-precision floating-point number.
/// </summary>
/// <param name="val">A number that is greater than or equal to Double..::..MinValue, but less than or equal to Double..::..MaxValue.</param>
/// <returns>A double-precision floating-point number, x, such that 0 ≤ x ≤ Double..::..MaxValue.</returns>
/// <remarks>
/// 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.
/// </remarks>
/// <exception cref="NotImplementedException"/>
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern double Abs(double val);

/// <summary>
/// Returns the absolute value of a single-precision floating-point number.
/// </summary>
/// <param name="val">A number that is greater than or equal to Double..::..MinValue, but less than or equal to Double..::..MaxValue.</param>
/// <returns>A single-precision floating-point number, x, such that 0 ≤ x ≤ Double..::..MaxValue.</returns>
/// <remarks>
/// 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.
/// It might not be available in all platforms or with firmware images that where build with double point FPU option.
/// </remarks>
/// <exception cref="NotImplementedException"/>
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern float Abs(float val);

/// <summary>
/// Returns the larger of two 32-bit signed integers.
/// </summary>
/// <param name="val1">The first of two 32-bit signed integers to compare. </param>
/// <param name="val2">The second of two 32-bit signed integers to compare. </param>
/// <returns>Parameter val1 or val2, whichever is larger.</returns>
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern int Max(int val1, int val2);

/// <summary>
/// Returns the larger of two double-precision floating-point numbers.
/// </summary>
/// <param name="x">The first of two double-precision floating-point numbers to compare. </param>
/// <param name="y">The second of two double-precision floating-point numbers to compare. </param>
/// <returns>Parameter x or y, whichever is larger. If x, y, or both x and y are equal to NaN, NaN is returned.</returns>
/// <remarks>
/// 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.
/// </remarks>
/// <exception cref="NotImplementedException"/>
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern double Max(double x, double y);

/// <summary>
/// Returns the larger of two single-precision floating-point numbers.
/// </summary>
/// <param name="x">The first of two single-precision floating-point numbers to compare. </param>
/// <param name="y">The second of two single-precision floating-point numbers to compare. </param>
/// <returns>Parameter x or y, whichever is larger. If x, y, or both x and y are equal to NaN, NaN is returned.</returns>
/// <remarks>
/// 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.
/// It might not be available in all platforms or with firmware images that where build with double point FPU option.
/// </remarks>
/// <exception cref="NotImplementedException"/>
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern float Max(float x, float y);
internal static extern int Abs(int val);

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

/// <summary>
/// Returns the smaller of two double-precision floating-point numbers.
/// </summary>
/// <param name="x">The first of two double-precision floating-point numbers to compare. </param>
/// <param name="y">The second of two double-precision floating-point numbers to compare. </param>
/// <returns>Parameter x or y, whichever is smaller. If x, y, or both x and y are equal to NaN, NaN is returned.</returns>
/// <remarks>
/// 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.
/// </remarks>
/// <exception cref="NotImplementedException"/>
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern double Min(double x, double y);
/// <summary>
/// Returns the smaller of two single-precision floating-point numbers.
/// </summary>
/// <param name="x">The first of two single-precision floating-point numbers to compare. </param>
/// <param name="y">The second of two single-precision floating-point numbers to compare. </param>
/// <returns>Parameter x or y, whichever is smaller. If x, y, or both x and y are equal to NaN, NaN is returned.</returns>
/// <remarks>
/// 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.
/// It might not be available in all platforms or with firmware images that where build with double point FPU option.
/// </remarks>
/// <exception cref="NotImplementedException"/>
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern float Min(float x, float y);

internal static extern int Max(int val1, int val2);
}
}
2 changes: 1 addition & 1 deletion source/nanoFramework.CoreLibrary/System/String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ public static string Format(string format, params object[] args)
}
else if (alignment < 0)
{
output += token.PadRight(Math.Abs(alignment));
output += token.PadRight(MathInternal.Abs(alignment));
}
else
{
Expand Down
14 changes: 7 additions & 7 deletions source/nanoFramework.CoreLibrary/System/Text/StringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public StringBuilder(int capacity, int maxCapacity)
if (capacity > maxCapacity) throw new ArgumentOutOfRangeException("capacity");
if (maxCapacity < 1) throw new ArgumentOutOfRangeException("maxCapacity");
if (capacity < 0) throw new ArgumentOutOfRangeException("capacity");
if (capacity == 0) capacity = Math.Min(0x10, maxCapacity);
if (capacity == 0) capacity = MathInternal.Min(0x10, maxCapacity);
_maxCapacity = maxCapacity;
_chunkChars = new char[capacity];
}
Expand Down Expand Up @@ -711,8 +711,8 @@ public StringBuilder Replace(char oldChar, char newChar, int startIndex, int cou
var num4 = startIndex - chunkPrevious._chunkOffset;
if (num3 >= 0)
{
var index = Math.Max(num4, 0);
var num6 = Math.Min(chunkPrevious._chunkLength, num3);
var index = MathInternal.Max(num4, 0);
var num6 = MathInternal.Min(chunkPrevious._chunkLength, num3);
while (index < num6)
{
if (chunkPrevious._chunkChars[index] == oldChar)
Expand Down Expand Up @@ -940,7 +940,7 @@ private void ReplaceInPlaceAtChunk(ref StringBuilder chunk, ref int indexInChunk
while (true)
{
//int num = chunk.m_ChunkLength - indexInChunk;
var length = Math.Min(chunk._chunkLength - indexInChunk, count);
var length = MathInternal.Min(chunk._chunkLength - indexInChunk, count);
//ThreadSafeCopy(value, ref valueIndex, chunk.m_ChunkChars, ref indexInChunk, num2);
Array.Copy(value, valueIndex, chunk._chunkChars, indexInChunk, length);
indexInChunk += length;
Expand Down Expand Up @@ -977,9 +977,9 @@ internal void MakeRoom(int index, int count, out StringBuilder chunk, out int in
}
else
{
var builder = new StringBuilder(Math.Max(count, 0x10), chunk._maxCapacity, chunk._chunkPrevious);
var builder = new StringBuilder(MathInternal.Max(count, 0x10), chunk._maxCapacity, chunk._chunkPrevious);
builder._chunkLength = count;
var length = Math.Min(count, indexInChunk);
var length = MathInternal.Min(count, indexInChunk);
if (length > 0)
{
Array.Copy(chunk._chunkChars, 0, builder._chunkChars, 0, length);
Expand Down Expand Up @@ -1016,7 +1016,7 @@ internal void AppendHelper(ref string value)
internal void ExpandByABlock(int minBlockCharCount)
{
if (minBlockCharCount + Length > _maxCapacity) throw new ArgumentOutOfRangeException("requiredLength");
var num = Math.Max(minBlockCharCount, Math.Min(Length, 0x1f40));
var num = MathInternal.Max(minBlockCharCount, MathInternal.Min(Length, 0x1f40));
_chunkPrevious = new StringBuilder(this);
_chunkOffset += _chunkLength;
_chunkLength = 0;
Expand Down