summaryrefslogtreecommitdiff
path: root/src/System.Private.CoreLib/shared/System/Number.NumberBuffer.cs
blob: 2316f99bd3a0f3b90a2a51264deb16cb6087c2a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// 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.

        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        internal unsafe ref struct NumberBuffer // needs to match layout of NUMBER in coreclr's src/classlibnative/bcltype/number.h
        {
            public int precision;
            public int scale;
            private int _sign;
            private DigitsAndNullTerminator _digits;
            private char* _allDigits;

            public bool sign { get => _sign != 0; set => _sign = value ? 1 : 0; }
            public char* digits => (char*)Unsafe.AsPointer(ref _digits);

            [StructLayout(LayoutKind.Sequential, Size = (NumberMaxDigits + 1) * sizeof(char))]
            private struct DigitsAndNullTerminator { }
        }
    }
}