mathematicator-core / calculator
Advance PHP math calculator with complex operations.
Installs: 2 940
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 2
Open Issues: 1
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-11-30 01:50:52 UTC
README
Advance PHP Calculator
Simple to use modular calculator with steps to solution and result explanation.
It is highly recommended to make sure you have enabled BCMath or GMP extension on your PHP server for much faster calculations.
Installation
composer require mathematicator-core/calculator
Idea
Imagine you want compute some math problem, for instance:
(5 + 3) * (2 / (7 + 3))
How to compute it? Very simply:
$calculator = new Calculator(/* some dependencies */); echo $calculator->calculateString('(5 + 3) * (2 / (7 + 3))'); // \frac{8}{5}
Method calculateString()
returns entity CalculatorResult
that implements __toString()
method.
Advance use is by an array of tokens created by 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 Framework tools structure
The biggest advantage is that you can choose which layer best fits your needs and start build on the top of it, immediately, without the need to create everything by yourself. Our tools are tested for bugs and tuned for performance, so you can save a significant amount of your time, money, and effort.
Framework tend to be modular as much as possible, so you should be able to create an extension on each layer and its sublayers.
Mathematicator framework layers ordered from the most concrete one to the most abstract one:
Third-party packages:
⚠️ Not guaranteed!
Contribution
Please help improve this documentation by sending a Pull request.
Tests
All new contributions should have its unit tests in /tests
directory.
Before you send a PR, please, check all tests pass.
This package uses Nette Tester. You can run tests via command:
composer test
Before PR, please run complete code check via command:
composer cs:install # only first time composer fix # otherwise pre-commit hook can fail