Open In App

PHP | gmp_div_r() Function

Improve
Improve
Like Article
Like
Save
Share
Report

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
// PHP program to perform the division of
// GMP numbers
   
// creating GMP numbers using gmp_init()
$num1 = gmp_init(257);
$num2 = gmp_init(17);
  
// calculates the remainder when
//  $num1 is divided by num2
 
$res = gmp_div_r($num1, $num2);
// Display the remainder
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
// PHP program to perform the division of
// GMP numbers
   
// creating GMP number using gmp_init()
$a = gmp_init("7891267541121");
  
// calculates the remainder when
// $a is divided by 115789034
$res = gmp_div_r($a, 115789034);
 
// Display the remainder
echo $res;
?>


Output

13295953

Reference : http://php.net/manual/en/function.gmp-div-r.php



Last Updated : 31 May, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads