Skip to content

A C++ Calculator api to evaluate mathematical expressions.

License

Notifications You must be signed in to change notification settings

mwthinker/Calculator

Repository files navigation

calc::Calculator CI build codecov License: MIT

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.

Code example

#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.

Building project locally

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

Open source

The project is under the MIT license (see LICENSE.txt).

About

A C++ Calculator api to evaluate mathematical expressions.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published