PHP | gmp_div_r() Function
The gmp_div_r() function is an in-built function in PHP which performs the division operation between two GMP numbers (GNU Multiple Precision : For large numbers) and returns the remainder. Syntax :
gmp_div_r($num1, $num2)
Parameters : This function accepts two GMP numbers, $num1 and $num2 as mandatory parameters as shown in the above syntax. These parameters can be GMP objects in PHP version 5.6 and later, or numeric strings can be passed to the function provided that it is possible to convert those strings to numbers. Return Value : This function returns a GMP number which is the remainder of the division. Examples:
Input : $num1 = 146, $num2 = 12
Output : 2
Input : $num1 = "189126457831", $num2 = "12098123409"
Output : 7654606696
Below programs will illustrate the use of gmp_div_r() function. Program 1 : Program to perform the division of GMP numbers when GMP numbers are passed as arguments.
php
<?php
$num1 = gmp_init(257);
$num2 = gmp_init(17);
$res = gmp_div_r( $num1 , $num2 );
echo $res ;
?>
|
Output
2
Program 2 : Program to perform the division of GMP numbers when numeric strings as GMP numbers are passed as arguments.
php
<?php
$a = gmp_init("7891267541121");
$res = gmp_div_r( $a , 115789034);
echo $res ;
?>
|
Output
13295953
Reference : http://php.net/manual/en/function.gmp-div-r.php
Last Updated :
31 May, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...