HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

gmp_div_q

Description

The gmp_div_q of GMP for PHP divides numbers and gets the quotient.

Syntax

gmp_div_q(
    GMP|int|string $num1,
    GMP|int|string $num2,
    int $rounding_mode = GMP_ROUND_ZERO
): GMP

Parameters

num1

The number being divided.

A GMP object, an int or a numeric string.

num2

The number that num1 is being divided by.

A GMP object, an int or a numeric string.

rounding_mode

The result rounding is defined by the rounding_mode:

ConstantDescription
GMP_ROUND_ZEROThe result is truncated towards 0.
GMP_ROUND_PLUSINFThe result is rounded towards +infinity.
GMP_ROUND_MINUSINFThe result is rounded towards -infinity.

Return

Returns a GMP object.

Examples

1 · num1 num2 · GMP

<?

$num1 = 2;
$num2 = 3;

$num1 = gmp_init($num1);
$num2 = gmp_init($num2);

$return = gmp_div_q($num1, $num2);

var_dump($return);
object(GMP)#3 (1) {
  ["num"]=>
  string(1) "0"
}

2 · num1 num2 · int

<?

$num1 = 2;
$num2 = 3;

$return = gmp_div_q($num1, $num2);

var_dump($return);
object(GMP)#1 (1) {
  ["num"]=>
  string(1) "0"
}

3 · num1 num2 · string

<?

$num1 = "2";
$num2 = "3";

$return = gmp_div_q($num1, $num2);

var_dump($return);
object(GMP)#1 (1) {
  ["num"]=>
  string(1) "0"
}

4 · rounding_mode · GMP_ROUND_ZERO

<?

$num1 = 2;
$num2 = 3;
$rounding_mode = GMP_ROUND_ZERO;

$return = gmp_div_q($num1, $num2, $rounding_mode);

var_dump($return);
object(GMP)#1 (1) {
  ["num"]=>
  string(1) "0"
}

5 · rounding_mode · GMP_ROUND_PLUSINF

<?

$num1 = 2;
$num2 = 3;
$rounding_mode = GMP_ROUND_PLUSINF;

$return = gmp_div_q($num1, $num2, $rounding_mode);

var_dump($return);
object(GMP)#1 (1) {
  ["num"]=>
  string(1) "1"
}

6 · rounding_mode · GMP_ROUND_MINUSINF

<?

$num1 = -2;
$num2 = 3;
$rounding_mode = GMP_ROUND_MINUSINF;

$return = gmp_div_q($num1, $num2, $rounding_mode);

var_dump($return);
object(GMP)#1 (1) {
  ["num"]=>
  string(2) "-1"
}