fdiv
Divides numbers without raising an error on division by zero.
Syntax
fdiv(float $num1, float $num2): floatParameters
| Parameter | Type | Description |
|---|---|---|
| $num1 | float | The dividend. |
| $num2 | float | The 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
In the tutorial
- Numbers and maths — PHP's maths functions — rounding, number formatting, random numbers and the precision of fractions.