Skip to content

Simple mathematical/logical expression parser and calculator.

License

Notifications You must be signed in to change notification settings

webfactorybulgaria/lib-beeme

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Beeme (Basic Equation/Expression Math Engine)

Simple mathematical expression parser and calculator based on the great work of Adrean Boyadzhiev.

Install

The recommended way to install Beeme is through composer.

{
    "require": {
        "oat-sa/lib-beeme": "dev-master"
    }
}

Basic Usage

Here is an simple example of evaluation of mathematical expression

<?php

$parser = new \oat\beeme\Parser();
$expression = '1 + 2 * 3 * ( 7 * 8 ) - ( 45 - 10 )';
$result = $parser->evaluate($expression);

echo $result; // 302.000000

Constants

Beeme comes with two built-in constants that are "pi" and "e". You can also use custom constans in your expressions, and give them actual values at runtime. Below, an example with the constant "x" replaced by the integer value 3.

<?php

$parser = new \oat\beeme\Parser();
$expression = '3 + x';
$result = $parser->evaluate(
    $expression,
    ['x' => 3]
);

echo $result; // 6.000000

Functions

Beeme provides a set of unary functions to be used in your expressions. Below is an example of using the "abs" function in an expression.

<?php

$expression = '1 + abs(x)';
$result = $parser->evaluate(
    $expression,
    ['x' => -10]
);

echo $result; // 11.000000

Please see the list of available unary functions available in Beeme. They all map to their PHP built-in equivalent:

TODO

  • Always more unit tests
  • N-ary functions

License

MIT, see LICENSE.

About

Simple mathematical/logical expression parser and calculator.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%