Skip to content
SivaPA08Public

About

Lightweight C++ mathematical expression evaluator header file

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

10 Commits

Folders and files

Repository files navigation

evalpp

Lightweight C++ mathematical expression evaluator.


Features

  • Arithmetic operators
  • Bitwise operators
  • Logical operators
  • Comparison operators
  • Ternary operator
  • Mathematical functions
  • Constants (pi, e)
  • Single-header
  • C++17
  • No dependencies

Installation

#include "evalpp.hpp"

Usage

#include "evalpp.hpp"
#include <iostream>

int main() {

    std::cout << evalpp::eval("1+2*3") << '\n';

    std::cout << evalpp::eval("pow(2,5)") << '\n';

    std::cout << evalpp::eval("sin(pi/2)") << '\n';
}

Supported Operators

Type Operators
Arithmetic + - * / %
Bitwise & | ^ ~ << >>
Logical && || !
Comparison == != < <= > >=
Ternary ?:

Supported Functions

Function Example
sin(x) sin(pi/2)
cos(x) cos(0)
tan(x) tan(1)
asin(x) asin(1)
acos(x) acos(1)
atan(x) atan(1)
sqrt(x) sqrt(25)
pow(x,y) pow(2,10)
log(x) log(e)
log10(x) log10(100)
exp(x) exp(1)
abs(x) abs(-5)
floor(x) floor(2.9)
ceil(x) ceil(2.1)
round(x) round(2.6)
min(...) min(5,2,9)
max(...) max(5,2,9)

Constants

Constant Value
pi 3.1415926535...
e 2.7182818284...

Examples

evalpp::eval("1+2*3")
evalpp::eval("(1+2)*3")

evalpp::eval("5&3")
evalpp::eval("1<<4")

evalpp::eval("sin(pi/2)")
evalpp::eval("pow(2,10)")

evalpp::eval("5>3 ? 100 : 0")

About

Lightweight C++ mathematical expression evaluator header file

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages