Esempio n. 1
0
 /**
  * Calculate a mathematical expression that uses pokemath-numbers
  *
  * @param $expression
  *
  * @return Number
  */
 public function calculate($expression)
 {
     $translatedExpression = $this->translate($expression);
     $result = eval('return ' . $translatedExpression . ';');
     $decimalResult = new Number($result);
     // this is bad and needs some work
     return $decimalResult->convert($this->numberSystem);
 }
 /**
  * Parse the part of an expression.
  *
  * @param $part
  *
  * @return Number
  */
 protected function parseExpressionPart($part, NumberSystem $sourceSystem, NumberSystem $targetSystem)
 {
     try {
         // if it is a valid number of the source-system convert it
         $sourceNumber = new Number($part, $sourceSystem);
         return $sourceNumber->convert($targetSystem)->value();
     } catch (NumberParseException $e) {
         return $part;
     }
 }