PHP Function Reference

PHP fdiv() Function



The PHP fdiv() function divides two numbers, according to IEEE 754. This function returns the floating point result of dividing x by y. In special cases it returns the following:

  • If either argument is NAN, then NAN is returned.
  • If first argument is infinite, or the second argument is zero, then one of INF, -INF, or NAN will be returned.
  • If the first argument is finite and the second argument is infinite, then 0 or -0 will be returned.
Note: This function is available as of PHP 8.0.0.

Syntax

fdiv(x, y)   

Parameters

x Required. Specify the dividend.
y Required. Specify the divisor.

Return Value

Returns the floating point result of dividing x by y.

Example:

The example below shows the usage of fdiv() function.

<?php
echo "fdiv(25, 7) = ".fdiv(25, 7)."\n";
echo "fdiv(-25, 7) = ".fdiv(-25, 7)."\n";
echo "fdiv(25, -7) = ".fdiv(25, -7)."\n";
echo "fdiv(-25, -7) = ".fdiv(-25, -7)."\n";
echo "fdiv(25, INF) = ".fdiv(25, INF)."\n";
echo "fdiv(-25, INF) = ".fdiv(-25, INF)."\n";
echo "fdiv(INF, 7) = ".fdiv(INF, 7)."\n";
echo "fdiv(NAN, 7) = ".fdiv(NAN, 7)."\n";
?>

The output of the above code will be:

fdiv(25, 7) = 3.5714285714286
fdiv(-25, 7) = -3.5714285714286
fdiv(25, -7) = -3.5714285714286
fdiv(-25, -7) = 3.5714285714286
fdiv(25, INF) = 0
fdiv(-25, INF) = -0
fdiv(INF, 7) = INF
fdiv(NAN, 7) = NAN

❮ PHP Math Reference