lee / dependency-calculator
This is about simple calculator with depency injection pattern
v1.0
2019-03-23 18:28 UTC
Requires
- php: ^7.1
- ext-bcmath: *
- ext-gmp: *
Requires (Dev)
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-11-20 14:34:35 UTC
README
Introduction
- This is the demonsration for SITCON 2019 talk.
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