示例#1
0
        public NumeralControl()
        {
            InitializeComponent();

            translation     = new BigExpoFraction(0, Base, 0);
            tbxNumeral.Text = translation.ToString();
        }
示例#2
0
        private void TbxNumeral_TextChanged(object sender, TextChangedEventArgs e)
        {
            BigExpoFraction fraction = new BigExpoFraction(tbxNumeral.Text, Base);

            if (fraction != translation && fraction != Value)
            {
                translation = fraction;
                Value       = fraction;
            }
        }
示例#3
0
        public BigExpoFraction Simplify()
        {
            BigExpoFraction bef = this;

            while (bef.DenominatorExponent > 0 && bef.Numerator % bef.DenominatorBase == BigInteger.Zero)
            {
                bef.DenominatorExponent--;
                bef.Numerator /= bef.DenominatorBase;
            }

            return(bef);
        }
示例#4
0
        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);
                }
            }
        }
示例#5
0
        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());
        }
示例#6
0
        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));
        }