Function calculate_expression

Source
pub fn calculate_expression(
    input: &str,
    history: &mut History,
) -> CalculationResult
Expand description

Endpoint to process a mathematical expression and return the result as a string.

#Arguments

  • ‘input’: A string representation of the infix expression to be processed.

#Returns

‘CalculationResult’ structure containing:

  • success: A boolean indicating whether the calculation was successful.
  • expression: The original mathematical expression provided by the user.
  • rpn_expression: The corresponding expression in Reverse Polish Notation (RPN).
  • result: The numerical result of the calculation.
  • message: An additional message providing details about the calculation outcome, such as errors or warnings.

#Errors

This function returns an error code in the following cases:

  • If the expression contains mismatched parentheses or cannot be tokenized, an error message is returned.
  • If the conversion to C-compatible format fails, an error message is returned.
  • If the C function for evaluation fails, an error message with details is included in the response.