public NumeralControl() { InitializeComponent(); translation = new BigExpoFraction(0, Base, 0); tbxNumeral.Text = translation.ToString(); }
private void TbxNumeral_TextChanged(object sender, TextChangedEventArgs e) { BigExpoFraction fraction = new BigExpoFraction(tbxNumeral.Text, Base); if (fraction != translation && fraction != Value) { translation = fraction; Value = fraction; } }
public BigExpoFraction Simplify() { BigExpoFraction bef = this; while (bef.DenominatorExponent > 0 && bef.Numerator % bef.DenominatorBase == BigInteger.Zero) { bef.DenominatorExponent--; bef.Numerator /= bef.DenominatorBase; } return(bef); }
private void SetActualValue() { if (translation.DenominatorBase != Base || Value != translation) { translation = NumeralSystemConverter.Translate(Value, Base, Round); if (tbxNumeral != null) { int selectionStart = tbxNumeral.SelectionStart; int selectionLength = tbxNumeral.SelectionLength; tbxNumeral.Text = translation.ToString(); tbxNumeral.Select(selectionStart, selectionLength); } } }
public static BigExpoFraction Translate(BigExpoFraction value, int toBase, Round round) { if (!round.IsRelative) { return(value.ToDenominator(toBase, Math.Max(round.Absolute, 0))); } BigFraction maxRelDelta = new BigExpoFraction(1, 10, round.Relative) * value; BigExpoFraction output; int expo = -1; do { expo++; output = value.ToDenominator(toBase, expo); }while ((output - value).GetAbs() > maxRelDelta); return(output.Simplify()); }
public override string ToString() { BigExpoFraction fraction = this; int carry = 0; string text = string.Empty; for (int i = 0; fraction.Numerator > BigInteger.Zero || i <= fraction.DenominatorExponent; i++) { if (i == fraction.DenominatorExponent && fraction.DenominatorExponent > 0) { text = "," + text; } int currentNumeral = (int)BigInteger.Remainder(fraction.Numerator, fraction.DenominatorBase) + carry; carry = currentNumeral / fraction.DenominatorBase; fraction.Numerator /= fraction.DenominatorBase; text = numerals[currentNumeral % fraction.DenominatorBase] + text; } return(FinishString(text)); }