Cover Image for PHP gmp_gcd() Function
233 views

PHP gmp_gcd() Function

As of my last update in September 2021, the gmp_gcd() function is available in PHP’s GMP (GNU Multiple Precision) extension. The gmp_gcd() function is used to calculate the greatest common divisor (GCD) of two GMP numbers.

Here’s the syntax of the gmp_gcd() function:

GMP gmp_gcd ( GMP $a , GMP $b )

Parameters:

  • $a: The first GMP number.
  • $b: The second GMP number.

Return value:

  • The gmp_gcd() function returns a GMP number representing the greatest common divisor of $a and $b.

Example:

$a = gmp_init('24');
$b = gmp_init('36');

$gcd = gmp_gcd($a, $b);

echo "Greatest Common Divisor of 24 and 36 is: " . gmp_strval($gcd); // Output: 12

In this example, the gmp_gcd() function is used to calculate the GCD of the GMP numbers 24 and 36. The result is 12, which is the greatest common divisor of 24 and 36.

The GCD represents the largest positive integer that divides both input numbers without leaving a remainder. It has various applications in number theory, cryptography, and mathematical calculations.

Please note that the GMP extension needs to be enabled in your PHP configuration to use this function. Additionally, the availability of functions may change in newer PHP versions, so always refer to the PHP manual for the specific version you are using.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS