mugesh / calculator
A simple calculator package for PHP
Installs: 9
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/mugesh/calculator
Requires
- php: >=7.4
Requires (Dev)
- phpunit/phpunit: ^9.0|^10.0
README
Mugesh Calculator
A simple and lightweight calculator package for PHP that provides basic arithmetic operations.
Installation
You can install this package via Composer:
composer require mugesh/calculator
Usage
<?php require_once 'vendor/autoload.php'; use Mugesh\Calculator\Calculator; $calc = new Calculator(); // Basic operations echo $calc->add(5, 3); // 8 echo $calc->subtract(10, 4); // 6 echo $calc->multiply(6, 7); // 42 echo $calc->divide(15, 3); // 5 // Advanced operations echo $calc->percentage(200, 15); // 30 (15% of 200) echo $calc->power(2, 8); // 256 echo $calc->sqrt(64); // 8
Available Methods
add(float $a, float $b): float- Additionsubtract(float $a, float $b): float- Subtractionmultiply(float $a, float $b): float- Multiplicationdivide(float $a, float $b): float- Division (throws exception for division by zero)percentage(float $value, float $percentage): float- Percentage calculationpower(float $base, float $exponent): float- Power calculationsqrt(float $number): float- Square root (throws exception for negative numbers)
Testing
Run the test suite:
composer test
Or using PHPUnit directly:
vendor/bin/phpunit
Requirements
- PHP 7.4 or higher
License
This package is open-sourced software licensed under the MIT license.