Friday, November 21, 2025
HomeLanguagesPHP | gmp_div_r() Function

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
// 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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32405 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6781 POSTS0 COMMENTS
Nicole Veronica
11928 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11997 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7166 POSTS0 COMMENTS
Thapelo Manthata
6862 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS