• PHP Video Tutorials

PHP - gmp_div_r() Function



Definition and Usage

The gmp_div_r() function divides the given numbers and returns the remainder.

Description

gmp_div_r() divides the given numbers and returns remainder.

Syntax

gmp_div_r ( GMP $a , GMP $b [, int $round = GMP_ROUND_ZERO ] ) : GMP

Parameters

Sr.No Parameter & Description
1

a

The number to be divided.It can a GMP resource number , a gmp object or a numeric string .

2

b

The number that you will divide with parameter a. It can a GMP resource number , a gmp object or a numeric string .

3

round

The rounding can be done using following constants −

  • GMP_ROUND_ZERO − The result is truncated towards 0.
  • GMP_ROUND_PLUSINF − The result is rounded towards +infinity.
  • GMP_ROUND_MINUSINF − The result is rounded towards -infinity.

Return Values

PHP gmp_div_r() function returns remainder which is a GMP number.

PHP Version

This function will work from PHP Version greater than 5.0.0.

Example 1

Working of gmp_div_r −

<?php
   $res = gmp_div_r('120', '45');
   echo "Dividing 120/45 : ";
   echo "<br/><br/>";
   echo "Remainder is : ".$res;
?>

This will produce following result −

Dividing 120/45
Quotient is : 2
Remainder is : 30

Example 2

Working of gmp_div_r with hexadecimal numbers −

<?php
   $res = gmp_div_r('0xFF', '0x80');
   echo "Dividing 0xFF/0x80";
   echo "<br/><br/>";
   echo "Remainder is : ".$res;
?>

This will produce following result −

Dividing 0xFF/0x80
Remainder is : 127
php_function_reference.htm
Advertisements