Logo Search packages:      
Sourcecode: libqalculate version File versions  Download package

MathStructure * Calculator::calculateRPN ( MathFunction f,
const EvaluationOptions eo = default_evaluation_options,
MathStructure parsed_struct = NULL 
)

Applies a mathematical operation to the first value on the RPN stack. The value is set as the first argument of the function. If no register is available, then zero is added.

Parameters:
f Mathematical function.
eo Options for the evaluation and parsing of the expression.
[out] parsed_struct NULL or a math structure to fill with the unevaluated result.
Returns:
The first value on the stack.

Definition at line 1914 of file Calculator.cc.

References MathStructure::addChild(), ParseOptions::angle_unit, MathFunction::appendDefaultValues(), MathFunction::args(), MathStructure::eval(), MathFunction::getArgumentDefinition(), getDegUnit(), getGraUnit(), getRadUnit(), EvaluationOptions::parse_options, MathStructure::set(), and Argument::type().

                                                                                                                  {
      MathStructure *mstruct = new MathStructure(f, NULL);
      if(f->args() != 0) {
            if(rpn_stack.size() == 0) mstruct->addChild(m_zero);
            else mstruct->addChild(*rpn_stack.back());
            f->appendDefaultValues(*mstruct);
            if(f->getArgumentDefinition(1) && f->getArgumentDefinition(1)->type() == ARGUMENT_TYPE_ANGLE) {
                  switch(eo.parse_options.angle_unit) {
                        case ANGLE_UNIT_DEGREES: {
                              (*mstruct)[0].multiply(getDegUnit());
                              break;
                        }
                        case ANGLE_UNIT_GRADIANS: {
                              (*mstruct)[0].multiply(getGraUnit());
                              break;
                        }
                        case ANGLE_UNIT_RADIANS: {
                              (*mstruct)[0].multiply(getRadUnit());
                              break;
                        }
                        default: {}
                  }
            }
      }
      if(parsed_struct) parsed_struct->set(*mstruct);
      mstruct->eval(eo);
      autoConvert(*mstruct, *mstruct, eo);
      if(rpn_stack.size() == 0) {
            rpn_stack.push_back(mstruct);
      } else {
            rpn_stack.back()->unref();
            rpn_stack.back() = mstruct;
      }
      return rpn_stack.back();
}


Generated by  Doxygen 1.6.0   Back to index