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

Breadcrumb

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

function BigInteger::gcd

Returns the greatest common divisor of this number and the given one.

The GCD is always positive, unless both operands are zero, in which case it is zero.

Parameters

BigNumber|int|float|string $that The operand. Must be convertible to an integer number.:

File

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

Class

BigInteger
An arbitrary-size integer.

Namespace

Brick\Math

Code

public function gcd(BigNumber|int|float|string $that) : BigInteger {
    $that = BigInteger::of($that);
    if ($that->value === '0' && $this->value[0] !== '-') {
        return $this;
    }
    if ($this->value === '0' && $that->value[0] !== '-') {
        return $that;
    }
    $value = Calculator::get()->gcd($this->value, $that->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