# fdiv() function

- Thread: https://staging.externals.io/message/107361
- Original archive: https://news-web.php.net/php.internals/107361
- Started by Nikita Popov on 2019-10-02T13:14:21+00:00
- Messages: 2
- RFC: Reclassifying engine warnings (Implemented (PHP 8.0)) — https://staging.externals.io/rfc/engine_warnings.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://staging.externals.io/search.md?q={query} · RFCs at https://staging.externals.io/rfc.md · JSON API at https://staging.externals.io/api · documentation at https://staging.externals.io/llms.txt

---

## #107361 — Nikita Popov — 2019-10-02T13:14:21+00:00

URL: https://staging.externals.io/message/107361#107361

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

---

## #107373 — Niklas Keller — 2019-10-04T20:28:48+00:00

URL: https://staging.externals.io/message/107361#107373 · In reply to: #107361

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 existing `fmod()` 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
