Changing Number.BigInteger and Number.NumberBuffer to directly use fixed-sized buffer...
[platform/upstream/coreclr.git] / src / System.Private.CoreLib / shared / System / Number.NumberBuffer.cs
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5 using System.Runtime.InteropServices;
6 using Internal.Runtime.CompilerServices;
7
8 namespace System
9 {
10     internal static partial class Number
11     {
12         private const int NumberMaxDigits = 50;
13
14         private const double Log10V2 = 0.30102999566398119521373889472449;
15
16         // DriftFactor = 1 - Log10V2 - epsilon (a small number account for drift of floating point multiplication)
17         private const double DriftFactor = 0.69;
18
19         [StructLayout(LayoutKind.Sequential, Pack = 1)]
20         internal unsafe ref struct NumberBuffer
21         {
22             public int precision;
23             public int scale;
24             public bool sign;
25             public NumberBufferKind kind;
26             public fixed char digits[NumberMaxDigits + 1];
27
28             public char* GetDigitsPointer()
29             {
30                 // This is safe to do since we are a ref struct
31                 return (char*)(Unsafe.AsPointer(ref digits[0]));
32             }
33         }
34
35         internal enum NumberBufferKind : byte
36         {
37             Unknown = 0,
38             Integer = 1,
39             Decimal = 2,
40             Double = 3
41         }
42     }
43 }