ToNewBase() public static méthode

Converts number to the new numeral system.
public static ToNewBase ( int number, NumeralSystem numeralSystem ) : string
number int The number.
numeralSystem NumeralSystem The numeral system.
Résultat string
Exemple #1
0
        /// <summary>
        /// Solves the specified expression.
        /// </summary>
        /// <param name="function">The function.</param>
        /// <param name="simplify">if set to <c>true</c> parser will simplify expression.</param>
        /// <returns>The result of solving.</returns>
        public IResult Solve(string function, bool simplify)
        {
            var exp = Parse(function);

            exp.Analyze(TypeAnalyzer);

            var result = exp.Execute(Parameters);

            if (result is double number)
            {
                if (NumeralSystem == NumeralSystem.Decimal)
                {
                    return(new NumberResult(number));
                }

                return(new StringResult(MathExtensions.ToNewBase((int)number, NumeralSystem)));
            }
            if (result is Complex complex)
            {
                return(new ComplexNumberResult(complex));
            }
            if (result is bool boolean)
            {
                return(new BooleanResult(boolean));
            }
            if (result is string str)
            {
                return(new StringResult(str));
            }
            if (result is IExpression expression)
            {
                if (simplify)
                {
                    return(new ExpressionResult(Simplify(expression)));
                }

                return(new ExpressionResult(expression));
            }

            throw new InvalidResultException();
        }
Exemple #2
0
        /// <summary>
        /// Solves the specified expression.
        /// </summary>
        /// <param name="function">The function.</param>
        /// <returns>The result of solving.</returns>
        public IResult Solve(string function)
        {
            var exp = Parse(function);

            exp.Analyze(TypeAnalyzer);

            var result = exp.Execute(Parameters);

            if (result is double)
            {
                if (NumeralSystem == NumeralSystem.Decimal)
                {
                    return(new NumberResult((double)result));
                }

                return(new StringResult(MathExtensions.ToNewBase((int)(double)result, NumeralSystem)));
            }
            if (result is Complex)
            {
                return(new ComplexNumberResult((Complex)result));
            }
            if (result is bool)
            {
                return(new BooleanResult((bool)result));
            }
            if (result is string)
            {
                return(new StringResult((string)result));
            }
            if (result is IExpression)
            {
                if (DoSimplify)
                {
                    return(new ExpressionResult(Simplify((IExpression)result)));
                }

                return(new ExpressionResult((IExpression)result));
            }

            throw new InvalidResultException();
        }