Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2023-05-31 (3 months ago)  | | Not yet rated by the users | | Total: 34 | | All time: 10,809 This week: 94 |
|
Description | | Author peter279k
Contributor
|
This package can perform math calculations using an injected object.
It provides an abstract calculator class that can perform several math calculations with numbers, like adding, subtracting, multiplying, and dividing.
The calculator class takes an injected object that will perform the actual calculations.
The package provides several classes that implement the math operations using different approaches to perform those operations.
Currently, it provides math operations classes that can be used to create objects to inject in the calculator class, like:
- GMP (GNU Multi Precision)
- BCMath (Arbitrary Precision Mathematics) Innovation Award
 June 2023
Number 6 |
Several solutions can work as alternatives when a developer needs to solve a problem.
For instance, a developer may store and retrieve the application data using different databases.
In this case, using different classes that implement the same database access operations with other codes is recommended for accessing different types of databases.
Then the application may write code that works well with different databases.
If, in the future, the developer needs to change the application to use a different type of database, he needs to use an object to access that type of database without needing to change the code of the rest of the application.
In this case, the application uses a database access object and injects it into the code that implements the application.
This approach to separate the application code from the implementation class code that the application depends on is called dependency injection.
This package implements this approach to perform math operations. It provides a main class that implements several types of math operations. It also offers several courses that implement those math operations with different PHP extensions that provide various types of precision.
Manuel Lemos |
| |
 |
|
Innovation award
 Nominee: 12x
Winner: 1x |
|
Details
Dependency Calculator

Introduction
Usage
Here is some examples about how to calculate two numbers.
Add two numbers
use Lee\Calculator\Calculator;
use Lee\Calculator\modules\GmpCalculator;
use Lee\Calculator\modules\BcMathCalculator;
$gmpCalculator = new Calculator(new GmpCalculator());
$bcMathCalculator = new Calculator(new BcMathCalculator());
echo $gmpCalculator->add('123456789', '123456789000000'); // 123456912456789
echo $bcMathCalculator->add('123456789', '123456789000000'); // 123456912456789
Minus two numbers
use Lee\Calculator\Calculator;
use Lee\Calculator\modules\GmpCalculator;
use Lee\Calculator\modules\BcMathCalculator;
$gmpCalculator = new Calculator(new GmpCalculator());
$bcMathCalculator = new Calculator(new BcMathCalculator());
echo $gmpCalculator->minus('123456789', '123456789000000'); // -123456665543211
echo $bcMathCalculator->minus('123456789', '123456789000000'); // -123456665543211
Multiple two numbers
use Lee\Calculator\Calculator;
use Lee\Calculator\modules\GmpCalculator;
use Lee\Calculator\modules\BcMathCalculator;
$gmpCalculator = new Calculator(new GmpCalculator());
$bcMathCalculator = new Calculator(new BcMathCalculator());
echo $gmpCalculator->mul('123456789', '123456789000000'); // 15241578750190521000000
echo $bcMathCalculator->mul('123456789', '123456789000000'); // 15241578750190521000000
Divide two numbers
use Lee\Calculator\Calculator;
use Lee\Calculator\modules\GmpCalculator;
use Lee\Calculator\modules\BcMathCalculator;
$gmpCalculator = new Calculator(new GmpCalculator());
$bcMathCalculator = new Calculator(new BcMathCalculator());
echo $gmpCalculator->divide('123456789000000', '123456789'); // 1000000
echo $bcMathCalculator->divide('123456789000000', '123456789'); // 1000000
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.