mathematicator-core / calculator
高级PHP数学计算器,支持复杂数学运算。
v3.0.2
2021-02-22 19:13 UTC
Requires
- php: ^8.0
- baraja-core/url: ^1.1
- brick/math: ^0.8.15 || ^0.9.0
- mathematicator-core/engine: ^2.0 || ^3.0
- mathematicator-core/numbers: ^2.1
- mathematicator-core/tokenizer: ^2.1 || ^3.0
- nette/application: ^3.0
- nette/caching: ^3.0
- nette/di: ^3.0
- nette/utils: ^3.0
- symfony/polyfill-php80: ^1.17
Requires (Dev)
- brainmaestro/composer-git-hooks: dev-master
- jetbrains/phpstorm-attributes: ^1.0
- nette/bootstrap: ^3.0
- nette/tester: ~2.3.2
- phpstan/phpstan: ^0.12.74
- phpstan/phpstan-nette: ^0.12.14
- roave/security-advisories: dev-master
- spaze/phpstan-disallowed-calls: ^1.1
- tracy/tracy: ^2.8
Suggests
- ext-bcmath: For faster math operations
- ext-gmp: Alternative for faster math operations
- nette/caching: (^3.0) To use package in Nette Framework
- nette/di: (^3.0) To use package in Nette Framework
This package is auto-updated.
Last update: 2024-08-30 01:12:22 UTC
README
高级PHP计算器
简单易用的模块化计算器,具有解决方案步骤和结果解释。
强烈建议确保您已经在您的PHP服务器上启用了BCMath或GMP扩展,以便进行更快的计算。
安装
composer require mathematicator-core/calculator
想法
想象一下,您想要计算某个数学问题,例如
(5 + 3) * (2 / (7 + 3))
如何计算它?非常简单
$calculator = new Calculator(/* some dependencies */); echo $calculator->calculateString('(5 + 3) * (2 / (7 + 3))'); // \frac{8}{5}
方法calculateString()
返回实现__toString()
方法的实体CalculatorResult
。
高级使用是通过Tokenizer
创建的令牌数组
$tokenizer = new Tokenizer(/* some dependencies */); // Convert math formule to array of tokens: $tokens = $tokenizer->tokenize('(5+3)*(2/(7+3))'); // Now you can convert tokens to more useful format: $objectTokens = $tokenizer->tokensToObject($tokens); $calculator->calculate($objectTokens);
Mathematicator框架工具结构
最大的优势是您可以选择最适合您需求的层,并立即在此基础上构建,无需自行创建一切。我们的工具经过错误检测和性能调优,因此您可以节省大量的时间、金钱和精力。
框架尽可能模块化,因此您应该能够在每一层及其子层上创建扩展。
Mathematicator框架层 从最具体的一层到最抽象的一层排序
第三方包
⚠️ 不保证!
贡献
请通过发送Pull请求来帮助改进此文档。
测试
所有新贡献都应在/tests
目录中包含其单元测试。
在您发送PR之前,请检查所有测试是否通过。
此包使用Nette Tester。您可以通过命令运行测试
composer test
在PR之前,请通过命令运行完整的代码检查
composer cs:install # only first time composer fix # otherwise pre-commit hook can fail