Example #1
0
        //••••••••••••••••••••••••••••••••••••••••••••••••••••••••
        /// <summary>
        /// Solve user expression, may throw Calc.SyntaxException,
        /// Calc.CommandException, Calc.EngineException.</summary>
        /// <param name="_sExpr">user expression</param>
        /// <param name="_Answer">user answer holder, where
        /// solved expression result is placed</param>
        public void Solve(string _sExpr, ref CNumber _Answer)
        {// void expression equals to void result
            if (_sExpr == null || _sExpr == "")
            {
                return;
            }
            _sExpr = _sExpr.Replace(" ", "").ToLower(); // simplify

            CatchCommand(_sExpr);                       // if command - execute

            // reinit & assimilate template number properties
            m_block.Init(_Answer);

            // `m_result` will like the caller answer holder and will take
            // a part in temporary calculations through `Parts_Solve` and
            // Parse_to_Blocks;
            m_result = new CNumber("0", _Answer);
            try
            {
                Parse_to_Blocks(_sExpr);
            }
            catch (ServiceException xcp)
            {
                ASSERT(false, xcp.Message, "Solve.conversion");
            }

            Parts_Solve(m_block);

            // set user answer holder and common answer registry to
            // a newly solved value
            _Answer = m_block[0].Number;
            m_reg.ANSWER.GetProperties(_Answer);
            m_reg.ANSWER = _Answer;
            return;
        }
Example #2
0
        /// <summary>
        /// Create and return the sub-copy of the current object</summary>
        /// <param name="_from">from index in current object</param>
        /// <param name="_to">to index in current object</param>
        public CBlock Projection(int _from, int _to)
        {
            CBlock block = new CBlock();

            block.Init(m_NumEtalon);
            for (int i = _from; i <= _to; i++)
            {
                if (this[i].IsOperator)
                {
                    block.BaseAdd(null, this[i].Operator);
                }
                else if (this[i].IsNumber)
                {
                    block.BaseAdd(null, this[i].Number);
                }
            }
            return(block);
        }