The gmp_powm() is an inbuilt function in PHP which is used to calculate the number raised to a power of two GMP numbers modulo of another GMP number.(GNU Multiple Precision: For large numbers)
gmp_pow( $base, $exp, $mod)
Parameters: The function accepts three mandatory parameters $base, $exp and $mod
- $base – It is the base number.
- $exp – It is the power which is raised to the base.
- $mod – It returns the remainder after division with $mod
Note: All the parameters are a GMP object in PHP version 5.6 and later, or we are also allowed to pass a numeric string provided that it is possible to convert that string to a number.
Return Value: This function returns a positive GMP number which is equivalent to (baseexp)%mod
Input : $base = "2" $exp = "2" $mod = 3 Output : 1 Input : $base = "4" $exp = "2" $mod = 10 Output : 6
Below programs illustrate the gmp_powm() function:
Program 1: The program below demonstrates the working of gmp_powm() function when GMP number are passed as arguments.
Program 2: The program below demonstrates the working of gmp_powm() when numeric string are passed as arguments.