gmp_div_q


gmp apg

DIVIDE two GMP number.

This function is an alias of gmp_div.



gmp_div


gmp apg

DIVIDE two GMP number.

This function is an alias of gmp_div_q.





This function returns a GMP number representing the ( $num1 / $num2 ), with the result rounding.



<?php

GMP gmp_div_q 
GMP|int|string $num1
                           
GMP|int|string $num2
                                            
int $rounding_mode GMP_ROUND_ZERO )


where,

$num1 The divisor

$num2 
The dividend

$rounding_mode 
The result rounding
                            
SEE the below TABLE )

?> 

$num1


The divisor.



$num2


The dividend.



$rounding_mode


The result rounding, which can have the following values:


CONSTANT NAMEVALUEMEANING
GMP_ROUND_ZERO0The result is
truncate towards 0
GMP_ROUND_PLUSINF1The result is
round towards +infinity
GMP_ROUND_MINUSINF2The result is
round towards -infinity
ed48

  1 EXERCISE   

<?php

$a01a 
PHP_INT_MAX;

$a01b = [ 281832 ];

echo 
'GMP_ROUND_ZERO<br><br>';

foreach(
$a01b as $b01a)
{
    
$g01a gmp_div_q($a01a$b01a);
    
$s01a gmp_strval($g01a);
    echo 
'gmp_div_q ( ' $a01a ', ' $b01a ', 0 ) =<br>= ' $s01a '<br>';
}

echo 
'<br><br>GMP_ROUND_PLUSINF<br><br>';

foreach(
$a01b as $b01b)
{
    
$g01b gmp_div_q($a01a$b01b1);
    
$s01b gmp_strval($g01b);
    echo 
'gmp_div_q ( ' $a01a ', ' $b01b ', 1 ) =<br>= ' $s01b '<br>';
}

echo 
'<br><br>GMP_ROUND_MINUSINF<br><br>';

foreach(
$a01b as $b01c)
{
    
$g01c gmp_div_q($a01a$b01c2);
    
$s01c gmp_strval($g01c);
    echo 
'gmp_div_q ( ' $a01a ', ' $b01c ', 2 ) =<br>= ' $s01c '<br>';
}

?> 

 RESULT   

GMP_ROUND_ZERO

gmp_div_q ( 9223372036854775807, 2, 0 ) =
= 4611686018427387903
gmp_div_q ( 9223372036854775807, 8, 0 ) =
= 1152921504606846975
gmp_div_q ( 9223372036854775807, 18, 0 ) =
= 512409557603043100
gmp_div_q ( 9223372036854775807, 32, 0 ) =
= 288230376151711743


GMP_ROUND_PLUSINF

gmp_div_q ( 9223372036854775807, 2, 1 ) =
= 4611686018427387904
gmp_div_q ( 9223372036854775807, 8, 1 ) =
= 1152921504606846976
gmp_div_q ( 9223372036854775807, 18, 1 ) =
= 512409557603043101
gmp_div_q ( 9223372036854775807, 32, 1 ) =
= 288230376151711744


GMP_ROUND_MINUSINF

gmp_div_q ( 9223372036854775807, 2, 2 ) =
= 4611686018427387903
gmp_div_q ( 9223372036854775807, 8, 2 ) =
= 1152921504606846975
gmp_div_q ( 9223372036854775807, 18, 2 ) =
= 512409557603043100
gmp_div_q ( 9223372036854775807, 32, 2 ) =
= 288230376151711743