Skip to content

Nico343/BASIC

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Modifications

Renamed the repository as BASIC (Basic Arduino String Input Calculator) cuz that is what its intended for.

Borked the smart implementation based on regex and vector by using buffers of character and double. I also had to implement my own push, pop, length, back, isempty, and empty functions. I had to do that since Arduino doesn't support regex and vectors natively.

Yes I'm aware that there are pre-built regex and vector libraries. But under space constraints, having another library to use the original code doesn't help. That's also why I couldn't use the far more capable tinyexpr.

Will be updating this repo as my code golfing ability improves.

Calculator 🔰

A simple calculator that supports BODMAS, nested parentheses, unary operators, variable precision, and more. It uses the Shunting Yard Algorithm to convert an input infix expression to postfix expression before evaluating it.

Enter your mathematical expression : 4*(5-3)^4

Enter precision (number of decimal places): 5

Postfix = 4 5 3 - 4 ^ * 

Answer = 64.00000

🚀 Usage

Download the project using Git (or otherwise) and compile the code in calculator.cpp.

👍 Examples of valid expressions

112+22*(2*(22-53^2*(2))-7/(7/2-1/4)) //-246159.38462

2+-1 // 1

2^0.5 // 1.413

7^7^(2/(4-532)^3) // 7^(7^(2/(4-532)^3)) = 7.0

2(2)  // same as 2*2

👎 Examples of invalid expressions

1---1 //not supported yet
2* //incomplete expression
7 ^ 7 ^ (2/(4-532)^3) //(No spaces between digits/operators are allowed when inputting directly from console)

🛑 Current limitations

  • Range of numbers is limited by double data type.
  • No support for trigonometric and logarithmic expressions.
  • No support for expressions containing irrational numbers ($\pi$, $e$, $\ln 3 + 5$)
  • Input is not validated so all invalid inputs will cause program to crash.

About

Basic Arduino String Input Calculator. Simple calculator that supports BODMAS, nested parentheses, unary operators, and more. Precision of output can be varied.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C++ 100.0%