<?php
array gmp_div_qr ( 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 mode
( SEE the below TABLE )
?>
CONSTANT NAME | VALUE | MEANING |
GMP_ROUND_ZERO | 0 | The result is truncate towards 0 |
GMP_ROUND_PLUSINF | 1 | The result is round towards +infinity |
GMP_ROUND_MINUSINF | 2 | The result is round towards -infinity |
ed48 |
<?php
$a01a = PHP_INT_MAX;
$a01b = [ 2, 8, 18, 32 ];
echo 'GMP_ROUND_ZERO<br><br>';
foreach($a01b as $b01a)
{
$g01a = gmp_div_qr($a01a, $b01a);
$s01aa = gmp_strval($g01a[0]);
$s01ab = gmp_strval($g01a[1]);
echo 'gmp_div_qr ( ' . $a01a . ', ' . $b01a . ', 0 )
<br>Quotient = ' . $s01aa . '<br>Remainder = ' . $s01ab . '<br><br>';
}
echo '<br><br>GMP_ROUND_PLUSINF<br><br>';
foreach($a01b as $b01b)
{
$g01b = gmp_div_qr($a01a, $b01b, 1);
$s01ba = gmp_strval($g01b[0]);
$s01bb = gmp_strval($g01b[1]);
echo 'gmp_div_qr ( ' . $a01a . ', ' . $b01b . ', 1 )
<br>Quotient = ' . $s01ba . '<br>Remainder = ' . $s01bb . '<br><br>';
}
echo '<br><br>GMP_ROUND_MINUSINF<br><br>';
foreach($a01b as $b01c)
{
$g01c = gmp_div_qr($a01a, $b01c, 2);
$s01ca = gmp_strval($g01c[0]);
$s01cb = gmp_strval($g01c[1]);
echo 'gmp_div_qr ( ' . $a01a . ', ' . $b01c . ', 2 )
<br>Quotient = ' . $s01ca . '<br>Remainder = ' . $s01cb . '<br><br>';
}
?>
<?php
$a02a = 255;
$a02b = 32;
echo 'GMP_ROUND_ZERO<br><br>';
$g02a = gmp_div_qr($a02a, $a02b, 0);
echo 'gmp_div_qr ( ' . $a02a . ', ' . $a02b . ', 0 )
<br>Quotient = ' . $g02a[0] . '<br>Remainder = ' . $g02a[1] . '<br><br>';
echo '<br><br>GMP_ROUND_PLUSINF<br><br>';
$g02a = gmp_div_qr($a02a, $a02b, 1);
echo 'gmp_div_qr ( ' . $a02a . ', ' . $a02b . ', 1 )
<br>Quotient = ' . $g02a[0] . '<br>Remainder = ' . $g02a[1] . '<br><br>';
echo '<br><br>GMP_ROUND_MINUSINF<br><br>';
$g02a = gmp_div_qr($a02a, $a02b, 2);
echo 'gmp_div_qr ( ' . $a02a . ', ' . $a02b . ', 2 )
<br>Quotient = ' . $g02a[0] . '<br>Remainder = ' . $g02a[1] . '<br><br>where ';
echo "($a02a - ($a02a / $a02b) * $a02b) = " . ($a02a - ($a02a / $a02b) * $a02b) . '<br><br>';
?>
<?php
echo "<pre>";
var_dump(gmp_div_qr(0,1));
echo "</pre><br><br><pre>";
try {
var_dump(gmp_div_qr(1,0));
} catch (\DivisionByZeroError $e) {
echo $e->getMessage() . "<br><br>";
}
try {
var_dump(gmp_div_qr(gmp_init(1), gmp_init(0)));
} catch (\DivisionByZeroError $e) {
echo $e->getMessage() . "<br><br>";
}
var_dump(gmp_div_qr(12653,23482734));
try {
var_dump(gmp_div_qr(12653,23482734, 10));
} catch (\ValueError $e) {
echo $e->getMessage() . "<br><br>";
}
var_dump(gmp_div_qr(1123123,123));
echo "</pre><br><br><pre>";
var_dump(gmp_div_qr(1123123,123, 1));
echo "</pre><br><br><pre>";
var_dump(gmp_div_qr(1123123,123, 2));
echo "</pre><br><br><pre>";
var_dump(gmp_div_qr(gmp_init(1123123), gmp_init(123)));
echo "</pre><br><br><pre>";
var_dump(gmp_div_qr(1123123,123, GMP_ROUND_ZERO));
echo "</pre><br><br><pre>";
var_dump(gmp_div_qr(1123123,123, GMP_ROUND_PLUSINF));
echo "</pre><br><br><pre>";
var_dump(gmp_div_qr(1123123,123, GMP_ROUND_MINUSINF));
echo "</pre><br><br>";
$fp = fopen(__FILE__, 'r');
try {
var_dump(gmp_div_qr($fp, $fp));
} catch (\TypeError $e) {
echo $e->getMessage() . "<br><br>";
}
try {
var_dump(gmp_div_qr(array(), array()));
} catch (\TypeError $e) {
echo $e->getMessage() . "<br><br>";
}
?>