An open API service indexing awesome lists of open source software.

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.

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

[![portfolio](https://img.shields.io/badge/my_portfolio-000?style=for-the-badge&logo=ko-fi&logoColor=white)](https://sakshamjoshi.vercel.app/)
[![linkedin](https://img.shields.io/badge/linkedin-0A66C2?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/sakshamjoshi27)
[![Github](https://img.shields.io/badge/Visit_my-Github-purple)](https://github.com/saksham-joshi)
[![X(Twitter)](https://img.shields.io/twitter/follow/sakshamjoshi27
)](https://x.com/sakshamjoshi27)
[![Static Badge](https://img.shields.io/badge/mail_at-social.sakshamjoshi%40gmail.com-aqua)](mailto:social.sakshamjoshi@gmail.com)

---