Friday, October 10, 2025
HomeLanguagesPHP | gmp_mod() Function

PHP | gmp_mod() Function

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. 

php




<?php
// PHP program to demonstrate the gmp_mod() function
 
// arguments as numeric strings
$mod = gmp_mod("8", "3");
 
// prints the calculated modulus
echo gmp_strval($mod) . "\n"; 
?>


Output:

2

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

php




<?php
// PHP program to demonstrate the gmp_mod function
 
// arguments as GMP numbers
 
$num = gmp_init("1010", 2); // num = 10
$d = gmp_init("100", 2);  // d = 4
 
$mod = gmp_mod($num, $d);
 
// prints the calculated modulus
// gmp_strval converts GMP number to string
// representation in given base(default 10).
echo gmp_strval($mod) . "\n"; 
?>


Output:

2

Reference: http://php.net/manual/en/function.gmp-mod.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!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7100 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS