PHP Classes

File: public/Classes/Operationen/Cosinus.php

Recommend this page to a friend!
  Classes of stefan   PHP Calculator   public/Classes/Operationen/Cosinus.php   Download  
File: public/Classes/Operationen/Cosinus.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP Calculator
Calculate the result of multiple math operations
Author: By
Last change: resolve error ( and sin( in same term
Date: 2 years ago
Size: 1,044 bytes
 

Contents

Class file image Download
<?php

namespace Taschenrechner\Classes\Operationen;
class
Cosinus extends Operation {
    public function
getSign() {
        return
"cos(";
    }

    public function
calculate($a, $b=NULL) {
        return
cos(deg2rad($a));
    }

    public function
findAndCalculateTerm($term, $operations) {
           
//arbeitet intern mit dem Array
           
$array = preg_split('/(?<!^)(?!$)/u', $term );
              
           
$array = $this->concatinator->concatinateArray($array,$operations);
           
//TODO change numeric to concatinator
            //$array = $this->concatinator->concatinateNumericValues($array);
            //$array = $this->concatinator->concatinateOperations($array);
           
for($i =0; $i < sizeof($array)-1; $i++) {
                if(
$array[$i]=="cos(") {
                   
$array[$i] = $this->calculate($array[$i+1]);
                    unset(
$array[$i+1]);
                    unset(
$array[$i+2]);
                   
$array = array_values($array);
                }
            }
            return
implode("", $array);
    }
}