Expand description
Command-line interface for the kalkulator
library.
This interface allows users to either convert mathematical expressions to postfix notation or evaluate them directly, and to display all supported operators.
§Usage
To convert an expression to postfix notation without evaluating:
kalkulator --expr "2+3/4" -p
To evaluate the result of an expression:
kalkulator --expr "2+3/4"
To show all available operations:
kalkulator --show-ops
§Library Usage Examples
Below are examples showcasing how to use the Expression
struct within Rust code to evaluate mathematical expressions.
Basic usage to evaluate an arithmetic expression:
use kalkulator::Expression;
let mut expr = Expression::new("3+4*2");
expr.infix_to_postfix().unwrap(); // Converts to postfix notation
expr.compute_expression().unwrap(); // Evaluates the expression
assert_eq!(expr.get_result().unwrap(), 11); // The result is 11
Evaluating an expression with factorial and division:
use kalkulator::Expression;
let mut expr = Expression::new("4!/(2+3)");
expr.infix_to_postfix().unwrap(); // Converts to postfix notation
expr.compute_expression().unwrap(); // Evaluates the expression
assert_eq!(expr.get_result().unwrap(), 24); // The result is 24 (120 / 5)
Evaluating an expression involving all supported operations:
use kalkulator::Expression;
let mut expr = Expression::new("2+3*4-5/2");
expr.infix_to_postfix().unwrap();
expr.compute_expression().unwrap();
assert_eq!(expr.get_result().unwrap(), 11); // The result is 11
Structs§
- Expression
- Represents an arithmetic expression, its postfix notation, and computation result.
- FACTORIAL_
CACHE
Enums§
- Error
Kind - Enumerates possible errors that can occur during expression parsing and evaluation.