The fdiv()
function in PHP performs the floating-point division of two numbers and returns its results, according to the IEEE 754 Standard.
Note: The
fdiv()
function is only available in PHP 8 and newer versions.
The prototype of the fdiv()
method is shown below:
fdiv(float $num1, float $num2): float
The fdiv()
function requires two floating numbers as mandatory parameters:
$num1
: The dividend of the division to be performed$num2
: The divisor of the divisionThe fdiv()
function returns the result of the division of the provided parameters, i.e., num1 / num2
as a floating-point value.
If num2
is zero, the fdiv()
function returns one of the following:
INF
(Infinite)-INF
(Negative Infinite)NAN
(Not-A-Number)The code below shows how the fdiv()
function works in PHP.
In this case, we divide two numbers and print the result with the echo
function.
Note: The result is also a
float
.
<?phpecho "fdiv(14, 6) = ".fdiv(14, 6)."\n";echo "fdiv(2, INF) = ".fdiv(2, INF)."\n";echo "fdiv(5, 0) = ".fdiv(5, 0)."\n";?>
fdiv(14, 6) = 2.3333333333333
fdiv(2, INF) = 0
fdiv(5, 0) = INF