Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Porting NumberToDouble to managed code. (dotnet/coreclr#20080)
Browse files Browse the repository at this point in the history
* Porting NumberToDouble to managed code.

* Deleting bcltype/number.cpp and bcltype/number.h

* Fixing NumberToDouble to call Int64BitsToDouble, rather than DoubleToInt64Bits

* Some minor code cleanup in NumberToDouble for better readability.

* Some additional code cleanup in the Number.NumberToDouble.cs code

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
  • Loading branch information
tannergooding authored and jkotas committed Sep 23, 2018
1 parent dec2d45 commit 90bd9e4
Show file tree
Hide file tree
Showing 3 changed files with 453 additions and 4 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 unsafe ref struct NumberBuffer // needs to match layout of NUMBER in co
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
Loading

0 comments on commit 90bd9e4

Please sign in to comment.