Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. BigDecimal.php

function BigDecimal::power

Returns this number exponentiated to the given value.

The result has a scale of `$this->scale * $exponent`.

Throws

\InvalidArgumentException If the exponent is not in the range 0 to 1,000,000.

File

vendor/brick/math/src/BigDecimal.php, line 301

Class

BigDecimal
Immutable, arbitrary-precision signed decimal numbers.

Namespace

Brick\Math

Code

public function power(int $exponent) : BigDecimal {
    if ($exponent === 0) {
        return BigDecimal::one();
    }
    if ($exponent === 1) {
        return $this;
    }
    if ($exponent < 0 || $exponent > Calculator::MAX_POWER) {
        throw new \InvalidArgumentException(\sprintf('The exponent %d is not in the range 0 to %d.', $exponent, Calculator::MAX_POWER));
    }
    return new BigDecimal(Calculator::get()->pow($this->value, $exponent), $this->scale * $exponent);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal