VOOZH about

URL: https://www.geeksforgeeks.org/php/php-gmp_mod-function/

⇱ PHP | gmp_mod() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

PHP | gmp_mod() Function

Last Updated : 11 Jul, 2025

The gmp_mod() is an inbuilt function in PHP which is used to find the modulo of a GMP number(GNU Multiple Precision: For large numbers) with another GMP number $d where the sign of $d is neglected. 

Syntax: 

gmp_mod ( $num, $d )

Parameters: The function accepts two GMP numbers $num and $d as mandatory parameters as shown in the above syntax. These parameters can be a GMP object in PHP version 5.6 and later, or we are also allowed to pass multiple numeric strings provided that it is possible to convert that string to a number.

 Return Value: The function returns a GMP number which is equivalent to ($num % $d). 

Examples:

Input : $num="8" $d="3" 
Output : 2

Input : $num="10" $d="4"
Output : 2

Below programs illustrate the gmp_mod() function: 

Program 1: The program below demonstrates the working of gmp_mod() function when numeric string are passed as arguments. 

Output:

2

Program 2: The program below demonstrates the working of gmp_mod() when GMP number are passed as arguments. 

Output:

2

Reference: https://www.php.net/manual/en/function.gmp-mod.php

Comment
Article Tags: