PHP Classes

PHP Dependency Injection Calculator: Perform math calculations using an injected object

Recommend this page to a friend!
  Info   View files Documentation   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2023-05-31 (16 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 32 This week: 3All time: 10,791 This week: 43Up
Version License PHP version Categories
dependency-calculato 1.0.0MIT/X Consortium ...7Math, Design Patterns, PHP 7
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)

Picture of Chun-Sheng, Li
  Performance   Level  
Name: Chun-Sheng, Li <contact>
Classes: 21 packages by
Country: Taiwan Taiwan
Innovation award
Innovation award
Nominee: 11x

Winner: 1x

Details

Dependency Calculator

build Coverage Status

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
  Files folder image Files  
File Role Description
Files folder image.github (1 directory)
Files folder imagesrc (1 file, 2 directories)
Files folder imagetests (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file build.yml Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageinterfaces (1 file)
Files folder imagemodules (2 files)
  Plain text file Calculator.php Class Class source

  Files folder image Files  /  src  /  interfaces  
File Role Description
  Plain text file Calculator.php Class Class source

  Files folder image Files  /  src  /  modules  
File Role Description
  Plain text file BcMathCalculator.php Class Class source
  Plain text file GmpCalculator.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file CalculatorTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:32
This week:3
All time:10,791
This week:43Up