The gmp_divexact() is a built-in function in PHP which is used to check whether a GMP number(GNU Multiple Precision : For large numbers) is exactly divisible by another GMP number or not. If it so happens then function returns the exact result else any other irrelevant GMP number.
Parameters: This function accepts two GMP numbers, $num1, $num2 as mandatory parameters as shown in the above syntax. These parameters can be GMP objects in PHP version 5.6 and later, or we are also allowed to pass numeric strings such that it is possible to convert those strings to numbers.
Return Value: This function uses fast division algorithm and checks if the division is possible or not and thus returns the result of division as a GMP number.
Input : gmp_divexact("15", "5") Output : 3 Input : gmp_divexact("13", "3") Output : 12297829382473034415
Below programs illustrate the gmp_divexact() function in PHP:
Program 1: Program to perform “exact division” algorithm on GMP numbers when numeric strings as GMP numbers are passed as arguments.
Program 2: Program to perform “exact division” algorithm on GMP numbers when GMP numbers are passed as arguments.
Program 3: Program to perform “exact division” algorithm on GMP numbers when GMP numbers are passed as arguments.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.