Hi internals,
I would like to add an fdiv() function in PHP 8, implemented in
https://github.com/php/php-src/pull/4769.
Per https://wiki.php.net/rfc/engine_warnings the main division operation
will switch to throwing DivisionByZeroError on division by zero. However, I
think it is important to expose a division with IEEE-754 semantics for
division by zero for the use-cases that do need this. It is fairly tricky
and not very efficient to implement this by hand in userland code,
primarily due to correct handling for negative zero.
The fdiv() function will perform a floating-point division while treating
division by zero as a perfectly legal operation, and will not emit any kind
of diagnostic in that case. Instead it will return the INF/-INF/NAN result
mandated by IEEE-754. It mirrors the existing fmod()
function.
Does anyone see an issue with this addition?
Regards,
Nikita
Hi Nikita,
The fdiv() function will perform a floating-point division while treating
division by zero as a perfectly legal operation, and will not emit any kind
of diagnostic in that case. Instead it will return the INF/-INF/NAN result
mandated by IEEE-754. It mirrors the existingfmod()
function.
I'd prefer floatdiv() as name matching intdiv()
, but wasn't aware
fmod()
is already a thing. So now I think fdiv() might be the slightly
more consistent name.
Regards, Niklas