Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2023-05-31 (16 days ago) | | Not yet rated by the users | | Total: 32 This week: 3 | | All time: 10,791 This week: 43 |
|
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
Nominee: 11x
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.