gmp_div_r


gmp apg

CALCULATES the remainder of the division of two GMP number.





This function returns the REMAINDER as GMP number of ( $num1 / $num2 ), with the result rounding.

The remainder has the sign of $num1 if $num1 ≠ 0.



<?php

GMP gmp_div_r 
( 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 = [ 2, 8, 18, 32 ];

echo 
'GMP_ROUND_ZERO<br><br>';

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

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

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

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

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

?> 

  2 EXERCISE   

<?php

$a02a 
= 0X100;
// HEXADECIMAL VALUE 0X100 = 0x100 =  DECIMAL VALUE 256

$a02b = [ 3, 4, 5 ];

$tp02c = [ "GMP_ROUND_ZERO" => GMP_ROUND_ZERO, 
                 
"GMP_ROUND_PLUSINF" => GMP_ROUND_PLUSINF, 
                 
"GMP_ROUND_MINUSINF" => GMP_ROUND_MINUSINF ]; 

foreach(
$a02b as $b02a)
{  
    foreach(
$tp02c as $k02c => $t02c)
    {
        echo 
$k02c . '<br>';
    
$g02a = gmp_div_r($a02a, $b02a, $t02c);
    
$s02a = gmp_strval($g02a);
    echo 
'gmp_div_r ( ' . $a02a . ', ' . $b02a . ', ' . $t02c . ' ) = ' . $g02a . '<br>';
    echo 
'gmp_strval( ' . $g02a . ' ) = ' . $s02a .  '<br><br>';
}
}


?>