
PHP gmp_div_qr() Function
As of my last update in September 2021, the gmp_div_qr()
function in PHP is used to calculate the quotient and remainder of the division of two GMP numbers. GMP (GNU Multiple Precision) is an extension in PHP that allows working with arbitrary precision numbers.
Here’s the syntax of the gmp_div_qr()
function:
array gmp_div_qr ( GMP $num , GMP $den )
Parameters:
$num
: The GMP number (numerator) to be divided.$den
: The GMP number (denominator) by which$num
is divided.
Return value:
- An array containing two elements:
- The first element is the quotient as a GMP number.
- The second element is the remainder as a GMP number.
Here’s a simple example demonstrating the usage of gmp_div_qr()
:
$numerator = gmp_init('12345678901234567890');
$denominator = gmp_init('12345');
$result = gmp_div_qr($numerator, $denominator);
$quotient = $result[0];
$remainder = $result[1];
echo "Quotient: " . gmp_strval($quotient) . PHP_EOL;
echo "Remainder: " . gmp_strval($remainder) . PHP_EOL;
Remember to make sure that the GMP extension is enabled in your PHP configuration. The gmp_div_qr()
function won’t work without it. Also, please note that the availability of functions may change in newer versions of PHP, so always consult the PHP manual for the version you are using.
It’s worth noting that the GMP extension provides other arithmetic functions for working with arbitrary precision numbers, such as gmp_add()
, gmp_sub()
, gmp_mul()
, and more. You can refer to the PHP manual for a comprehensive list of GMP functions and their descriptions.