PHP | bcmod() Function

The bcmod() function in PHP is an inbuilt function and is used to calculate modulus of an arbitrary precision numbers. This function accepts an arbitrary precision number and returns the modulus of that number after scaling the result to a specified precision.

Syntax:

string bcadd ( $dividend, $modulus)

Parameters: This function accepts two parameters as shown in the above syntax and explained below:



  • $dividend: This parameter is of string type and represents the dividend which will be divided by the given modulus value $modulus. This parameter is mandatory.
  • $modulus: This parameter is of string type and represents the modulus. This parameter is mandatory.

Return Value: This function returns the remainder when $dividend is divided by $modulus. In other words, it returns the value equivalent to ($dividend % $modulus). If $modulus is zero, then this function returns NULL.

Examples:

Input:  $dividend = 11, $modulus = 3
Output: 2

Input:  $dividend = 3, $modulus = 11
Output: 3

Below programs illustrate the bcmod() function in PHP :

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to illustrate bcmod() function
   
// input numbers with arbitrary precision
$dividend = "11";
$modulus = "3";
   
// calculates the modulus
$res = bcmod($dividend, $modulus);
  
echo $res;
   
?>

chevron_right


Output:

2

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to illustrate bcmod() function
   
// input numbers with arbitrary precision
$dividend = "3";
$modulus = "11";
   
// calculates the modulus
$res = bcmod($dividend, $modulus);
  
echo $res;
   
?>

chevron_right


Output:

3

Reference:
http://php.net/manual/en/function.bcmod.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.