GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Categories
  • Newsletter
  • Submit
  • Login
  • Awesome C++
  • Math

This view

  • Original page
  • New address

GeezerVison is showing cpp.libhunt.com — ceval Alternatives - C++ Math | LibHunt

  • Subscribe
  • Submit
  • Categories
  • About
  • Login

ceval

A C/C++ library for parsing and evaluation of arithmetic expressions.

erstan logo
Source Code    Changelog
Suggest Changes
Take the C++ Developer Survey - About 6 minutes on the tools, libraries and AI you use with C++. You get the results by email. Take the survey »
Popularity
1.4
Growing
Activity
0.0
Stable
Stars 11
Watchers 2
Forks 4
Last Commit about 4 years ago

Programming language: C
License: MIT License
Tags: Math     Interpreter     Eval     Parse Trees    
Latest version: v1.0.1

ceval alternatives and similar libraries

Based on the "Math" category.
Alternatively, view ceval alternatives based on common mentions on social networks and blogs.

  • GLM

    9.2 7.8 L1 ceval VS GLM
    OpenGL Mathematics (GLM)
    g-truc logo
  • QuantLib

    8.9 9.9 L1 ceval VS QuantLib
    The QuantLib C++ library
    lballabio logo
  • SaaSHub - Software Alternatives and Reviews

    SaaSHub helps you find the best software and product alternatives
    Promo www.saashub.com
    SaaSHub Logo
  • OpenBLAS

    8.7 9.9 ceval VS OpenBLAS
    OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.
    OpenMathLib logo
  • CGal

    8.5 9.9 L1 ceval VS CGal
    The public CGAL repository, see the README below
    CGAL logo
  • ceres-solver

    8.2 9.1 L1 ceval VS ceres-solver
    A large scale non-linear optimization library
    ceres-solver logo
  • Eigen

    7.1 - ceval VS Eigen
    A high-level C++ library of template headers for linear algebra, matrix and vector operations, numerical solvers and related algorithms. [MPL2]
  • TinyExpr

    6.6 7.2 L4 ceval VS TinyExpr
    tiny recursive descent expression parser, compiler, and evaluation engine for math expressions
    codeplea logo
  • Vc

    6.0 3.6 L1 ceval VS Vc
    SIMD Vector Classes for C++
    VcDevel logo
  • ExprTK

    5.8 0.0 L1 ceval VS ExprTK
    C++ Mathematical Expression Parsing And Evaluation Library https://www.partow.net/programming/exprtk/index.html
    ArashPartow logo
  • linmath.h

    5.3 0.0 ceval VS linmath.h
    a lean linear math library, aimed at graphics programming. Supports vec3, vec4, mat4x4 and quaternions
    datenwolf logo
  • HLSL++

    5.2 7.4 ceval VS HLSL++
    Math library using HLSL syntax with multiplatform SIMD support
    redorav logo
  • MIRACL

    5.2 0.0 L1 ceval VS MIRACL
    MIRACL Cryptographic SDK: Multiprecision Integer and Rational Arithmetic Cryptographic Library is a C software library that is widely regarded by developers as the gold standard open source SDK for elliptic curve cryptography (ECC).
    miracl logo
  • LibTomMath

    5.2 6.7 L2 ceval VS LibTomMath
    LibTomMath is a free open source portable number theoretic multiple-precision integer library written entirely in C.
    libtom logo
  • NT2

    5.0 5.6 ceval VS NT2
    DISCONTINUED. A SIMD-optimized numerical template library that provides an interface with MATLAB-like syntax. [Boost]
  • Klein

    4.6 0.0 ceval VS Klein
    DISCONTINUED. P(R*_{3, 0, 1}) specialized SIMD Geometric Algebra Library
  • muparser

    4.5 6.6 L1 ceval VS muparser
    muparser is a fast math parser library for C/C++ with (optional) OpenMP support.
    beltoforion logo
  • GMTL

    3.8 0.0 L1 ceval VS GMTL
    Generic Math Template Library (forked from http://ggt.sourceforge.net/)
    imvu logo
  • Boost.Multiprecision

    3.8 6.6 L1 ceval VS Boost.Multiprecision
    Boost.Multiprecision
    boostorg logo
  • safe_numerics

    3.4 3.1 ceval VS safe_numerics
    Replacements to standard numeric types which throw exceptions on errors
    boostorg logo
  • Apophenia

    3.2 2.0 L2 ceval VS Apophenia
    A C library for statistical and scientific computing
    b-k logo
  • Wykobi

    3.2 0.0 ceval VS Wykobi
    Wykobi C++ Computational Geometry Library https://www.wykobi.com
    ArashPartow logo
  • blaze

    3.1 - ceval VS blaze
    high-performance C++ math library for dense and sparse arithmetic. [BSD]
  • Versor

    1.8 0.0 ceval VS Versor
    [older version] Versor 1.0 C++ library for conformal geometric algebra draw routines
    wolftype logo
  • metamath

    1.7 0.0 ceval VS metamath
    Meta mathematics. Symbolic functions and derivatives.
    egladysh logo
  • SLIMCPP

    1.7 4.9 ceval VS SLIMCPP
    Simple Long Integer Math for C++. Lightweight cross-platform header-only library what implements big integer arithmetic in С++17.
    devatrun logo
  • Xerus

    1.6 0.0 ceval VS Xerus
    A general purpose library for numerical calculations with higher order tensors, Tensor-Train Decompositions / Matrix Product States and other Tensor Networks
    libxerus logo
  • Mission : Impossible (AutoDiff)

    1.4 0.0 ceval VS Mission : Impossible (AutoDiff)
    A concise C++17 implementation of automatic differentiation (operator overloading)
    vincent-picaud logo
  • macadam

    0.9 0.0 ceval VS macadam
    DISCONTINUED. Numerical library. Complete BLAS. Hybrid cpp98/cpp11 c99/c11
  • Armadillo

    - ceval VS Armadillo
    A high quality C++ linear algebra library, aiming towards a good balance between speed and ease of use. The syntax (API) is deliberately similar to Matlab. [MPL2]
  • GMP

    - ceval VS GMP
    A C/C++ library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating-point numbers. [LGPL3 & GPL2]

* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.

Do you think we are missing an alternative of ceval or a related project?

Add another 'Math' Library

Popular Comparisons

  • ceval
    vs
    TinyExpr
  • ceval
    vs
    ExprTK
  • ceval
    vs
    GMTL
  • ceval
    vs
    GMP
  • ceval
    vs
    ceres-solver

README

ceval

A C/C++ header for parsing and evaluation of arithmetic expressions.

Functions accessibe from main()

FunctionArgument(s)Return Value ceval_result() A mathematical expression in the form of a character array or a CPP string The result of the expression as a floating point number ceval_tree() A mathematical expression in the form of a character array or a CPP string The function prints the parse tree with each node properly indented depending on it's location in the tree structure

Supported expressions

Any valid combination of the following operators and functions, with floating point numbers (in decimal or exponential form) as operands can be parsed by ceval. Parentheses can be used to override the default operator precedences.

  • Arithematic operators

+ (addition), - (subtraction), * (multiplication), / (division), % (modulo), ** (exponentiation), // (quotient)

  • Relational operators

== (equal), != (not equal), < (strictly less), > (strictly greater), <= (less or equal), >= (greater or equal) to compare the results of two expressions

  • Single-argument functions

exp(), sqrt(), cbrt(), sin(), cos(), tan(), asin(), acos(), atan(), sinh(), cosh(), tanh(), abs(), ceil(), floor(), log10(), ln(), deg2rad(), rad2deg(), signum(), int(), frac(), fact()

  • Two-argument functions

pow(), atan2(), gcd(), hcf(), lcm(), log() (generalized log(b, x) to any base b)

  • Pre-defined math constants

pi, e

  • Logical operators

&&, || and !

  • Bitwise operators

&, |, ^, <<, >>, ~

  • Other operators

    • , (Comma operator) Comma operator returns the result of it's rightmost operand Ex: 2,3 would give 3; 4,3,0 would be equal to 0; and cos(pi/2,pi/3,pi) would return cos(pi) i.e, -1

Installation

From source:

git clone https://github.com/erstan/ceval.git /tmp/ceval && \
cd /tmp/ceval && \
sudo make install

Or install the latest release with the clib package manager:

clib install erstan/ceval -o /tmp/ceval

Usage

After the installation, just include the ceval library using #include<ceval/ceval.h> directive in your C/C++ project.

The code snippet given below is a console based interpreter that interactively takes in math expressions from stdin, and prints out their parse trees and results.

//lang=c
#include<stdio.h>
#include<stdlib.h>

#include<ceval/ceval.h>

int main(int argc, char ** argv) {
  char expr[100];
  while (1) {
    printf("In = ");
    fgets(expr, 100, stdin);
    if (!strcmp(expr, "exit\n")) {
      break;
    } else if (!strcmp(expr, "clear\n")) {
      system("clear");
      continue;
    } else {
      ceval_tree(expr);
      printf("\nOut = %f\n\n", ceval_result(expr));
    }
  }
  return 0;
}

The same interpreter can be implemented in C++ as follows

//lang=cpp
#include<iostream>
#include<cstdlib>
#include<string>

#include<ceval/ceval.h>

int main(int argc, char ** argv) {
  std::string expr;
  while (1) {
    printf("In = ");
    std::cin >> expr;
    if (expr=="exit") {
      break;
    } else if (expr=="clear") {
      system("clear");
      continue;
    } else {
      ceval_tree(expr);
      std::cout << "\nOut = " << ceval_result(expr) << "\n\n";
    }
  }
  return 0;
}

Test Run

In = 3*7**2
                2
        **
                7
*
        3

Out = 147.000000


In = (3.2+2.8)/2
        2
/
                2.80
        +
                3.20

Out = 3.000000


In = e**pi>pi**e
                e
        **
                pi
>
                pi
        **
                e

Out = 1.000000


In = 5.4%2
        2
%
        5.40

Out = 1.400000


In = 5.4//2
        2
//
        5.40

Out = 2.000000


In = 2*2.0+1.4
        1.40
+
                2
        *
                2

Out = 5.400000


In = (5/4+3*-5)+(sin(pi))**2+(cos(pi))**2
                2
        **
                        pi
                cos
+
                        2
                **
                                pi
                        sin
        +
                                        5
                                -
                        *
                                3
                +
                                4
                        /
                                5

Out = -12.750000


In = 3,4,5,6
        6
,
                5
        ,
                        4
                ,
                        3

Out = 6.000000


In = tanh(2/3)==(sinh(2/3)/cosh(2/3))
                                3
                        /
                                2
                cosh
        /
                                3
                        /
                                2
                sinh
==
                        3
                /
                        2
        tanh

Out = 1.000000


In = (2+3/3+(3+9.7))
                9.70
        +
                3
+
                        3
                /
                        3
        +
                2

Out = 15.700000


In = sin(pi/2)+cos(pi/2)+tan(pi/2)
                        2
                /
                        pi
        tan
+
                                2
                        /
                                pi
                cos
        +
                                2
                        /
                                pi
                sin

[ceval]: tan() is not defined for odd-integral multiples of pi/2

Out = nan


In = asin(2)
        2
asin

[ceval]: Numerical argument out of domain

Out = nan


In = exit
... Program finished with exit code 0

Stoic mode

The inbuilt functions in ceval print out error messages to stdout when some syntactical anomaly is encountered during the parsing and evaluation process. To suppress the error messages, define the CEVAL_STOICAL macro before including the library in a C/C++ project. In the stoic mode, problematic expressions are evaluated to nan.

#define CEVAL_STOICAL
#include<ceval/ceval.h>
.
.
.

Do not miss the trending, libraries, news and articles with our weekly report.

Awesome C++ is part of the LibHunt network. Terms. Privacy Policy.

(CC)
BY-SA
Spin The Wheel Of Names for a cryptographically secure random name picker.
Schedule a when to meet poll.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.