Beispiel #1
0
            internal void Append(SymbolAndPower symbolAndPower, SymbolFormat symbolFormat)
            {
                this.Append(symbolAndPower.Symbol);
                if (symbolAndPower.Power == 1)
                {
                    return;
                }

                switch (symbolFormat)
                {
                    case SymbolFormat.SignedHatPowers:
                        this.Append('^');
                        this.Append(symbolAndPower.Power.ToString(CultureInfo.InvariantCulture));
                        break;
                    case SymbolFormat.FractionHatPowers:
                        {
                            var power = Math.Abs(symbolAndPower.Power);
                            if (power == 1)
                            {
                                return;
                            }

                            this.Append('^');
                            this.Append(power.ToString(CultureInfo.InvariantCulture));
                            break;
                        }

                    case SymbolFormat.SignedSuperScript:
                        {
                            if (symbolAndPower.Power == 1)
                            {
                                return;
                            }

                            if (symbolAndPower.Power < 0)
                            {
                                this.Append(SuperScript.Minus);
                            }

                            this.Append(SuperScript.GetChar(Math.Abs(symbolAndPower.Power)));
                            break;
                        }

                    case SymbolFormat.Default:
                    case SymbolFormat.FractionSuperScript:
                        {
                            var power = Math.Abs(symbolAndPower.Power);
                            if (power == 1)
                            {
                                return;
                            }

                            this.Append(SuperScript.GetChar(Math.Abs(symbolAndPower.Power)));
                            break;
                        }

                    default:
                        throw new ArgumentOutOfRangeException(nameof(symbolFormat), symbolFormat, null);
                }
            }
Beispiel #2
0
        public override string ToString()
        {
            string p;

            if (this.Power == 1)
            {
                p = string.Empty;
            }
            else if (this.Power > 1)
            {
                p = new string(SuperScript.GetChar(this.Power), 1);
            }
            else
            {
                p = new string(new[] { '⁻', SuperScript.GetChar(-1 * this.Power) });
            }

            return($"{this.Symbol}{p}");
        }
Beispiel #3
0
        private static bool TryReadSuperScriptInt(string text, ref int pos, out int result)
        {
            result = SuperScript.GetDigit(text[pos]);
            if (result < 0)
            {
                result = 0;
                return(false);
            }

            pos++;

            while (pos < text.Length &&
                   text[pos].IsSuperscriptDigit())
            {
                result *= 10;
                result += SuperScript.GetDigit(text[pos]);
                pos++;
            }

            return(true);
        }