PHP | gmp_powm() Function
Last Updated :
14 Mar, 2022
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)
Syntax:
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
Examples:
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.
php
<?php
$base = gmp_init("100", 2);
$exp = gmp_init("10", 2);
$mod = gmp_init("1010", 2);
$powm = gmp_powm( $base , $exp , $mod );
echo gmp_strval( $powm , 2);
?>
|
Output:
110
Program 2: The program below demonstrates the working of gmp_powm() when numeric string are passed as arguments.
php
<?php
$base = "4";
$exp = "2";
$mod = "10";
$powm = gmp_powm( $base , $exp , $mod );
echo $powm ;
?>
|
Output:
6
Reference:
http://php.net/manual/en/function.gmp-powm.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...