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); } }
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}"); }