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

Commit

Permalink
Moving GetExponent/Mantissa and make BigInteger used fixed-sized buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
tannergooding committed Sep 19, 2018
1 parent c27ad27 commit 9f259bc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
16 changes: 0 additions & 16 deletions src/System.Private.CoreLib/shared/System/Double.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,6 @@ namespace System
// We use this explicit definition to avoid the confusion between 0.0 and -0.0.
internal const double NegativeZero = -0.0;

[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static int GetExponent(double d)
{
var bits = BitConverter.DoubleToInt64Bits(d);
return (int)((bits >> 52) & 0x7FF);
}

[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static long GetMantissa(double d)
{
var bits = BitConverter.DoubleToInt64Bits(d);
return (bits & 0xFFFFFFFFFFFFF);
}

/// <summary>Determines whether the specified value is finite (zero, subnormal, or normal).</summary>
[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,11 @@ public void ShiftLeft(uint shift)
}
}

[StructLayout(LayoutKind.Sequential, Size = (MaxBlockCount * sizeof(uint)))]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
private struct BlocksBuffer
{
private fixed uint _blocks[MaxBlockCount];

public ref uint this[int index]
{
get
Expand Down
18 changes: 16 additions & 2 deletions src/System.Private.CoreLib/shared/System/Number.Formatting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2310,8 +2310,8 @@ private static unsafe void DoubleToNumber(double value, int precision, ref Numbe

private static long ExtractFractionAndBiasedExponent(double value, out int exponent)
{
long fraction = double.GetMantissa(value);
exponent = double.GetExponent(value);
long fraction = GetMantissa(value);
exponent = GetExponent(value);

if (exponent != 0)
{
Expand All @@ -2338,5 +2338,19 @@ private static long ExtractFractionAndBiasedExponent(double value, out int expon

return fraction;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static int GetExponent(double d)
{
var bits = BitConverter.DoubleToInt64Bits(d);
return (int)((bits >> 52) & 0x7FF);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static long GetMantissa(double d)
{
var bits = BitConverter.DoubleToInt64Bits(d);
return (bits & 0xFFFFFFFFFFFFF);
}
}
}

0 comments on commit 9f259bc

Please sign in to comment.