PHP Classes

PHP Calculator: Calculate the result of multiple math operations

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 98 All time: 9,836 This week: 206Up
Version License PHP version Categories
taschenrechner 1.0.6Free for non-comm...7PHP 5, Math
Description 

Author

This package can calculate the result of multiple math operations.

It can process multiple math operations with numeric parameters.

A separate class implements each operation. Currently the package supports operations like addition, subtraction, multiplication, division, power, sin, cos, tan, root and grouping of operations.

Innovation Award
PHP Programming Innovation award winner
November 2021
Winner


Prize: One official elePHPant Plush Mascott
Some applications need to be able to perform calculations with dynamic operations and values that are only available at the time when the application code executes.

This package provides a solution for dynamically composing math operations depending on a logic defined by the applications using values for the operations variables that the application determines at execution time.

Manuel Lemos
Picture of stefan
  Performance   Level  
Innovation award
Innovation award
Nominee: 3x

Winner: 1x

 

Example

<?php
   
require_once __DIR__ . '/../vendor/autoload.php';
    use
Taschenrechner\Classes\Calculator;
    use
Taschenrechner\Classes\Operationen\Klammer;
    use
Taschenrechner\Classes\Operationen\KlammerZu;
    use
Taschenrechner\Classes\Operationen\Wurzel;
    use
Taschenrechner\Classes\Operationen\Tan;
    use
Taschenrechner\Classes\Operationen\Cosinus;
    use
Taschenrechner\Classes\Operationen\Sinus;
    use
Taschenrechner\Classes\Operationen\Potenz;
    use
Taschenrechner\Classes\Operationen\Multiplikation;
    use
Taschenrechner\Classes\Operationen\Division;
    use
Taschenrechner\Classes\Operationen\Addition;
    use
Taschenrechner\Classes\Operationen\Subtraktion;
    use
Taschenrechner\Classes\Concatinator;

   
session_start();
    unset(
$_SESSION["exception"]);
    unset(
$_SESSION["ergebnis"]);
    unset(
$_SESSION["term"]);
   
$term = $_GET["term"];
   
    try {
       
//Initialisiere den Taschenrechner
       
$calculator = new Calculator();
       
       
//Füge Operationen hinzu:
        //Deklariere einen Term und übergebe den Term
       
       
$calculator->addOperation(5, new Klammer($calculator, new Concatinator()));
       
$calculator->addOperation(0, new KlammerZu($calculator, new Concatinator()));
       
$calculator->addOperation(4, new Tan($calculator, new Concatinator()));
       
$calculator->addOperation(4, new Cosinus($calculator, new Concatinator()));
       
$calculator->addOperation(4, new Sinus($calculator, new Concatinator()));
       
$calculator->addOperation(3, new Wurzel($calculator, new Concatinator()));
       
$calculator->addOperation(3, new Potenz($calculator, new Concatinator()));
       
$calculator->addOperation(2, new Multiplikation($calculator, new Concatinator()));
       
$calculator->addOperation(2, new Division($calculator, new Concatinator()));
       
$calculator->addOperation(1, new Addition($calculator, new Concatinator()));
       
$calculator->addOperation(1, new Subtraktion($calculator, new Concatinator()));

       
       
       
$ergebnis = $calculator->calculate($term);
       
//Sende das Ergebnis zurück zu Index.php
       
       
$_SESSION["ergebnis"] = $ergebnis;
       
$_SESSION["term"] = $term;
       
       
header("Location: index.php");
   
    } catch(
Exception $exception) {

       
//Sende den Fehler zurück zur Index.php
       
$_SESSION["exception"] = $exception->getMessage();
           
    }
   
$_SESSION["term"] = $term;


   
header("Location: index.php");
?>


Details

A Calculator created in PHP

This is a PHP Calculator which can take a math operation and return the result.

Currently the package supports operations like addition, subtraction, multiplication, division, power, root and grouping of operations.


  Files folder image Files (35)  
File Role Description
Files folder imagepublic (2 files, 1 directory)
Files folder imagetest (14 files)
Accessible without login Plain text file calculator.mdj Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file readme.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:98
This week:0
All time:9,836
This week:206Up