Пример #1
0
 /**
  * Returns this number exponentiated to the given value.
  *
  * The result has a scale of `$this->scale * $exponent`.
  *
  * @param int $exponent The exponent.
  *
  * @return BigDecimal The result.
  *
  * @throws \InvalidArgumentException If the exponent is not in the range 0 to 1,000,000.
  */
 public function power($exponent)
 {
     $exponent = (int) $exponent;
     if ($exponent === 0) {
         return self::one();
     }
     if ($exponent === 1) {
         return $this;
     }
     if ($exponent < 0 || $exponent > Math::MAX_POWER) {
         throw new \InvalidArgumentException(sprintf('The exponent %d is not in the range 0 to %d.', $exponent, Math::MAX_POWER));
     }
     return new self($this->intVal->power($exponent), $this->scale * $exponent);
 }