🧮 Introduction
A project of mine that evaluates math expressions, with no extensions involved. It was surely one of the best I made as I learned a lot of fun algorithms on the way.
Whole numbers, decimals, constants (π, e), complex numbers (i)
Arithmetic operations/functions (addition, subtraction, multiplication, division, brackets, square root, n-th root, GCD, LCM)
Trigonometric functions (sin, cos, tan)
Rounding functions (round, ceil, floor)
List operations (min, max, mean, sum, product)
📚 Examples
Result: ±0.00001 (10^(-5))
🧩Blocks (754)
🧮 Complexities and notes
Time complexity: O(N)
Space complexity O(N)
This program has two catches:
- The expression must be valid or the program may malfunction. For example, undefined functions will return 0.
- Exponents must be surrounded in brackets, e.g.
2*5^6
→2*(5^6)
, or else the expression will be treated as(2*5)^6
. I'm still working on it, though this will raise the time complexity to O(N*E), with E being the number of exponent symbols.
📥Downloads
AIA:
MathParser.aia (22.0 KB)
All materials in this post are licensed under the CC BY-SA 4.0 International license. To credit the author, please include his name (Gordon Lu) and a link to the community post.