<?php
float fdiv ( float $num1 , float $num2 )
where,
$num1 = The dividend
$num2 = The divisor
?>
<?php
// Run this code several times
setlocale(LC_ALL, 'pt-br', 'pr_BR');
$divd01a = mt_rand(30, 42);
$divs01a = mt_rand(1, 30);
if(PHP_MAJOR_VERSION >= 8)
{
$quoc01a = fdiv($divd01a, $divs01a);
echo $divd01a . ' divided by ' . $divs01a .
' produces quociente: ' . $quoc01a . '<br><br>';
$quoc01b = $divd01a / $divs01a;
echo 'The same of: ( ' . $divd01a . '/'
. $divs01a . ' ) = ' . $quoc01b . '<br>';
}
else
{
echo "This function is not available.<br><br>";
$quoc01b = $divd01a / $divs01a;
echo 'The same of alternative use: ( ' . $divd01a . '/'
. $divs01a . ' ) = ' . $quoc01b . '<br>';
}
?>
<?php
$divd02a = PHP_INT_MAX;
$divs02a = PHP_INT_MIN;
if(PHP_MAJOR_VERSION >= 8)
{
$quoc02a = fdiv($divd02a, $divs02a);
echo $divd02a . '<br>divided by<br>' . $divs02a .
'<br>produces quociente: ' . $quoc02a . '.<br><br>';
}
else
{
echo "This function is not available.";
}
?>
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - -
Division by zero
- - - - - - - - - - - - - - - - - - - - - - - - - - - */
$divd03a = PHP_INT_MAX;
$divs03a = 0;
if(PHP_MAJOR_VERSION >= 8)
{
$quoc03a = fdiv($divd03a, $divs03a);
echo $divd03a . '<br>divided by<br>' . $divs03a .
'<br>produces quociente: ' . $quoc03a . '<br><br>';
}
else
{
echo "This function is not available.";
}
?>
<?php
$divd04a = PHP_INT_MIN;
$divs04a = -1;
if(PHP_MAJOR_VERSION > 7)
{
$quoc04a = fdiv($divd04a, $divs04a);
echo $divd04a . '<br>divided by ' . $divs04a .
'<br>produces quociente:<br>' . $quoc04a . '<br><br>';
}
else
{
echo 'Function not available in PHP ' . PHP_VERSION;
}
?>
<?php
$divd05a = 22.999999;
$divs05a = 11.0123467;
if(PHP_MAJOR_VERSION > 7)
{
$quoc05a = fdiv($divd05a, $divs05a);
echo $divd05a . '<br>divided by<br>' . $divs05a .
'<br>produces quociente:<br>' . $quoc05a . '<br><br>';
}
else
{
echo 'Function not available in PHP ' . PHP_VERSION;
}
?>
<?php
if(PHP_MAJOR_VERSION > 7)
{
$divd06a = PHP_FLOAT_MAX;
for($divs06a = 0; $divs06a <= 10; $divs06a++)
{
$quoc06a = fdiv($divd06a, $divs06a);
echo $divd06a . ' divided by ' . $divs06a .
'<br>produces quociente:<br>' . $quoc06a . '<br><br>';
}
}
else
{
echo 'Function not available in PHP ' . PHP_VERSION;
}
?>
<?php
if(PHP_MAJOR_VERSION > 7)
{
var_dump(fdiv(10, 3));
echo '<br>';
var_dump(fdiv(10., 3.));
echo '<br>';
var_dump(fdiv(-10., 2.5));
echo '<br>';
var_dump(fdiv(10., -2.5));
echo "<br><br>";
var_dump(fdiv(10., 0.));
echo '<br>';
var_dump(fdiv(10., -0.));
echo '<br>';
var_dump(fdiv(-10., 0.));
echo '<br>';
var_dump(fdiv(-10., -0.));
echo "<br><br>";
var_dump(fdiv(INF, 0.));
echo '<br>';
var_dump(fdiv(INF, -0.));
echo '<br>';
var_dump(fdiv(-INF, 0.));
echo '<br>';
var_dump(fdiv(-INF, -0.));
echo "<br><br>";
var_dump(fdiv(0., 0.));
echo '<br>';
var_dump(fdiv(0., -0.));
echo '<br>';
var_dump(fdiv(-0., 0.));
echo '<br>';
var_dump(fdiv(-0., -0.));
echo "<br><br>";
var_dump(fdiv(INF, INF));
echo '<br>';
var_dump(fdiv(INF, -INF));
echo '<br>';
var_dump(fdiv(-INF, INF));
echo '<br>';
var_dump(fdiv(-INF, -INF));
echo "<br><br>";
var_dump(fdiv(0., INF));
echo '<br>';
var_dump(fdiv(0., -INF));
echo '<br>';
var_dump(fdiv(-0., INF));
echo '<br>';
var_dump(fdiv(-0., -INF));
echo "<br><br>";
var_dump(fdiv(NAN, NAN));
echo '<br>';
var_dump(fdiv(INF, NAN));
echo '<br>';
var_dump(fdiv(0., NAN));
echo '<br>';
var_dump(fdiv(NAN, INF));
echo '<br>';
var_dump(fdiv(NAN, 0.));
}
else
{
echo 'Function not available in PHP ' . PHP_VERSION;
}
?>