示例#1
0
 public NumberBuffer(NumberBufferKind kind, char *pDigits, int digitsLength)
 {
     Precision = 0;
     Scale     = 0;
     Sign      = false;
     Kind      = kind;
     Digits    = new Span <char>(pDigits, digitsLength);
 }
示例#2
0
 public NumberBuffer(NumberBufferKind kind, byte *buffer, int digitsCount, int scale, bool isNegative)
 {
     Kind        = kind;
     _buffer     = buffer;
     DigitsCount = digitsCount;
     Scale       = scale;
     IsNegative  = isNegative;
 }
示例#3
0
 internal NumberBuffer(NumberBufferKind kind, byte *digits, int digitsLength)
 {
     DigitsCount    = 0;
     Scale          = 0;
     IsNegative     = false;
     HasNonZeroTail = false;
     Kind           = kind;
     Digits         = new Span <byte>(digits, digitsLength);
     Digits[0]      = (byte)('\0');
 }
            public NumberBuffer(NumberBufferKind kind, char *digits, int digitsLength)
            {
                Debug.Assert(Enum.IsDefined(typeof(NumberBufferKind), kind));
                Debug.Assert(kind != NumberBufferKind.Unknown);
                Debug.Assert(digits != null);
                Debug.Assert(digitsLength > 0);

                Precision      = 0;
                Scale          = 0;
                Sign           = false;
                HasNonZeroTail = false;
                Kind           = kind;
                Digits         = new Span <char>(digits, digitsLength);
            }
示例#5
0
            public NumberBuffer(NumberBufferKind kind, char *digits, int digitsLength)
            {
                Debug.Assert(kind == NumberBufferKind.Integer ||
                             kind == NumberBufferKind.Decimal ||
                             kind == NumberBufferKind.FloatingPoint);
                Debug.Assert(digits != null);
                Debug.Assert(digitsLength > 0);

                Precision      = 0;
                Scale          = 0;
                Sign           = false;
                HasNonZeroTail = false;
                Kind           = kind;
                Digits         = new Span <char>(digits, digitsLength);
            }
示例#6
0
            /// <summary>Initializes the NumberBuffer.</summary>
            /// <param name="kind">The kind of the buffer.</param>
            /// <param name="digits">The digits scratch space. The referenced memory must not be moveable, e.g. stack memory, pinned array, etc.</param>
            public NumberBuffer(NumberBufferKind kind, Span <byte> digits)
            {
                Debug.Assert(!digits.IsEmpty);

                DigitsCount    = 0;
                Scale          = 0;
                IsNegative     = false;
                HasNonZeroTail = false;
                Kind           = kind;
                Digits         = digits;
#if DEBUG
                Digits.Fill(0xCC);
#endif
                Digits[0] = (byte)'\0';
                CheckConsistency();
            }
示例#7
0
        internal static unsafe string Format(Number value, string format, IFormatProvider formatProvider)
        {
            if (value._isNull)
            {
                return("NULL");
            }

            BigInteger       unscaledValue = value._unscaledNumber;
            int              scale         = value.Scale;
            NumberFormatInfo info          = NumberFormatInfo.GetInstance(formatProvider);

            if (string.IsNullOrEmpty(format))
            {
                return(FormatDigits(unscaledValue, scale, value.GetPrecision(), info));
            }

            ReadOnlySpan <char> formatSpan = format;
            int  precision = FormattingHelpers.CountDigits(unscaledValue);
            char fmt       = ParseFormatSpecifier(formatSpan, out int digits);

            if (fmt == 'D' || fmt == 'd')
            {
                return(FormatDigits(unscaledValue, scale, Math.Max(digits, precision), info));
            }

            int              bufferLength = precision + 1 + 1;
            byte *           digitsBuffer = stackalloc byte[bufferLength];
            NumberBufferKind kind         = scale > 0 ? NumberBufferKind.Decimal : NumberBufferKind.Integer;
            NumberBuffer     number       = new NumberBuffer(kind, digitsBuffer, bufferLength);

            BigIntegerToNumber(ref unscaledValue, ref number, precision, scale);

            const int          CharStackBufferSize = 32;
            char *             charBuffer          = stackalloc char[CharStackBufferSize];
            ValueStringBuilder sb = new ValueStringBuilder(new Span <char>(charBuffer, CharStackBufferSize));

            if (fmt != 0)
            {
                NumberToString(ref sb, ref number, fmt, digits, info);
            }
            else
            {
                NumberToStringFormat(ref sb, ref number, formatSpan, info);
            }

            return(sb.ToString());
        }
            public NumberBuffer(NumberBufferKind kind, byte *digits, int digitsLength)
            {
                Debug.Assert(digits != null);
                Debug.Assert(digitsLength > 0);

                DigitsCount    = 0;
                Scale          = 0;
                IsNegative     = false;
                HasNonZeroTail = false;
                Kind           = kind;
                Digits         = new Span <byte>(digits, digitsLength);

#if DEBUG
                Digits.Fill(0xCC);
#endif

                Digits[0] = (byte)('\0');
                CheckConsistency();
            }
示例#9
0
 public NumberBuffer(NumberBufferKind kind, byte *digits, int digitsLength) : this(kind, new Span <byte>(digits, digitsLength))
 {
     Debug.Assert(digits != null);
 }