Solver is a Java-based library designed to evaluate mathematical expressions with operator precedence. It provides robust support for operations like addition, subtraction, multiplication, division, factorials, exponentiation, and parenthesis-based grouping, following standard mathematical rules.
- Operator Precedence: Handles the correct order of operations (e.g., multiplication/division before addition/subtraction).
- Parentheses Support: Supports nested expressions with parentheses.
- Factorial and Exponentiation: Includes support for factorial (
!) and exponentiation (^) operators. - Error Handling: Includes detailed exception handling for invalid expressions.
- Customizable: Easily extendable for additional operators or functionalities.
The Solver class evaluates mathematical expressions using a recursive descent parser. This allows the library to handle complex arithmetic expressions while maintaining clarity and modularity.
Example:
Solver solver = new Solver("3 + 5 * (2 - 8)^2!");
long result = solver.evaluate();
System.out.println(result); // Output: 183The following operators are supported:
+(Addition)-(Subtraction)*(Multiplication)/(Division)!(Factorial)^(Exponentiation)()(Parentheses for grouping)
<dependencies>
<dependency>
<groupId>com.github.embuc</groupId>
<artifactId>equation-solver</artifactId>
<version>1.0</version>
</dependency>
</dependencies>See the ChangeLog.txt file.
This project is licensed under the ISC License. See the ISC License documentation for more details (There is also one in the root of the project).