Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

fdiv

Divides numbers without raising an error on division by zero.

Syntax

fdiv(float $num1, float $num2): float

Parameters

ParameterTypeDescription
$num1floatThe dividend.
$num2floatThe divisor.

Return value

floatThe quotient; `INF`, `-INF` or `NAN` on division by zero.

Examples

Division by zero:

<?php
 
var_dump(fdiv(10, 4));
var_dump(fdiv(10, 0));
var_dump(is_nan(fdiv(0, 0)));

Output:

float(2.5)
float(INF)
bool(true)

Notes

The regular / operator throws DivisionByZeroError on division by zero.

See also

  • intdiv — Performs integer division.
  • fmod — Returns the remainder of a division of floats.
  • is_nan — Checks whether a value is "not a number" (NAN).

In the tutorial

  • Numbers and maths — PHP's maths functions — rounding, number formatting, random numbers and the precision of fractions.

Thanks for reading!

Donate to the site — we work hard for you.