oat-sa/lib-beeme
最新稳定版本:0.2.0
Composer 安装命令:
composer require oat-sa/lib-beeme
包简介
Simple mathematical expression/equation parser and calculator.
README 文档
README
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.
统计信息
- 总下载量: 160.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 3
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-04-04