On 26.08.2022 at 01:29, Larry Garfield wrote:

> On Thu, Aug 25, 2022, at 3:16 PM, Rowan Tommins wrote:
>
>> But then we face the awkward asymmetry of the current functionality:
>>
>> intdiv() - Integer division
>> / - Floating-point division
>> % - Integer modulus
>> fmod() - Floating-point modulo
>>
>> Apparently as of PHP 8.0, there is also an fdiv() function, but the
>> manual doesn't currently explain why it exists, and whether it will
>> always give the same result as / (and if not, why not?)
>
> / in PHP 8.0+ throws DivideByZeroError if you divide by 0.  Prior versions, 
> it was a fatal error.
>
> fdiv() returns a NAN or INF constant for division by 0.
>
> echo fdiv(5, 0); // INF
> echo fdiv(-5, 0); // -INF
> echo fdiv(0, 0); // NAN

There is another (minor?) difference, namely that the / operator
evaluates to an int, if the numbers are evenly divisible, but fdiv()
always returns a float (<https://3v4l.org/sCgJt>).

--
Christoph M. Becker

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to