/**
  * @param InformationUnit $unit
  *
  * @return InformationUnit
  * @throws \OutOfBoundsException
  */
 public function subtract(InformationUnit $unit) : self
 {
     $value = self::convert($unit->getAmount(), $unit->getDimensionCode(), $this->getDimensionCode());
     $result = $this->getAmount() - $value;
     if ($result < 0) {
         throw new \OutOfBoundsException('Cannot subtract, less or equal zero result');
     }
     $this->amount = $result;
     return $this;
 }
示例#2
0
 /**
  * Bytes constructor.
  *
  * @param float $amount
  *
  * @throws \OutOfBoundsException
  */
 public function __construct(float $amount)
 {
     parent::__construct($amount);
     $this->dimension = self::$megaByte;
 }