A Calculator api created in C++. The goal for the api is to take a mathematical expression and calculate the value at runtime.
The project uses C++20 and the C++ Standard Library.
#include <iostream>
#include <string>
#include <calc/calculator.h>
int main() {
calc::Calculator calculator;
std::cout << "1 - (-(2^2)) - 1 = " << calculator.excecute("1 - (-(2^2)) - 1") << "\n";
calculator.addVariable("pi", 3.1416f);
std::cout << "2^2 * pi" << calculator.excecute("2^2 * pi") << "\n";
return 0;
}
Output:
1 - (-(2^2)) - 1 = 4.0
2^2 * pi = 12.5664
For more example code see Calculator_Benchmark or Calculator_Test.
CMake and vcpkg can be used to run the repository locally.
Inside the project folder, e.g.
cmake --preset=unix -B build -DCalculator_Test=1; cmake --build build; ctest --test-dir build/Calculator_Test
./build/Signal_Example/Signal_Example
The project is under the MIT license (see LICENSE.txt).