Re: Proposal for floored division and modulo functions

From: Date: Thu, 25 Aug 2022 23:29:43 +0000
Subject: Re: Proposal for floored division and modulo functions
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-118481@lists.php.net to get a copy of this message
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 This was a Nikita special. Yes, the docs should likely be updated. --Larry Garfield

« previous php.internals (#118481) next »