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

gmp_gcd

Description

The gmp_gcd of GMP for PHP calculates the greatest common divisor (GCD).

Syntax

gmp_gcd(
    GMP|int|string $num1,
    GMP|int|string $num2
): GMP

Parameters

num1

A GMP object, an int or a numeric string.

num2

A GMP object, an int or a numeric string.

Return

Returns a positive GMP object that divides into both num1 and num2.

Examples

1 · num1 num2 · GMP

<?

$num1 = -6;
$num2 = 9;

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

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

var_dump($return);

?>
object(GMP)#3 (1) {
  ["num"]=>
  string(1) "3"
}

2 · num1 num2 · int

<?

$num1 = -6;
$num2 = 9;

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

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(1) "3"
}

3 · num1 num2 · string

<?

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

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

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(1) "3"
}
HomeMenu