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

Breadcrumb

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

function BigInteger::sqrt

Returns the integer square root number of this number, rounded down.

The result is the largest x such that x² ≤ n.

Throws

NegativeNumberException If this number is negative.

File

vendor/brick/math/src/BigInteger.php, line 670

Class

BigInteger
An arbitrary-size integer.

Namespace

Brick\Math

Code

public function sqrt() : BigInteger {
    if ($this->value[0] === '-') {
        throw new NegativeNumberException('Cannot calculate the square root of a negative number.');
    }
    $value = Calculator::get()->sqrt($this->value);
    return new BigInteger($value);
}

API Navigation

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