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

bool Calculator::calculateRPN ( MathFunction f,
int  msecs,
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. This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified. The calculation can then be stopped with abort().

Parameters:
f Mathematical function.
msecs The maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
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:
true if the calculation was successfully started (and finished if msecs > 0).

Definition at line 1814 of file Calculator.cc.

References MathStructure::addChild(), ParseOptions::angle_unit, MathFunction::appendDefaultValues(), MathFunction::args(), 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);
      return calculateRPN(mstruct, PROC_RPN_OPERATION_1, 0, msecs, eo);
}


Generated by  Doxygen 1.6.0   Back to index