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

bool Calculator::calculateRPN ( MathOperation  op,
int  msecs,
const EvaluationOptions eo = default_evaluation_options,
MathStructure parsed_struct = NULL 
)

Applies a mathematical operation to the first and second value on the RPN stack. The the second value is changed with input from the first value. For example, with OPERATION_SUBTRACT the first value is subtracted from the second. The first value on the stack is removed. If not enough registers is available, then zeros are 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:
op Operation.
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 1777 of file Calculator.cc.

References MathStructure::add(), MathStructure::clear(), MathStructure::set(), and MathStructure::transform().

                                                                                                                    {
      MathStructure *mstruct;
      if(rpn_stack.size() == 0) {
            mstruct = new MathStructure();
            mstruct->add(m_zero, op);
            if(parsed_struct) parsed_struct->clear();
      } else if(rpn_stack.size() == 1) {
            if(parsed_struct) {
                  parsed_struct->clear();
                  if(op == OPERATION_SUBTRACT) {
                        parsed_struct->transform(STRUCT_ADDITION, *rpn_stack.back());
                        (*parsed_struct)[1].transform(STRUCT_NEGATE);
                  } else if(op == OPERATION_DIVIDE) {
                        parsed_struct->transform(STRUCT_DIVISION, *rpn_stack.back());
                  } else {
                        parsed_struct->add(*rpn_stack.back(), op);
                  }
            }
            mstruct = new MathStructure();
            mstruct->add(*rpn_stack.back(), op);
      } else {
            if(parsed_struct) {
                  parsed_struct->set(*rpn_stack[rpn_stack.size() - 2]);
                  if(op == OPERATION_SUBTRACT) {
                        parsed_struct->transform(STRUCT_ADDITION, *rpn_stack.back());
                        (*parsed_struct)[1].transform(STRUCT_NEGATE);
                  } else if(op == OPERATION_DIVIDE) {
                        parsed_struct->transform(STRUCT_DIVISION, *rpn_stack.back());
                  } else {
                        parsed_struct->add(*rpn_stack.back(), op);
                  }
            }
            mstruct = new MathStructure(*rpn_stack[rpn_stack.size() - 2]);
            mstruct->add(*rpn_stack.back(), op);
      }
      return calculateRPN(mstruct, PROC_RPN_OPERATION_2, 0, msecs, eo);
}


Generated by  Doxygen 1.6.0   Back to index