All Projects → kimwalisch → calculator

kimwalisch / calculator

Licence: BSD-2-Clause license
C++ operator precedence parser

Programming Languages

C++
36643 projects - #6 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to calculator

WarpPI
WarpPI Calculator, Step-by-step algebra calculator for Raspberry Pi. (abandoned project)
Stars: ✭ 93 (+27.4%)
Mutual labels:  calculator
availability-calculator
Calculate how much downtime should be permitted in your Service Level Agreement or Objective
Stars: ✭ 60 (-17.81%)
Mutual labels:  calculator
shellmath
Yes, Virginia, you can do floating-point arithmetic in Bash!
Stars: ✭ 33 (-54.79%)
Mutual labels:  calculator
netcalc
Advanced network calculator and address planning helper
Stars: ✭ 20 (-72.6%)
Mutual labels:  calculator
mathpad
Interactive scratchpad calculator for VS Code
Stars: ✭ 20 (-72.6%)
Mutual labels:  calculator
uniswapv3-calculator
An all-in-one platform for Uniswap liquidity providers (prev Uniswap Calculator)
Stars: ✭ 131 (+79.45%)
Mutual labels:  calculator
kalker
Kalker/kalk is a calculator with math syntax that supports user-defined variables and functions, complex numbers, and estimation of derivatives and integrals
Stars: ✭ 1,237 (+1594.52%)
Mutual labels:  calculator
calculator
Calculator app designed for elementary OS
Stars: ✭ 73 (+0%)
Mutual labels:  calculator
asm-docs
Documentation about native assembly programming on the TI CE calculators (84+CE / 83PCE)
Stars: ✭ 41 (-43.84%)
Mutual labels:  calculator
react-calculator
📐 PWA React + Redux Calculator
Stars: ✭ 65 (-10.96%)
Mutual labels:  calculator
Kelvin
A powerful language for symbolic computation written in Swift.
Stars: ✭ 23 (-68.49%)
Mutual labels:  calculator
attribute-depends-calculator
Automatically calculate a collection of depends attribute of ActiveRecord
Stars: ✭ 41 (-43.84%)
Mutual labels:  calculator
Sm4sh-Calculator
Web based Smash 4 knockback calculator
Stars: ✭ 12 (-83.56%)
Mutual labels:  calculator
bc
some useful math functions for linux calculator bc
Stars: ✭ 18 (-75.34%)
Mutual labels:  calculator
DevHelpBox
we are creating this community so that other developers can get benefits of it.
Stars: ✭ 35 (-52.05%)
Mutual labels:  calculator
Calcu
CALCULADORAS
Stars: ✭ 22 (-69.86%)
Mutual labels:  calculator
SwiftUICalculator
A calculator app using SwiftUI which is introduced in WWDC19
Stars: ✭ 33 (-54.79%)
Mutual labels:  calculator
cvss
CVSS (Common Vulnerability Scoring System) Calculator CVSSv3.1
Stars: ✭ 35 (-52.05%)
Mutual labels:  calculator
nano-id-cc
Nano ID collision calculator
Stars: ✭ 31 (-57.53%)
Mutual labels:  calculator
Love-Calculator
Let's Calculate love with real data. Love Calculator by Mohammed Cha
Stars: ✭ 54 (-26.03%)
Mutual labels:  calculator

calculator

calculator.hpp is a header-only C++ library for parsing and evaluating integer arithmetic expressions e.g. "10 * (7 - 1)". It compiles with any C++ compiler and works with any integer type e.g. int, long, uint64_t.

calculator is a simple but fast operator-precedence parser.

Supported operators

calculator.hpp uses the same operator precedence and associativity as the C++ programming language and also supports the power operator.

Operator Description
| Bitwise Inclusive OR
^ Bitwise Exclusive OR
& Bitwise AND
~ Unary Complement
<< Shift Left
>> Shift Right
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo
** Raise to power

C++ API

Functions defined in calculator.hpp.

int calculator::eval(const std::string& expression);

template <typename T>
T calculator::eval<T>(const std::string& expression);

How to use it

calculator::eval("1+2") takes a string with an integer arithmetic expression as an argument, evaluates the arithmetic expression and returns the result. If the expression string is not a valid integer arithmetic expression a calculator::error exception is thrown.

#include "calculator.hpp"
#include <stdint.h>
#include <iostream>

int main()
{
    try
    {
        int result = calculator::eval("(0 + ~(255 & 1000)*3) / -2");
        std::cout << result << std::endl;
    
        // 64-bit arithmetic
        int64_t r64 = calculator::eval<int64_t>("2**60");
        std::cout << r64 << std::endl;
    }
    catch (calculator::error& e)
    {
        std::cerr << e.what() << std::endl;
    }

    return 0;
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].