Re: Proposal for floored division and modulo functions

From: Date: Fri, 26 Aug 2022 12:40:18 +0000
Subject: Re: Proposal for floored division and modulo functions
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to internals+get-118508@lists.php.net to get a copy of this message
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

« previous php.internals (#118508) next »