Esempio n. 1
0
 public StringFormatOptions(BigFloat number, NumberFormatInfo nfi)
 {
     Number          = number;
     NuberFormatInfo = nfi;
 }
Esempio n. 2
0
            private void Normalize()
            {
                if (DigitsPart.IsVoid())
                {
                    return;
                }

                if (UnchangedRounding || Exponent > DigitsPart.Length)
                {
                    return;
                }

                var max  = _digits[Base];
                var last = DigitsPart.TakeLast(2);

                if (last.Length < 2)
                {
                    return;
                }

                var    exp = Exponent;
                string alt;

                if (last[1] != '0' && last[1] != max)
                {
                    last = last.TakeFirst();
                }

                if (last[0] == '0')
                {
                    alt = DigitsPart.SkipLast().TrimEnd('0');
                }
                else if (last[0] == max)
                {
                    alt = DigitsPart.SkipLast().TrimEnd(max);
                    if (alt.Length == 0)
                    {
                        alt = "1";
                        exp = Exponent + 1;
                    }
                    else if (last[0] == max)
                    {
                        var c = alt.TakeLast()[0];
                        max = _digits[_position[c] + 1];
                        alt = $"{(alt.Length > 1 ? alt.Substring(0, alt.Length - 1) : "")}{max}";
                    }
                }
                else
                {
                    alt = DigitsPart.SkipLast();
                }

                var check = new BigFloat($"{SignPart}0.{alt}@{(exp >= 0 ? "+" : "-")}{Math.Abs(Exponent)}", Base, Number.Precision);

                if (!check.IsEqual(Number))
                {
                    return;
                }

                if (UnchangedLength)
                {
                    alt = alt.PadRight(DigitsPart.Length, '0');
                }

                Exponent   = exp;
                DigitsPart = alt;
                Value      = $"{SignPart}{DigitsPart}";
            }
Esempio n. 3
0
 public static bool IsNegative(BigFloat op) => op?.IsNegative() ?? false;