HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

gmp_gcdext

Description

The gmp_gcdext of GMP for PHP calculates the greatest common divisor (GCD) and multipliers.

Syntax

gmp_gcdext(
    GMP|int|string $num1,
    GMP|int|string $num2
): array

Parameters

num1

A GMP object, an int or a numeric string.

num2

A GMP object, an int or a numeric string.

Return

Returns an array of GMP objects.

gcd(a,b) = g = a*s + b*t

Examples

1 · num1 num2 · GMP

<?

$num1 = -6;
$num2 = 9;

$num1 = gmp_init($num1);
$num2 = gmp_init($num2);

$return = gmp_gcdext($num1, $num2);

var_dump($return);
array(3) {
  ["g"]=>
  object(GMP)#3 (1) {
    ["num"]=>
    string(1) "3"
  }
  ["s"]=>
  object(GMP)#4 (1) {
    ["num"]=>
    string(1) "1"
  }
  ["t"]=>
  object(GMP)#5 (1) {
    ["num"]=>
    string(1) "1"
  }
}

2 · num1 num2 · int

<?

$num1 = -6;
$num2 = 9;

$return = gmp_gcdext($num1, $num2);

var_dump($return);
array(3) {
  ["g"]=>
  object(GMP)#1 (1) {
    ["num"]=>
    string(1) "3"
  }
  ["s"]=>
  object(GMP)#2 (1) {
    ["num"]=>
    string(1) "1"
  }
  ["t"]=>
  object(GMP)#3 (1) {
    ["num"]=>
    string(1) "1"
  }
}

3 · num1 num2 · string

<?

$num1 = "-6";
$num2 = "9";

$return = gmp_gcdext($num1, $num2);

var_dump($return);
array(3) {
  ["g"]=>
  object(GMP)#1 (1) {
    ["num"]=>
    string(1) "3"
  }
  ["s"]=>
  object(GMP)#2 (1) {
    ["num"]=>
    string(1) "1"
  }
  ["t"]=>
  object(GMP)#3 (1) {
    ["num"]=>
    string(1) "1"
  }
}