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

v1.0.1 2025-07-02 12:14 UTC

This package is auto-updated.

Last update: 2025-12-18 06:25:24 UTC


README

Latest Version on Packagist Total Downloads Monthly Downloads Daily Downloads PHP Version Required License on Packagist

Build Status Last Commit Open Issues Pull Requests GitHub Stars GitHub Forks

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 - Addition
  • subtract(float $a, float $b): float - Subtraction
  • multiply(float $a, float $b): float - Multiplication
  • divide(float $a, float $b): float - Division (throws exception for division by zero)
  • percentage(float $value, float $percentage): float - Percentage calculation
  • power(float $base, float $exponent): float - Power calculation
  • sqrt(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.