https://github.com/saksham-joshi/eval-java
With insane speed, solve mathematical expressions at runtime in a string using "Evaluater" class in Java.
https://github.com/saksham-joshi/eval-java
evaluation java math mathematical-expressions solver
Last synced: 10 months ago
JSON representation
With insane speed, solve mathematical expressions at runtime in a string using "Evaluater" class in Java.
- Host: GitHub
- URL: https://github.com/saksham-joshi/eval-java
- Owner: saksham-joshi
- License: gpl-3.0
- Created: 2023-08-30T12:15:03.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-01-10T03:11:39.000Z (over 1 year ago)
- Last Synced: 2025-06-06T13:03:16.938Z (about 1 year ago)
- Topics: evaluation, java, math, mathematical-expressions, solver
- Language: Java
- Homepage:
- Size: 30.3 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ข Eval-Java ๐ข
#### Python has a function called eval() used to solve mathematical expressions in a string but Java has nothing like this, so i developed this algorithm which can do so.
**You can use this package to create a calculator which can solve complex mathematical expressions.**
> #### ```Average Time Complexity: **O(n)**```
> #### ```Average Space Complexity: **O(k + m)**```
## ๐ Sample code
```java
import evaluater.Evaluater;
import evaluater.EvaluaterExceptions;
public class sample {
public static void main(String[] args)
{
try
{
Evaluater eval = new Evaluater("1280.33/(12*-10.11)");
System.out.println(eval.evaluate());
}
catch(EvaluaterExceptions.InvalidMathExpression excep)
{
System.out.println(excep);
}
}
}
```
> #### **NOTE:** ```evaluate() methods throw InvalidMathExpression exception if the given expression is invalid. ```
## โ Supported operators โ
| Operators | Name | Precedence |
| :-------: | :-------: | :-----------: |
| **+** | Addition | `1` |
| **-** | Subtraction | `1` |
| **x,*,X** | Multiplication | `2` |
| **/,รท** | Division | `2` |
| **%** | Modulus | `2` |
| **^** | Power | `3` |
| **!** | Not | `4` |
## ๐ Developer Links
[](https://sakshamjoshi.vercel.app/)
[](https://www.linkedin.com/in/sakshamjoshi27)
[](https://github.com/saksham-joshi)
[](https://x.com/sakshamjoshi27)
[](mailto:social.sakshamjoshi@gmail.com)
---