This is the new version of the math interpreter since it got extremely hard to update and add new tests to it. So this is the same interpreter with a better structure so it is easier to maintain. You can find the original project here.
Thanks to CodePulse for the original project. He created the original interpreter in python and I basically converted to a C# project. You can find the original source code here. Thanks to CodePulse for the project.
The interpreter supports the following oprators in the given precedence-
Brackets : ( )
Exponent : **
Exponent : !
Division : /
Multiplication : *
Addition : +
Subtraction : -
It supports positive as well as negative numbers and also supports decimal numbers.
Note: Some of you might be wondering why there is not underroot operator. After much consideration, I decided that it was really unnecessary. Well you can just use this property - number1/x is equal to xth root of the number.
For example:
41/2 is equal to square root of 4 which is 2
271/3 is equal to cube root of 27 which is 3
and so on...
So, to perform the under root operation in the calualator for any number, lets say 144-
>>> 144 ** (1/2)
The parentheses are important as the power operator is upper in the operator hierarchy. If the don't include them the result would become-
>>> (144 ** 1) / 2
To use the math interpreter console, follow the given steps -
- Install the dotnet core sdk
- Clone the repository
- Navigate to
<repo_location>/Mathinterpreter.console/
directory in the terminal. (Where <repo_location> is the directory where you cloned the repo.) - Run the command
dotnet run
in the terminal. - It prompts you for input. Enter any valid mathematical expression as stated above.
Since the core application is a dotnet standard class library, it is easily portable. Just add a refernce to the MathInterpreter.MathInterpreter.csproj file in your project.