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

Porting NumberToDouble to managed code. #20080

Merged
merged 5 commits into from Sep 22, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/System.Private.CoreLib/System.Private.CoreLib.csproj
Expand Up @@ -276,7 +276,6 @@
<Compile Include="$(BclSourcesRoot)\System\MathF.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\mda.cs" />
<Compile Include="$(BclSourcesRoot)\System\MissingMemberException.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Number.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\RtType.cs" />
<Compile Include="$(BclSourcesRoot)\System\RuntimeArgumentHandle.cs" />
<Compile Include="$(BclSourcesRoot)\System\RuntimeHandles.cs" />
Expand Down
Expand Up @@ -283,6 +283,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Number.Formatting.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Number.Grisu3.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Number.NumberBuffer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Number.NumberToDouble.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Number.Parsing.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\NullReferenceException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ObjectDisposedException.cs" />
Expand Down
Expand Up @@ -3,22 +3,21 @@
// See the LICENSE file in the project root for more information.

using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;

namespace System
{
internal static partial class Number
{
private const int NumberMaxDigits = 50; // needs to == NUMBER_MAXDIGITS in coreclr's src/classlibnative/bcltype/number.h.
private const int NumberMaxDigits = 50;

private const double Log10V2 = 0.30102999566398119521373889472449;

// DriftFactor = 1 - Log10V2 - epsilon (a small number account for drift of floating point multiplication)
private const double DriftFactor = 0.69;

[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal unsafe ref struct NumberBuffer // needs to match layout of NUMBER in coreclr's src/classlibnative/bcltype/number.h
internal unsafe ref struct NumberBuffer
{
public int precision; // 0
public int scale; // 4
Expand All @@ -35,7 +34,7 @@ internal static partial class Number
private struct DigitsAndNullTerminator { }
}

internal enum NumberBufferKind // needs to match NUMBER_KIND in coreclr's src/classlibnative/bcltype/number.h
internal enum NumberBufferKind
{
Unknown = 0,
Integer = 1,
Expand Down