• PHP Video Tutorials

PHP - gmp_div() Function



Definition and Usage

The gmp_div() function divides the numbers.

Description

gmp_div() divides the numbers given and returns a GMP number.

Syntax

gmp_div ( 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 is done as follows −

  • 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() function divides the numbers given and returns a GMP number.

PHP Version

This function will work from PHP Version greater than 5.0.0.

Example 1

Working of gmp_div() −

<?php
   $num1 = gmp_div("200", "5");
   $num2 = gmp_div("99", "3");
   $num3 = gmp_div("1", "3", GMP_ROUND_PLUSINF);
   $num4 = gmp_div("-100", "4", GMP_ROUND_PLUSINF);
   $num5 = gmp_div("-50", "4", GMP_ROUND_MINUSINF);
   echo "The number 200/5 is : ".$num1;
   echo "<br/><br/>";
   echo "The number 99/3 is : ".$num2;
   echo "<br/><br/>";
   echo "The number 1/3 is : ".$num3;
   echo "<br/><br/>";
   echo "The number -100/4 is : ".$num4;
   echo "<br/><br/>";
   echo "The number -50/4 is : ".$num5;
?>

This will produce following result −

The number 200/5 is : 40
The number 99/3 is : 33
The number 1/3 is : 1
The number -100/4 is : -25
The number -50/4 is : -13

Example 2

Working of gmp_div() with hexadecimal numbers −

<?php
   $num1 = gmp_div("0x80", "0xFF");
   echo "The number 0x80/0xFF is : ".$num1;
?>

This will produce following result −

The number 0x80/0xFF is : 0
php_function_reference.htm
Advertisements